// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_vm.c
// Function: emit_move
static void
emit_move(ir_unit_t *iu, ir_instr_move_t *ii)
{
  const ir_value_t *src = value_get(iu, ii->value.value);

  int retreg, typecode;

  if(ii->super.ii_ret.value == -2) {
    const ir_value_t *v1 = value_get(iu, ii->super.ii_rets[0].value);
    const ir_value_t *v2 = value_get(iu, ii->super.ii_rets[1].value);

    if(v1->iv_reg + 4 != v2->iv_reg ||
       ii->super.ii_rets[0].type != ii->super.ii_rets[1].type)
      parser_error(iu, "Bad aggregate destination for move");

    const ir_type_t *ty = type_get(iu, ii->super.ii_rets[0].type);
    typecode = legalize_type(ty);
    if(typecode != IR_TYPE_INT32)
      parser_error(iu, "Bad aggregate destination type for move");

    // Merge to one 64bit reg
    retreg = value_reg(v1);
    typecode = IR_TYPE_INT64;

  } else {

    const ir_value_t *ret = value_get(iu, ii->super.ii_ret.value);
    const ir_type_t *ty = type_get(iu, ii->super.ii_ret.type);
    retreg = value_reg(ret);
    typecode = legalize_type(ty);
  }

  switch(COMBINE2(src->iv_class, typecode)) {
  case COMBINE2(IR_VC_CONSTANT, IR_TYPE_INT8):
    emit_op1(iu, VM_MOV8_C, retreg);
    emit_i8(iu, value_get_const32(iu, src));
    return;
  case COMBINE2(IR_VC_CONSTANT, IR_TYPE_INT16):
    emit_op1(iu, VM_MOV16_C, retreg);
    emit_i16(iu, value_get_const32(iu, src));
    return;

  case COMBINE2(IR_VC_CONSTANT, IR_TYPE_INT1):
  case COMBINE2(IR_VC_CONSTANT, IR_TYPE_INT32):
  case COMBINE2(IR_VC_CONSTANT, IR_TYPE_POINTER):
  case COMBINE2(IR_VC_CONSTANT, IR_TYPE_FLOAT):
    emit_op1(iu, VM_MOV32_C, retreg);
    emit_i32(iu, value_get_const32(iu, src));
    return;

  case COMBINE2(IR_VC_CONSTANT, IR_TYPE_INT64):
  case COMBINE2(IR_VC_CONSTANT, IR_TYPE_DOUBLE):
    vm_align32(iu, 0);
    emit_op1(iu, VM_MOV64_C, retreg);
    emit_i64(iu, value_get_const64(iu, src));
    return;

  case COMBINE2(IR_VC_GLOBALVAR, IR_TYPE_POINTER):
    emit_op1(iu, VM_MOV32_C, retreg);
    emit_i32(iu, value_get_const32(iu, src));
    return;

  case COMBINE2(IR_VC_REGFRAME, IR_TYPE_INT1):
  case COMBINE2(IR_VC_REGFRAME, IR_TYPE_INT8):
  case COMBINE2(IR_VC_REGFRAME, IR_TYPE_INT16):
  case COMBINE2(IR_VC_REGFRAME, IR_TYPE_INT32):
  case COMBINE2(IR_VC_REGFRAME, IR_TYPE_POINTER):
  case COMBINE2(IR_VC_REGFRAME, IR_TYPE_FLOAT):
    emit_op2(iu, VM_MOV32, retreg, value_reg(src));
    return;
  case COMBINE2(IR_VC_REGFRAME, IR_TYPE_INT64):
  case COMBINE2(IR_VC_REGFRAME, IR_TYPE_DOUBLE):
    emit_op2(iu, VM_MOV64, retreg, value_reg(src));
    return;

  case COMBINE2(IR_VC_FUNCTION, IR_TYPE_FUNCTION):
  case COMBINE2(IR_VC_FUNCTION, IR_TYPE_POINTER):
    emit_op1(iu, VM_MOV32_C, retreg);
    emit_i32(iu, value_function_addr(src));
    break;
  default:
    parser_error(iu, "Can't emit %s", instr_str(iu, &ii->super, 0));
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
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 $-0x2, 0x2c(%rax)
jne 0x2de6a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl (%rax), %esi
callq 0x20ee0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x8(%rax), %esi
callq 0x20ee0
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
addl $0x4, %eax
movq -0x30(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jne 0x2ddef
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
cmpl 0xc(%rcx), %eax
je 0x2de0d
movq -0x8(%rbp), %rdi
leaq 0x12125(%rip), %rsi     # 0x3ff1f
movl $0xee0, %edx            # imm = 0xEE0
leaq 0x12516(%rip), %rcx     # 0x4031c
movb $0x0, %al
callq 0x18220
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x4(%rax), %esi
callq 0x1ee20
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x45d0
movl %eax, -0x20(%rbp)
cmpl $0x5, -0x20(%rbp)
je 0x2de55
movq -0x8(%rbp), %rdi
leaq 0x120dd(%rip), %rsi     # 0x3ff1f
movl $0xee5, %edx            # imm = 0xEE5
leaq 0x124f1(%rip), %rcx     # 0x4033f
movb $0x0, %al
callq 0x18220
movq -0x28(%rbp), %rdi
callq 0x321a0
movl %eax, -0x1c(%rbp)
movl $0x6, -0x20(%rbp)
jmp 0x2deaa
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %esi
callq 0x20ee0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %esi
callq 0x1ee20
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x321a0
movl %eax, -0x1c(%rbp)
movq -0x48(%rbp), %rdi
callq 0x45d0
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
shll $0x8, %eax
movl -0x20(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x4c(%rbp)
addl $0xfffffef5, %eax       # imm = 0xFFFFFEF5
subl $0x2, %eax
jb 0x2e155
jmp 0x2decb
movl -0x4c(%rbp), %eax
subl $0x20b, %eax            # imm = 0x20B
je 0x2e0a3
jmp 0x2dedb
movl -0x4c(%rbp), %eax
subl $0x302, %eax            # imm = 0x302
je 0x2e025
jmp 0x2deeb
movl -0x4c(%rbp), %eax
subl $0x303, %eax            # imm = 0x303
je 0x2dfb1
jmp 0x2defb
movl -0x4c(%rbp), %eax
subl $0x304, %eax            # imm = 0x304
je 0x2dfeb
jmp 0x2df0b
movl -0x4c(%rbp), %eax
subl $0x305, %eax            # imm = 0x305
je 0x2e025
jmp 0x2df1b
movl -0x4c(%rbp), %eax
subl $0x306, %eax            # imm = 0x306
je 0x2e05e
jmp 0x2df2b
movl -0x4c(%rbp), %eax
subl $0x308, %eax            # imm = 0x308
je 0x2e025
jmp 0x2df3b
movl -0x4c(%rbp), %eax
subl $0x309, %eax            # imm = 0x309
je 0x2e05e
jmp 0x2df4b
movl -0x4c(%rbp), %eax
subl $0x30b, %eax            # imm = 0x30B
je 0x2e025
jmp 0x2df5b
movl -0x4c(%rbp), %eax
addl $0xfffffafe, %eax       # imm = 0xFFFFFAFE
subl $0x4, %eax
jb 0x2e0dc
jmp 0x2df6e
movl -0x4c(%rbp), %eax
subl $0x506, %eax            # imm = 0x506
je 0x2e117
jmp 0x2df7e
movl -0x4c(%rbp), %eax
subl $0x508, %eax            # imm = 0x508
je 0x2e0dc
jmp 0x2df8e
movl -0x4c(%rbp), %eax
subl $0x509, %eax            # imm = 0x509
je 0x2e117
jmp 0x2df9e
movl -0x4c(%rbp), %eax
subl $0x50b, %eax            # imm = 0x50B
je 0x2e0dc
jmp 0x2e18d
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl $0x17d, %esi            # imm = 0x17D
movzwl %ax, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x261a0
movq -0x58(%rbp), %rdi
movzbl %al, %esi
callq 0x32500
jmp 0x2e1cb
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl $0x17e, %esi            # imm = 0x17E
movzwl %ax, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x261a0
movq -0x60(%rbp), %rdi
movzwl %ax, %esi
callq 0x2bae0
jmp 0x2e1cb
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl $0x17f, %esi            # imm = 0x17F
movzwl %ax, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x261a0
movq -0x68(%rbp), %rdi
movl %eax, %esi
callq 0x2b450
jmp 0x2e1cb
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x321f0
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl $0x180, %esi            # imm = 0x180
movzwl %ax, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x322d0
movq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x32240
jmp 0x2e1cb
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl $0x17f, %esi            # imm = 0x17F
movzwl %ax, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x261a0
movq -0x78(%rbp), %rdi
movl %eax, %esi
callq 0x2b450
jmp 0x2e1cb
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movl -0x1c(%rbp), %eax
movw %ax, -0x7a(%rbp)
movq -0x18(%rbp), %rdi
callq 0x321a0
movq -0x88(%rbp), %rdi
movw -0x7a(%rbp), %cx
movl $0x17b, %esi            # imm = 0x17B
movzwl %cx, %edx
movzwl %ax, %ecx
callq 0x324a0
jmp 0x2e1cb
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x1c(%rbp), %eax
movw %ax, -0x8a(%rbp)
movq -0x18(%rbp), %rdi
callq 0x321a0
movq -0x98(%rbp), %rdi
movw -0x8a(%rbp), %cx
movl $0x17c, %esi            # imm = 0x17C
movzwl %cx, %edx
movzwl %ax, %ecx
callq 0x324a0
jmp 0x2e1cb
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl $0x17f, %esi            # imm = 0x17F
movzwl %ax, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x323e0
movq -0xa0(%rbp), %rdi
movl %eax, %esi
callq 0x2b450
jmp 0x2e1cb
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
xorl %edx, %edx
callq 0x225c0
movq -0xa8(%rbp), %rdi
movq %rax, %r8
leaq 0x11d67(%rip), %rsi     # 0x3ff1f
movl $0xf24, %edx            # imm = 0xF24
leaq 0x121a3(%rip), %rcx     # 0x40367
movb $0x0, %al
callq 0x18220
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)