// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_vm.c
// Function: emit_cmp_branch
static void
emit_cmp_branch(ir_unit_t *iu, ir_instr_cmp_branch_t *ii)
{
  int pred = ii->op;
  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_type_t *it = type_get(iu, ii->lhs_value.type);

  int textpos = iu->iu_text_ptr - iu->iu_text_alloc;
  VECTOR_PUSH_BACK(&iu->iu_branch_fixups, textpos);

  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_INT8:
        emit_i16(iu, pred - ICMP_EQ + VM_EQ8_BR);
        break;

      case IR_TYPE_INT32:
      case IR_TYPE_POINTER:
        emit_i16(iu, pred - ICMP_EQ + VM_EQ32_BR);
        break;

      default:
        parser_error(iu, "Can't cmpbr type %s class %d/%d op %d",
                     type_str(iu, it),
                     lhs->iv_class, rhs->iv_class, pred);
      }
      emit_i16(iu, ii->true_branch);
      emit_i16(iu, ii->false_branch);
      emit_i16(iu, value_reg(lhs));
      emit_i16(iu, value_reg(rhs));


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

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

  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_INT8:
        emit_i16(iu, pred - ICMP_EQ + VM_EQ8_C_BR);
        emit_i16(iu, ii->true_branch);
        emit_i16(iu, ii->false_branch);
        emit_i16(iu, value_reg(lhs));
        emit_i8(iu, value_get_const32(iu, rhs));
        break;

      case IR_TYPE_INT32:
      case IR_TYPE_POINTER:
        emit_i16(iu, pred - ICMP_EQ + VM_EQ32_C_BR);
        emit_i16(iu, ii->true_branch);
        emit_i16(iu, ii->false_branch);
        emit_i16(iu, value_reg(lhs));
        emit_i32(iu, value_get_const32(iu, rhs));
        break;

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

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

    emit_i16(iu, pred - ICMP_EQ + VM_EQ32_C_BR);
    emit_i16(iu, ii->true_branch);
    emit_i16(iu, ii->false_branch);
    emit_i16(iu, value_reg(lhs));
    emit_i32(iu, value_function_addr(rhs));

  } else {
    parser_error(iu, "Can't brcmp value class %d and %d",
                 lhs->iv_class, rhs->iv_class);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %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 0x5c(%rax), %esi
callq 0x20ee0
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x64(%rax), %esi
callq 0x20ee0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x60(%rax), %esi
callq 0x1ee20
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x440(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x438(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x34(%rbp)
movq -0x8(%rbp), %rax
movq 0x310(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq -0x8(%rbp), %rcx
cmpq 0x318(%rcx), %rax
jbe 0x31664
movq -0x40(%rbp), %rcx
addq $0x1, %rcx
shlq %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x318(%rax)
movq -0x8(%rbp), %rax
movq 0x318(%rax), %rax
shlq $0x2, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x308(%rax), %rdi
movq -0x48(%rbp), %rsi
callq 0x3390
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x308(%rax)
movq -0x40(%rbp), %rcx
addq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x310(%rax)
movl -0x34(%rbp), %edx
movq -0x8(%rbp), %rax
movq 0x308(%rax), %rax
movq -0x40(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x20(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x317ed
movq -0x28(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x317ed
cmpl $0x20, -0x14(%rbp)
jl 0x317c6
cmpl $0x29, -0x14(%rbp)
jg 0x317c6
movq -0x30(%rbp), %rdi
callq 0x45d0
movl %eax, %ecx
movl %ecx, -0x54(%rbp)
subl $0x3, %eax
je 0x316e3
jmp 0x316cf
movl -0x54(%rbp), %eax
subl $0x5, %eax
je 0x316fc
jmp 0x316d9
movl -0x54(%rbp), %eax
subl $0xb, %eax
je 0x316fc
jmp 0x31715
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %eax
subl $0x20, %eax
addl $0x127, %eax            # imm = 0x127
movzwl %ax, %esi
callq 0x2bae0
jmp 0x31764
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %eax
subl $0x20, %eax
addl $0x13b, %eax            # imm = 0x13B
movzwl %ax, %esi
callq 0x2bae0
jmp 0x31764
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x4760
movq -0x60(%rbp), %rdi
movq %rax, %r8
movq -0x20(%rbp), %rax
movl (%rax), %r9d
movq -0x28(%rbp), %rax
movl (%rax), %r10d
movl -0x14(%rbp), %eax
leaq 0xe7d6(%rip), %rsi      # 0x3ff1f
movl $0xd60, %edx            # imm = 0xD60
leaq 0xef25(%rip), %rcx      # 0x4067a
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x18220
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %eax
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x70(%rax), %eax
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdi
callq 0x321a0
movq -0x70(%rbp), %rdi
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rdi
callq 0x321a0
movq -0x68(%rbp), %rdi
movzwl %ax, %esi
callq 0x2bae0
jmp 0x317e8
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %r8d
leaq 0xe74a(%rip), %rsi      # 0x3ff1f
movl $0xd69, %edx            # imm = 0xD69
leaq 0xeaa5(%rip), %rcx      # 0x40286
movb $0x0, %al
callq 0x18220
jmp 0x31adc
movq -0x28(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x31819
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x20(%rbp)
movl -0x14(%rbp), %edi
callq 0x32da0
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x31a10
movq -0x28(%rbp), %rax
cmpl $0x3, (%rax)
je 0x3183c
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x31a10
cmpl $0x20, -0x14(%rbp)
jl 0x319e9
cmpl $0x29, -0x14(%rbp)
jg 0x319e9
movq -0x30(%rbp), %rdi
callq 0x45d0
movl %eax, %ecx
movl %ecx, -0x74(%rbp)
subl $0x3, %eax
je 0x31884
jmp 0x31865
movl -0x74(%rbp), %eax
subl $0x5, %eax
je 0x3190a
jmp 0x31873
movl -0x74(%rbp), %eax
subl $0xb, %eax
je 0x3190a
jmp 0x31992
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %eax
subl $0x20, %eax
addl $0x131, %eax            # imm = 0x131
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %eax
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x70(%rax), %eax
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x20(%rbp), %rdi
callq 0x321a0
movq -0x88(%rbp), %rdi
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x261a0
movq -0x80(%rbp), %rdi
movzbl %al, %esi
callq 0x32500
jmp 0x319e7
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %eax
subl $0x20, %eax
addl $0x145, %eax            # imm = 0x145
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %eax
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x70(%rax), %eax
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x20(%rbp), %rdi
callq 0x321a0
movq -0x98(%rbp), %rdi
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x261a0
movq -0x90(%rbp), %rdi
movl %eax, %esi
callq 0x2b450
jmp 0x319e7
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x4760
movq -0xa0(%rbp), %rdi
movq %rax, %r8
movq -0x20(%rbp), %rax
movl (%rax), %r9d
movq -0x28(%rbp), %rax
movl (%rax), %r10d
movl -0x14(%rbp), %eax
leaq 0xe553(%rip), %rsi      # 0x3ff1f
movl $0xd91, %edx            # imm = 0xD91
leaq 0xeca2(%rip), %rcx      # 0x4067a
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x18220
jmp 0x31a0b
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %r8d
leaq 0xe527(%rip), %rsi      # 0x3ff1f
movl $0xd94, %edx            # imm = 0xD94
leaq 0xec9c(%rip), %rcx      # 0x406a0
movb $0x0, %al
callq 0x18220
jmp 0x31adc
movq -0x20(%rbp), %rax
cmpl $0x5, (%rax)
jne 0x31aae
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
jne 0x31aae
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %eax
subl $0x20, %eax
addl $0x145, %eax            # imm = 0x145
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %eax
movzwl %ax, %esi
callq 0x2bae0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x70(%rax), %eax
movzwl %ax, %esi
callq 0x2bae0
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), %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x323e0
movq -0xa8(%rbp), %rdi
movl %eax, %esi
callq 0x2b450
jmp 0x31ada
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl (%rax), %r8d
movq -0x28(%rbp), %rax
movl (%rax), %r9d
leaq 0xe458(%rip), %rsi      # 0x3ff1f
movl $0xda2, %edx            # imm = 0xDA2
leaq 0xebe9(%rip), %rcx      # 0x406bc
movb $0x0, %al
callq 0x18220
jmp 0x31adc
addq $0xc0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)