// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_wasm_parser.c
// Function: wasm_call
static void
wasm_call(ir_unit_t *iu, ir_bb_t *ib, wasm_bytestream_t *wbs,
          int indirect)
{
  int callee_type;

  if(indirect) {
    const int wasm_callee_type = wbs_get_vu32(wbs);
    callee_type = VECTOR_ITEM(&iu->iu_wasm_type_map, wasm_callee_type);

  } else {

    const int callee_index = wbs_get_vu32(wbs);
    ir_function_t *callee = VECTOR_ITEM(&iu->iu_functions, callee_index);
    callee_type = callee->if_type;

    ir_value_t *iv = value_append_and_get(iu);
    iv->iv_class = IR_VC_FUNCTION;
    iv->iv_type = callee_type;
    iv->iv_func = callee;
  }

  const ir_type_t *it = type_get(iu, callee_type);
  const int num_args = it->it_function.num_parameters;

  ir_instr_call_t *i =
    instr_add(ib, sizeof(ir_instr_call_t) +
              sizeof(ir_instr_arg_t) * num_args, IR_IC_CALL);

  if(indirect) {

    i->callee = vstack_pop(iu);
    wbs_get_vu32(wbs); // reserved

  } else {
    i->callee.value = iu->iu_next_value - 1;
  }
  i->argc = num_args;
  for(int j = num_args - 1; j >= 0; j--) {
    i->argv[j].value = vstack_pop(iu);
  }

  const ir_type_t *rety = type_get(iu, it->it_function.return_type);
  if(rety->it_code == IR_TYPE_VOID)
    return;

  value_alloc_instr_ret(iu, it->it_function.return_type, &i->super);
  vstack_push(iu, i->super.ii_ret);
}

// 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)
cmpl $0x0, -0x1c(%rbp)
je 0x21273
movq -0x18(%rbp), %rdi
callq 0x1d450
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rax
movq 0x580(%rax), %rax
movslq -0x24(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
jmp 0x212cd
movq -0x18(%rbp), %rdi
callq 0x1d450
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x2d8(%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
callq 0x223d0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl $0x1, (%rax)
movl -0x20(%rbp), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x30(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x1ee20
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x44(%rbp), %rax
imulq $0xc, %rax, %rsi
addq $0x70, %rsi
movl $0xa, %edx
callq 0x20c10
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x2133a
movq -0x50(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1ea10
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x58(%rbp)
movq -0x58(%rbp), %rcx
movq %rcx, 0x58(%rax)
movq -0x18(%rbp), %rdi
callq 0x1d450
jmp 0x2134e
movq -0x8(%rbp), %rax
movl 0x198(%rax), %ecx
subl $0x1, %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x58(%rax)
movl -0x44(%rbp), %ecx
movq -0x50(%rbp), %rax
movl %ecx, 0x6c(%rax)
movl -0x44(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x5c(%rbp)
cmpl $0x0, -0x5c(%rbp)
jl 0x213a4
movq -0x50(%rbp), %rax
addq $0x70, %rax
movslq -0x5c(%rbp), %rcx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
callq 0x1ea10
movq %rax, %rcx
movq -0x80(%rbp), %rax
movq %rcx, -0x64(%rbp)
movq -0x64(%rbp), %rcx
movq %rcx, (%rax)
movl -0x5c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x21361
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl 0x10(%rax), %esi
callq 0x1ee20
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x213c3
jmp 0x213e8
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x50(%rbp), %rdx
callq 0x22410
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rax
movq 0x2c(%rax), %rsi
callq 0x1f360
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)