// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_vm.c
// Function: vm_emit_function
static void
vm_emit_function(ir_unit_t *iu, ir_function_t *f)
{
  ir_bb_t *ib;
  ir_instr_t *i;

  iu->iu_text_ptr = iu->iu_text_alloc;

  VECTOR_RESIZE(&iu->iu_branch_fixups, 0);
  VECTOR_RESIZE(&iu->iu_jit_vmbb_fixups, 0);
  VECTOR_RESIZE(&iu->iu_jit_branch_fixups, 0);
  VECTOR_RESIZE(&iu->iu_jit_bb_to_addr_fixups, 0);

#ifdef VM_TRACE
  int total_instructions = 0;
  TAILQ_FOREACH(ib, &f->if_bbs, ib_link) {
    TAILQ_FOREACH(i, &ib->ib_instrs, ii_link) {
      total_instructions++;
    }
  }
  f->if_instr_backrefs = calloc(total_instructions, sizeof(ir_instr_backref_t));
  f->if_instr_backref_size = 0;
#endif

#ifdef VMIR_VM_JIT
  jitctx_t jc;
  jitctx_init(iu, f, &jc);
  f->if_jit_offset = iu->iu_jit_ptr;
#endif

  TAILQ_FOREACH(ib, &f->if_bbs, ib_link) {
#ifdef VMIR_VM_JIT
    if(f->if_full_jit) {
      jit_emit(iu, ib, &jc);
      continue;
    }
#endif
    ib->ib_text_offset = iu->iu_text_ptr - iu->iu_text_alloc;
    if(iu->iu_debug_flags_func & VMIR_DBG_BB_INSTRUMENT) {
      emit_op(iu, VM_INSTRUMENT_COUNT);
      emit_i32(iu, VECTOR_LEN(&iu->iu_instrumentation));

      int num_instructions = 0;
      TAILQ_FOREACH(i, &ib->ib_instrs, ii_link)
        num_instructions++;

      ir_instrumentation_t ii = {f, ib->ib_id, num_instructions, 0};
      VECTOR_PUSH_BACK(&iu->iu_instrumentation, ii);
    }
    instr_emit(iu, ib, f
#ifdef VMIR_VM_JIT
               ,&jc
#endif
               );
  }

#ifdef VMIR_VM_JIT
  jitctx_done(iu, f, &jc);
#endif
  f->if_vm_text_size = iu->iu_text_ptr - iu->iu_text_alloc;
  if(f->if_full_jit) {
    assert(f->if_vm_text_size == 0);
    f->if_ext_func = iu->iu_jit_mem + f->if_jit_offset;
  } else {
    f->if_vm_text = malloc(f->if_vm_text_size);
    memcpy(f->if_vm_text, iu->iu_text_alloc, f->if_vm_text_size);

    iu->iu_stats.vm_code_size += f->if_vm_text_size;
    branch_fixup(iu);
  }
#ifdef VMIR_VM_JIT
  jit_branch_fixup(iu, f);
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x438(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x440(%rax)
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpq 0x318(%rcx), %rax
jbe 0x241e9
movq -0x8(%rbp), %rax
movq $0x0, 0x318(%rax)
movq -0x8(%rbp), %rax
movq 0x318(%rax), %rax
shlq $0x2, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x308(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x3390
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x308(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x310(%rax)
jmp 0x241fa
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpq 0x330(%rcx), %rax
jbe 0x2424d
movq -0x8(%rbp), %rax
movq $0x0, 0x330(%rax)
movq -0x8(%rbp), %rax
movq 0x330(%rax), %rax
shlq $0x2, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x320(%rax), %rdi
movq -0x30(%rbp), %rsi
callq 0x3390
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x320(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x328(%rax)
jmp 0x2425e
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpq 0x348(%rcx), %rax
jbe 0x242b1
movq -0x8(%rbp), %rax
movq $0x0, 0x348(%rax)
movq -0x8(%rbp), %rax
movq 0x348(%rax), %rax
shlq $0x2, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x338(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x3390
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x338(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x340(%rax)
jmp 0x242c2
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpq 0x360(%rcx), %rax
jbe 0x24315
movq -0x8(%rbp), %rax
movq $0x0, 0x360(%rax)
movq -0x8(%rbp), %rax
movq 0x360(%rax), %rax
shlq $0x2, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x350(%rax), %rdi
movq -0x40(%rbp), %rsi
callq 0x3390
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x350(%rax)
movq -0x8(%rbp), %rax
movq $0x0, 0x358(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x244b3
movq -0x8(%rbp), %rax
movq 0x440(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x438(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x20(%rax)
movq -0x8(%rbp), %rax
movl 0x104(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x24492
movq -0x8(%rbp), %rdi
movl $0x1fd, %esi            # imm = 0x1FD
callq 0x2b410
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x118(%rax), %rax
movl %eax, %esi
callq 0x2b450
movl $0x0, -0x44(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x243c7
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0x243aa
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x58(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x54(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x118(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
cmpq 0x120(%rcx), %rax
jbe 0x24453
movq -0x68(%rbp), %rcx
addq $0x1, %rcx
shlq %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x120(%rax)
movq -0x8(%rbp), %rax
imulq $0x18, 0x120(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rdi
movq -0x70(%rbp), %rsi
callq 0x3390
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x110(%rax)
movq -0x68(%rbp), %rcx
addq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x118(%rax)
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rax
imulq $0x18, -0x68(%rbp), %rcx
addq %rcx, %rax
movq -0x60(%rbp), %rcx
movq %rcx, (%rax)
movq -0x58(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x24492
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x10(%rbp), %rdx
callq 0x2b4e0
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x24330
movq -0x8(%rbp), %rax
movq 0x440(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x438(%rcx), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x68(%rax)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x2a(%rax)
je 0x2452a
movq -0x10(%rbp), %rax
cmpl $0x0, 0x68(%rax)
jne 0x244eb
jmp 0x2450a
leaq 0x1ba15(%rip), %rdi     # 0x3ff07
leaq 0x1ba26(%rip), %rsi     # 0x3ff1f
movl $0x12de, %edx           # imm = 0x12DE
leaq 0x1ba28(%rip), %rcx     # 0x3ff2d
callq 0x31c0
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rcx
movq -0x10(%rbp), %rax
movslq 0x84(%rax), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x70(%rax)
jmp 0x24582
movq -0x10(%rbp), %rax
movslq 0x68(%rax), %rdi
callq 0x3360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x438(%rax), %rsi
movq -0x10(%rbp), %rax
movslq 0x68(%rax), %rdx
callq 0x3330
movq -0x10(%rbp), %rax
movl 0x68(%rax), %ecx
movq -0x8(%rbp), %rax
addl 0x5f8(%rax), %ecx
movl %ecx, 0x5f8(%rax)
movq -0x8(%rbp), %rdi
callq 0x2b750
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)