// Both the if and then portion are call statements
bool IfConversionPass2::ConvertCallsIf(IfStatement* toConvert)
{
  Statement* thenPart = Denormalize(toConvert->get_then_part()) ;
  Statement* elsePart = Denormalize(toConvert->get_else_part()) ;

  CallStatement* thenCall = dynamic_cast<CallStatement*>(thenPart) ;
  CallStatement* elseCall = dynamic_cast<CallStatement*>(elsePart) ;

  assert(thenCall != NULL) ;
  assert(elseCall != NULL) ;

  CallStatement* boolSelectCall = 
    CreateBoolCall(thenCall->get_destination()) ;

  // Create call expression for each of the call statements
  //  and append them to the boolean select we are creating.

  Expression* thenCallValue = thenCall->get_callee_address() ;
  thenCall->set_callee_address(NULL) ;

  CallExpression* thenCallExp = 
    create_call_expression(theEnv,
			   thenCall->get_destination()->get_type()->get_base_type(),
			   thenCallValue) ;

  // Append all of the call arguments to the expression
  for (int i = 0 ; i < thenCall->get_argument_count() ; ++i)
  {
    Expression* nextArg = thenCall->get_argument(i) ;
    nextArg->set_parent(NULL) ;
    thenCallExp->append_argument(nextArg) ;
  }

  boolSelectCall->append_argument(thenCallExp) ;

  Expression* elseCallValue = elseCall->get_callee_address() ;
  elseCall->set_callee_address(NULL) ;
  CallExpression* elseCallExp =
    create_call_expression(theEnv,
			   thenCall->get_destination()->get_type()->get_base_type(),
			   elseCallValue) ;

  // Append all of the call arguments to the expression
  for (int i = 0 ; i < elseCall->get_argument_count() ; ++i)
  {
    Expression* nextArg = elseCall->get_argument(i) ;
    nextArg->set_parent(NULL) ;
    elseCallExp->append_argument(nextArg) ;
  }

  boolSelectCall->append_argument(elseCallExp) ;

  Expression* condition = toConvert->get_condition() ;
  toConvert->set_condition(NULL) ;
  boolSelectCall->append_argument(condition) ;

  toConvert->get_parent()->replace(toConvert, boolSelectCall) ;  
  return true ;
}
void DismantleCallArguments::
do_procedure_definition(ProcedureDefinition *pd) 
{
  list<CallStatement*> *l = collect_objects<CallStatement>(pd);
  while (!l->empty()) {
    CallStatement *call = l->front();
    l->pop_front();

    for (size_t i = 0; i < call->get_argument_count(); i++) {
      Expression *arg = call->get_argument(i);
      if (!arg) continue;
      if (is_kind_of<LoadVariableExpression>(arg)) continue;
      list<StoreVariableStatement *> l;
      force_dest_not_expr(arg, l);
    }
  }
  delete l;  
}