// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_vm.c
// Function: emit_cmp_select
static void
emit_cmp_select(ir_unit_t *iu, ir_instr_cmp_select_t *ii)
{
  int pred = ii->op;
  const ir_value_t *ret = value_get(iu, ii->super.ii_ret.value);
  const ir_value_t *lhs = value_get(iu, ii->lhs_value.value);
  const ir_value_t *rhs = value_get(iu, ii->rhs_value.value);
  const ir_value_t *trueval = value_get(iu, ii->true_value.value);
  const ir_value_t *falseval = value_get(iu, ii->false_value.value);
  const ir_type_t *it = type_get(iu, ii->lhs_value.type);

  int truereg;
  int falsereg;


  if(rhs->iv_class == IR_VC_REGFRAME && lhs->iv_class != IR_VC_REGFRAME) {
    // Swap LHS RHS
    const ir_value_t *tmp = rhs;
    rhs = lhs;
    lhs = tmp;
    pred = swap_pred(pred);
  }


  switch(trueval->iv_class) {
  case IR_VC_REGFRAME:
    truereg = value_reg(trueval);
    break;
  case IR_VC_CONSTANT:
  case IR_VC_GLOBALVAR:
    emit_op1(iu, VM_MOV32_C, 0);
    emit_i32(iu, value_get_const32(iu, trueval));
    truereg = 0;
    break;
  default:
    parser_error(iu, "Can't cmpselect value %s", value_str(iu, trueval));
  }

  switch(falseval->iv_class) {
  case IR_VC_REGFRAME:
    falsereg = value_reg(falseval);
    break;
  case IR_VC_CONSTANT:
  case IR_VC_GLOBALVAR:
    emit_op1(iu, VM_MOV32_C, 4);
    emit_i32(iu, value_get_const32(iu, falseval));
    falsereg = 4;
    break;
  default:
    parser_error(iu, "Can't cmpselect value %s", value_str(iu, falseval));
  }



  if(lhs->iv_class == IR_VC_REGFRAME &&
     rhs->iv_class == IR_VC_REGFRAME) {

    if(pred >= ICMP_EQ && pred <= ICMP_SLE) {

      switch(legalize_type(it)) {
      case IR_TYPE_INT32:
      case IR_TYPE_POINTER:
        emit_op(iu, pred - ICMP_EQ + VM_EQ32_SEL);
        break;

      default:
        parser_error(iu, "Can't cmpselect type %s class %d/%d op %d",
                     type_str(iu, it),
                     lhs->iv_class, rhs->iv_class, pred);
      }
      emit_i16(iu, value_reg(ret));
      emit_i16(iu, truereg);
      emit_i16(iu, falsereg);
      emit_i16(iu, value_reg(lhs));
      emit_i16(iu, value_reg(rhs));


    } else {
      parser_error(iu, "Can't compare pred %d", pred);
    }
    return;
  }

  if(lhs->iv_class == IR_VC_REGFRAME &&
     (rhs->iv_class == IR_VC_CONSTANT ||
      rhs->iv_class == IR_VC_GLOBALVAR)) {

    if(pred >= ICMP_EQ && pred <= ICMP_SLE) {

      switch(legalize_type(it)) {
      case IR_TYPE_INT32:
      case IR_TYPE_POINTER:
        emit_op(iu, pred - ICMP_EQ + VM_EQ32_C_SEL);
        emit_i16(iu, value_reg(ret));
        emit_i16(iu, truereg);
        emit_i16(iu, falsereg);
        emit_i16(iu, value_reg(lhs));
        emit_i32(iu, value_get_const32(iu, rhs));
        break;

      default:
        parser_error(iu, "Can't cmpsel type %s class %d/%d op %d",
                     type_str(iu, it),
                     lhs->iv_class, rhs->iv_class, pred);
      }
    } else {
      parser_error(iu, "Can't cmpsel pred %d (const)", pred);
    }
  } else {
    parser_error(iu, "Can't cmpsel value class %d and %d",
                 lhs->iv_class, rhs->iv_class);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x58(%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x2c(%rax), %esi
callq 0x20ee0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x5c(%rax), %esi
callq 0x20ee0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x64(%rax), %esi
callq 0x20ee0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %esi
callq 0x20ee0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x74(%rax), %esi
callq 0x20ee0
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x60(%rax), %esi
callq 0x1ee20
movq %rax, -0x48(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x31bba
movq -0x28(%rbp), %rax
cmpl $0x5, (%rax)
je 0x31bba
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %edi
callq 0x32da0
movl %eax, -0x14(%rbp)
movq -0x38(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
addl $-0x2, %eax
subl $0x2, %eax
jb 0x31be5
jmp 0x31bcd
movl -0x5c(%rbp), %eax
subl $0x5, %eax
jne 0x31c1e
jmp 0x31bd7
movq -0x38(%rbp), %rdi
callq 0x321a0
movl %eax, -0x4c(%rbp)
jmp 0x31c54
movq -0x8(%rbp), %rdi
movl $0x17f, %esi            # imm = 0x17F
xorl %edx, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x261a0
movq -0x68(%rbp), %rdi
movl %eax, %esi
callq 0x2b450
movl $0x0, -0x4c(%rbp)
jmp 0x31c54
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x264e0
movq -0x70(%rbp), %rdi
movq %rax, %r8
leaq 0xe2de(%rip), %rsi      # 0x3ff1f
movl $0xdcd, %edx            # imm = 0xDCD
leaq 0xea91(%rip), %rcx      # 0x406de
movb $0x0, %al
callq 0x18220
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x74(%rbp)
addl $-0x2, %eax
subl $0x2, %eax
jb 0x31c7f
jmp 0x31c67
movl -0x74(%rbp), %eax
subl $0x5, %eax
jne 0x31cbb
jmp 0x31c71
movq -0x40(%rbp), %rdi
callq 0x321a0
movl %eax, -0x50(%rbp)
jmp 0x31cf7
movq -0x8(%rbp), %rdi
movl $0x17f, %esi            # imm = 0x17F
movl $0x4, %edx
callq 0x32150
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x261a0
movq -0x80(%rbp), %rdi
movl %eax, %esi
callq 0x2b450
movl $0x4, -0x50(%rbp)
jmp 0x31cf7
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x8(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x264e0
movq -0x88(%rbp), %rdi
movq %rax, %r8
leaq 0xe23b(%rip), %rsi      # 0x3ff1f
movl $0xddb, %edx            # imm = 0xDDB
leaq 0xe9ee(%rip), %rcx      # 0x406de
movb $0x0, %al
callq 0x18220
movq -0x28(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x31e66
movq -0x30(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x31e66
cmpl $0x20, -0x14(%rbp)
jl 0x31e3f
cmpl $0x29, -0x14(%rbp)
jg 0x31e3f
movq -0x48(%rbp), %rdi
callq 0x45d0
movl %eax, %ecx
movl %ecx, -0x8c(%rbp)
subl $0x5, %eax
je 0x31d4a
jmp 0x31d3d
movl -0x8c(%rbp), %eax
subl $0xb, %eax
jne 0x31d61
jmp 0x31d4a
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
subl $0x20, %esi
addl $0x14f, %esi            # imm = 0x14F
callq 0x2b410
jmp 0x31db6
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x4760
movq -0x98(%rbp), %rdi
movq %rax, %r8
movq -0x28(%rbp), %rax
movl (%rax), %r9d
movq -0x30(%rbp), %rax
movl (%rax), %r10d
movl -0x14(%rbp), %eax
leaq 0xe184(%rip), %rsi      # 0x3ff1f
movl $0xdee, %edx            # imm = 0xDEE
leaq 0xe950(%rip), %rcx      # 0x406f7
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x18220
movq -0x8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x321a0
movq -0xb0(%rbp), %rdi
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %eax
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movl -0x50(%rbp), %eax
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x321a0
movq -0xa8(%rbp), %rdi
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x30(%rbp), %rdi
callq 0x321a0
movq -0xa0(%rbp), %rdi
movzwl %ax, %esi
callq 0x2bae0
jmp 0x31e61
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %r8d
leaq 0xe0d1(%rip), %rsi      # 0x3ff1f
movl $0xdf8, %edx            # imm = 0xDF8
leaq 0xe42c(%rip), %rcx      # 0x40286
movb $0x0, %al
callq 0x18220
jmp 0x3200e
movq -0x28(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x31fe2
movq -0x30(%rbp), %rax
cmpl $0x3, (%rax)
je 0x31e89
movq -0x30(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x31fe2
cmpl $0x20, -0x14(%rbp)
jl 0x31fbe
cmpl $0x29, -0x14(%rbp)
jg 0x31fbe
movq -0x48(%rbp), %rdi
callq 0x45d0
movl %eax, %ecx
movl %ecx, -0xb4(%rbp)
subl $0x5, %eax
je 0x31ec6
jmp 0x31eb5
movl -0xb4(%rbp), %eax
subl $0xb, %eax
jne 0x31f67
jmp 0x31ec6
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
subl $0x20, %esi
addl $0x159, %esi            # imm = 0x159
callq 0x2b410
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x20(%rbp), %rdi
callq 0x321a0
movq -0xd0(%rbp), %rdi
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %eax
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movl -0x50(%rbp), %eax
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x321a0
movq -0xc8(%rbp), %rdi
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x261a0
movq -0xc0(%rbp), %rdi
movl %eax, %esi
callq 0x2b450
jmp 0x31fbc
movq -0x8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x4760
movq -0xd8(%rbp), %rdi
movq %rax, %r8
movq -0x28(%rbp), %rax
movl (%rax), %r9d
movq -0x30(%rbp), %rax
movl (%rax), %r10d
movl -0x14(%rbp), %eax
leaq 0xdf7e(%rip), %rsi      # 0x3ff1f
movl $0xe11, %edx            # imm = 0xE11
leaq 0xe774(%rip), %rcx      # 0x40721
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x18220
jmp 0x31fe0
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %r8d
leaq 0xdf52(%rip), %rsi      # 0x3ff1f
movl $0xe14, %edx            # imm = 0xE14
leaq 0xe76f(%rip), %rcx      # 0x40748
movb $0x0, %al
callq 0x18220
jmp 0x3200e
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
movl (%rax), %r8d
movq -0x30(%rbp), %rax
movl (%rax), %r9d
leaq 0xdf24(%rip), %rsi      # 0x3ff1f
movl $0xe18, %edx            # imm = 0xE18
leaq 0xe75e(%rip), %rcx      # 0x40765
movb $0x0, %al
callq 0x18220
addq $0xf0, %rsp
popq %rbp
retq
nopw (%rax,%rax)