// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_vm.c
// Function: emit_load
static void
emit_load(ir_unit_t *iu, ir_instr_load_t *ii)
{
  const ir_value_t *src = value_get(iu, ii->ptr.value);
  const ir_value_t *roff =
    ii->value_offset.value >= 0 ? value_get(iu, ii->value_offset.value) : NULL;
  const ir_value_t *ret = value_get(iu, ii->super.ii_ret.value);
  const ir_type_t *retty = type_get(iu, ii->super.ii_ret.type);

  if(ii->cast != -1) {
    // Load + Cast
    ir_type_t *pointee = type_get(iu, ii->load_type);

    switch(COMBINE4(src->iv_class, legalize_type(retty),
                    legalize_type(pointee), ii->cast)) {
    case COMBINE4(IR_VC_REGFRAME, IR_TYPE_INT32, IR_TYPE_INT8, CAST_ZEXT):
      emit_op2(iu, roff ? VM_LOAD8_ZEXT_32_ROFF :
               VM_LOAD8_ZEXT_32_OFF, value_reg(ret), value_reg(src));
      emit_imm16(iu, ii->immediate_offset);
      break;
    case COMBINE4(IR_VC_REGFRAME, IR_TYPE_INT32, IR_TYPE_INT8, CAST_SEXT):
      emit_op2(iu, roff ? VM_LOAD8_SEXT_32_ROFF : VM_LOAD8_SEXT_32_OFF,
               value_reg(ret), value_reg(src));
      emit_imm16(iu, ii->immediate_offset);
      break;
    case COMBINE4(IR_VC_REGFRAME, IR_TYPE_INT32, IR_TYPE_INT16, CAST_ZEXT):
      emit_op2(iu, roff ? VM_LOAD16_ZEXT_32_ROFF: VM_LOAD16_ZEXT_32_OFF,
               value_reg(ret), value_reg(src));
      emit_imm16(iu, ii->immediate_offset);
      break;
    case COMBINE4(IR_VC_REGFRAME, IR_TYPE_INT32, IR_TYPE_INT16, CAST_SEXT):
      emit_op2(iu, roff ? VM_LOAD16_SEXT_32_ROFF : VM_LOAD16_SEXT_32_OFF,
               value_reg(ret), value_reg(src));
      emit_imm16(iu, ii->immediate_offset);
      break;

    case COMBINE4(IR_VC_CONSTANT, IR_TYPE_INT32, IR_TYPE_INT8, CAST_ZEXT):
      emit_op1(iu, VM_LOAD8_G_ZEXT_32, value_reg(ret));
      emit_i32(iu, value_get_const32(iu, src) + ii->immediate_offset);
      break;

    case COMBINE4(IR_VC_CONSTANT, IR_TYPE_INT32, IR_TYPE_INT8, CAST_SEXT):
      emit_op1(iu, VM_LOAD8_G_SEXT_32, value_reg(ret));
      emit_i32(iu, value_get_const32(iu, src) + ii->immediate_offset);
      break;

    case COMBINE4(IR_VC_CONSTANT, IR_TYPE_INT32, IR_TYPE_INT16, CAST_ZEXT):
      emit_op1(iu, VM_LOAD16_G_ZEXT_32, value_reg(ret));
      emit_i32(iu, value_get_const32(iu, src) + ii->immediate_offset);
      break;

    case COMBINE4(IR_VC_CONSTANT, IR_TYPE_INT32, IR_TYPE_INT16, CAST_SEXT):
      emit_op1(iu, VM_LOAD16_G_SEXT_32, value_reg(ret));
      emit_i32(iu, value_get_const32(iu, src) + ii->immediate_offset);
      break;


    default:
      parser_error(iu, "Can't load+cast to %s from %s cast:%d (%s)",
                   type_str(iu, retty),
                   type_str(iu, pointee),
                   ii->cast, instr_str(iu, &ii->super, 0));
    }
    if(roff != NULL) {
      emit_i16(iu, value_reg(roff));
      emit_i16(iu, ii->value_offset_multiply);
    }
    return;
  }

  emit_load1(iu, src, ret, retty, roff, ii->immediate_offset,
             ii->value_offset_multiply, ii);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x58(%rax), %esi
callq 0x20ee0
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x64(%rax)
jl 0x2cac7
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x64(%rax), %esi
callq 0x20ee0
movq %rax, -0x40(%rbp)
jmp 0x2cacf
xorl %eax, %eax
movq %rax, -0x40(%rbp)
jmp 0x2cacf
movq -0x40(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %esi
callq 0x20ee0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %esi
callq 0x1ee20
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x74(%rax), %eax
cmpl $-0x1, %eax
je 0x2cfae
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x70(%rax), %esi
callq 0x1ee20
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x18, %eax
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rdi
callq 0x45d0
movl %eax, %ecx
movl -0x4c(%rbp), %eax
shll $0x10, %ecx
orl %ecx, %eax
movl %eax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
callq 0x45d0
movl %eax, %ecx
movl -0x48(%rbp), %eax
shll $0x8, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movsbl 0x74(%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x44(%rbp)
subl $0x3050301, %eax        # imm = 0x3050301
je 0x2cd78
jmp 0x2cb73
movl -0x44(%rbp), %eax
subl $0x3050302, %eax        # imm = 0x3050302
je 0x2cdd2
jmp 0x2cb83
movl -0x44(%rbp), %eax
subl $0x3050401, %eax        # imm = 0x3050401
je 0x2ce2c
jmp 0x2cb93
movl -0x44(%rbp), %eax
subl $0x3050402, %eax        # imm = 0x3050402
je 0x2ce86
jmp 0x2cba3
movl -0x44(%rbp), %eax
subl $0x5050301, %eax        # imm = 0x5050301
je 0x2cbe2
jmp 0x2cbaf
movl -0x44(%rbp), %eax
subl $0x5050302, %eax        # imm = 0x5050302
je 0x2cc43
jmp 0x2cbbf
movl -0x44(%rbp), %eax
subl $0x5050401, %eax        # imm = 0x5050401
je 0x2cca4
jmp 0x2cbcf
movl -0x44(%rbp), %eax
subl $0x5050402, %eax        # imm = 0x5050402
je 0x2cd05
jmp 0x2cee0
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rdx
movl $0x76, %eax
movl $0x79, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rdi
callq 0x321a0
movw %ax, -0x4e(%rbp)
movq -0x18(%rbp), %rdi
callq 0x321a0
movq -0x60(%rbp), %rdi
movl -0x54(%rbp), %esi
movw -0x4e(%rbp), %cx
movzwl %cx, %edx
movzwl %ax, %ecx
callq 0x324a0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x60(%rax), %esi
callq 0x32590
jmp 0x2cf6f
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdx
movl $0x77, %eax
movl $0x7a, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x68(%rbp)
movq -0x28(%rbp), %rdi
callq 0x321a0
movw %ax, -0x62(%rbp)
movq -0x18(%rbp), %rdi
callq 0x321a0
movq -0x70(%rbp), %rdi
movl -0x68(%rbp), %esi
movw -0x62(%rbp), %cx
movzwl %cx, %edx
movzwl %ax, %ecx
callq 0x324a0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x60(%rax), %esi
callq 0x32590
jmp 0x2cf6f
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x20(%rbp), %rdx
movl $0x84, %eax
movl $0x87, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x78(%rbp)
movq -0x28(%rbp), %rdi
callq 0x321a0
movw %ax, -0x72(%rbp)
movq -0x18(%rbp), %rdi
callq 0x321a0
movq -0x80(%rbp), %rdi
movl -0x78(%rbp), %esi
movw -0x72(%rbp), %cx
movzwl %cx, %edx
movzwl %ax, %ecx
callq 0x324a0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x60(%rax), %esi
callq 0x32590
jmp 0x2cf6f
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rdx
movl $0x85, %eax
movl $0x88, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x88(%rbp)
movq -0x28(%rbp), %rdi
callq 0x321a0
movw %ax, -0x82(%rbp)
movq -0x18(%rbp), %rdi
callq 0x321a0
movq -0x90(%rbp), %rdi
movl -0x88(%rbp), %esi
movw -0x82(%rbp), %cx
movzwl %cx, %edx
movzwl %ax, %ecx
callq 0x324a0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x60(%rax), %esi
callq 0x32590
jmp 0x2cf6f
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x321a0
movq -0xa0(%rbp), %rdi
movl $0x7b, %esi
movzwl %ax, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x261a0
movq -0x98(%rbp), %rdi
movl %eax, %esi
movq -0x10(%rbp), %rax
addl 0x60(%rax), %esi
callq 0x2b450
jmp 0x2cf6f
movq -0x8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x321a0
movq -0xb0(%rbp), %rdi
movl $0x7c, %esi
movzwl %ax, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x261a0
movq -0xa8(%rbp), %rdi
movl %eax, %esi
movq -0x10(%rbp), %rax
addl 0x60(%rax), %esi
callq 0x2b450
jmp 0x2cf6f
movq -0x8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x321a0
movq -0xc0(%rbp), %rdi
movl $0x89, %esi
movzwl %ax, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x261a0
movq -0xb8(%rbp), %rdi
movl %eax, %esi
movq -0x10(%rbp), %rax
addl 0x60(%rax), %esi
callq 0x2b450
jmp 0x2cf6f
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x321a0
movq -0xd0(%rbp), %rdi
movl $0x8a, %esi
movzwl %ax, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x261a0
movq -0xc8(%rbp), %rdi
movl %eax, %esi
movq -0x10(%rbp), %rax
addl 0x60(%rax), %esi
callq 0x2b450
jmp 0x2cf6f
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x4760
movq %rax, -0xe8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x4760
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x74(%rax), %eax
movl %eax, -0xd4(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x225c0
movq -0xf0(%rbp), %rdi
movq -0xe8(%rbp), %r8
movq -0xe0(%rbp), %r9
movl -0xd4(%rbp), %r10d
leaq 0x12fcc(%rip), %rsi     # 0x3ff1f
movl $0xb79, %edx            # imm = 0xB79
leaq 0x13264(%rip), %rcx     # 0x401c3
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x18220
cmpq $0x0, -0x20(%rbp)
je 0x2cfac
movq -0x8(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x20(%rbp), %rdi
callq 0x321a0
movq -0xf8(%rbp), %rdi
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %eax
movzwl %ax, %esi
callq 0x2bae0
jmp 0x2cfe4
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x10(%rbp), %rax
movl 0x60(%rax), %r9d
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %r10d
movq -0x10(%rbp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x325f0
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax)