// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_transform.c
// Function: prepare_call
static int
prepare_call(ir_unit_t *iu, ir_function_t *f, ir_instr_call_t *ii,
             int call_arg_base, int *num_call_args, int callargtype)
{
  int callpos = 0;
  int stackgrowth = 0;
  int total_slots = 0;

  instr_bind_clear_inputs(&ii->super);
  instr_bind_input(iu, ii->callee, &ii->super);

  for(int i = 0; i < ii->argc; i++) {
    int slots = value_regframe_slots(iu, ii->argv[i].value.type);
    int arg = call_arg_base + total_slots;
    total_slots += slots;

    while(total_slots > *num_call_args) {
      ir_valuetype_t vt = value_alloc_temporary(iu, callargtype);
      ir_value_t *iv = value_get(iu, vt.value);
      iv->iv_precolored = *num_call_args;
      *num_call_args += 1;
    }


    if(ii->argv[i].copy_size) {
      assert(slots == 1);
      ir_instr_stackcopy_t *stackcopy =
        instr_add_before(sizeof(ir_instr_stackcopy_t), IR_IC_STACKCOPY,
                         &ii->super);

      stackcopy->super.ii_ret.value = arg;
      stackcopy->super.ii_ret.type = callargtype;

      stackcopy->value = ii->argv[i].value;
      stackcopy->size = ii->argv[i].copy_size;

      instr_bind_input(iu, ii->argv[i].value, &stackcopy->super);
      value_bind_return_value(iu, &stackcopy->super);

      stackgrowth += stackcopy->size;

      ii->argv[i].value.value = arg;
      instr_bind_input(iu, ii->argv[i].value, &ii->super);

    } else if(slots == 2) {
      ir_instr_move_t *move =
        instr_add_before(sizeof(ir_instr_move_t), IR_IC_MOVE, &ii->super);

      move->super.ii_rets = malloc(sizeof(ir_valuetype_t) * 2);
      move->super.ii_ret.value = -2;
      move->super.ii_rets[0].value = arg + 1;
      move->super.ii_rets[0].type = callargtype;
      move->super.ii_rets[1].value = arg;
      move->super.ii_rets[1].type = callargtype;
      move->value = ii->argv[i].value;

      instr_bind_input(iu, move->value, &move->super);

      value_bind_instr(value_get(iu, arg + 1), &move->super, IVI_OUTPUT);
      value_bind_instr(value_get(iu, arg    ), &move->super, IVI_OUTPUT);

      ii->argv[i].value.value = arg;
      instr_bind_input(iu, ii->argv[i].value, &ii->super);


    } else {
      ir_instr_move_t *move =
        instr_add_before(sizeof(ir_instr_move_t), IR_IC_MOVE, &ii->super);
      move->super.ii_ret.value = arg;
      move->super.ii_ret.type = ii->argv[i].value.type;

      move->value = ii->argv[i].value;
      instr_bind_input(iu, ii->argv[i].value, &move->super);
      value_bind_return_value(iu, &move->super);

      ii->argv[i].value.value = arg;
      instr_bind_input(iu, ii->argv[i].value, &ii->super);
    }
  }

  ir_function_t *callee = value_function(iu, ii->callee.value);
  if(callee != NULL)
    callee->if_used = 1;

  if(stackgrowth > 0) {
    ir_instr_stackshrink_t *ss =
      instr_add_after(sizeof(ir_instr_stackshrink_t), IR_IC_STACKSHRINK,
                      &ii->super);
      ss->super.ii_ret.value = -1;
      ss->size = stackgrowth;
  }
  return callpos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movq -0x18(%rbp), %rdi
callq 0x28760
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movq -0x18(%rbp), %rdx
movq 0x58(%rax), %rsi
callq 0x267c0
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x6c(%rcx), %eax
jge 0x286f0
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %esi
callq 0x20a10
movl %eax, -0x40(%rbp)
movl -0x1c(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jle 0x283c5
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x20c80
movq %rax, -0x4c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
callq 0x20ee0
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %ecx
movq -0x58(%rbp), %rax
movl %ecx, 0x38(%rax)
movq -0x28(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x28380
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x8(%rax)
je 0x284ec
cmpl $0x1, -0x40(%rbp)
jne 0x283ea
jmp 0x28409
leaq 0x17458(%rip), %rdi     # 0x3f849
leaq 0x16ff5(%rip), %rsi     # 0x3f3ed
movl $0x887, %edx            # imm = 0x887
leaq 0x17450(%rip), %rcx     # 0x3f854
callq 0x31c0
movq -0x18(%rbp), %rdx
movl $0x68, %edi
movl $0x17, %esi
callq 0x26380
movq %rax, -0x60(%rbp)
movl -0x44(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl -0x2c(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
addq $0x70, %rcx
movslq -0x3c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq %rcx, 0x58(%rax)
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x60(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x60(%rbp), %rdx
movq (%rax), %rsi
callq 0x267c0
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x20cf0
movq -0x60(%rbp), %rax
movl 0x60(%rax), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rdx
movq (%rax), %rsi
callq 0x267c0
jmp 0x286e0
cmpl $0x2, -0x40(%rbp)
jne 0x28617
movq -0x18(%rbp), %rdx
movl $0x60, %edi
movl $0x15, %esi
callq 0x26380
movq %rax, -0x68(%rbp)
movl $0x10, %edi
callq 0x3360
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x68(%rbp), %rax
movl $0xfffffffe, 0x2c(%rax) # imm = 0xFFFFFFFE
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rax
movl %ecx, (%rax)
movl -0x2c(%rbp), %ecx
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rax
movl %ecx, 0x4(%rax)
movl -0x44(%rbp), %ecx
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rax
movl %ecx, 0x8(%rax)
movl -0x2c(%rbp), %ecx
movq -0x68(%rbp), %rax
movq 0x18(%rax), %rax
movl %ecx, 0xc(%rax)
movq -0x68(%rbp), %rax
movq -0x18(%rbp), %rcx
addq $0x70, %rcx
movslq -0x3c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq %rcx, 0x58(%rax)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rax
movq -0x68(%rbp), %rdx
movq 0x58(%rax), %rsi
callq 0x267c0
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %esi
addl $0x1, %esi
callq 0x20ee0
movq %rax, %rdi
movq -0x68(%rbp), %rsi
movl $0x1, %edx
callq 0x20e00
movq -0x8(%rbp), %rdi
movl -0x44(%rbp), %esi
callq 0x20ee0
movq %rax, %rdi
movq -0x68(%rbp), %rsi
movl $0x1, %edx
callq 0x20e00
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rdx
movq (%rax), %rsi
callq 0x267c0
jmp 0x286de
movq -0x18(%rbp), %rdx
movl $0x60, %edi
movl $0x15, %esi
callq 0x26380
movq %rax, -0x70(%rbp)
movl -0x44(%rbp), %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x2c(%rax)
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %ecx
movq -0x70(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x70(%rbp), %rax
movq -0x18(%rbp), %rcx
addq $0x70, %rcx
movslq -0x3c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
movq %rcx, 0x58(%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x70(%rbp), %rdx
movq (%rax), %rsi
callq 0x267c0
movq -0x8(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x20cf0
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rdx
imulq $0xc, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
addq $0x70, %rax
movslq -0x3c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq -0x18(%rbp), %rdx
movq (%rax), %rsi
callq 0x267c0
jmp 0x286e0
jmp 0x286e2
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x2833c
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0x58(%rax), %esi
callq 0x24040
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0x28713
movq -0x78(%rbp), %rax
movb $0x1, 0x29(%rax)
cmpl $0x0, -0x34(%rbp)
jle 0x28745
movq -0x18(%rbp), %rdx
movl $0x60, %edi
movl $0x18, %esi
callq 0x265e0
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movl $0xffffffff, 0x2c(%rax) # imm = 0xFFFFFFFF
movl -0x34(%rbp), %ecx
movq -0x80(%rbp), %rax
movl %ecx, 0x58(%rax)
movl -0x30(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)