// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_transform.c
// Function: combine_select_with_compare
static void
combine_select_with_compare(ir_unit_t *iu, ir_instr_select_t *sel)
{
  ir_instr_t *iip;

  iip = combine_get_upstream_instruction(iu, sel->pred, &sel->super);
  if(iip == NULL || iip->ii_class != IR_IC_CMP2)
    return;
  ir_instr_binary_t *cmp = (ir_instr_binary_t *)iip;
  if(!(cmp->op >= ICMP_EQ && cmp->op <= ICMP_SLE))
    return;

  ir_type_t *cmpty = type_get(iu, cmp->lhs_value.type);
  if(!(cmpty->it_code == IR_TYPE_INT32 ||
       cmpty->it_code == IR_TYPE_POINTER))
    return;

  ir_type_t *opty = type_get(iu, sel->super.ii_ret.type);
  if(!(opty->it_code == IR_TYPE_INT8 ||
       opty->it_code == IR_TYPE_INT16 ||
       opty->it_code == IR_TYPE_INT32 ||
       opty->it_code == IR_TYPE_POINTER))
    return;

  assert(iip->ii_ret.value == sel->pred.value);

  ir_instr_cmp_select_t *ics =
    instr_add_after(sizeof(ir_instr_cmp_select_t), IR_IC_CMP_SELECT,
                    &sel->super);

  ics->op = cmp->op;
  ics->lhs_value = cmp->lhs_value;
  ics->rhs_value = cmp->rhs_value;
  ics->true_value = sel->true_value;
  ics->false_value = sel->false_value;
  ics->super.ii_ret = sel->super.ii_ret;

  instr_bind_input(iu, ics->lhs_value, &ics->super);
  instr_bind_input(iu, ics->rhs_value, &ics->super);
  instr_bind_input(iu, ics->true_value, &ics->super);
  instr_bind_input(iu, ics->false_value, &ics->super);
  value_bind_return_value(iu, &ics->super);

  value_get(iu, sel->pred.value)->iv_class = IR_VC_DEAD;

  instr_destroy(&sel->super);
  instr_destroy(iip);

  iu->iu_stats.cmp_select_combine++;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rdx
movq 0x68(%rax), %rsi
callq 0x275d0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x273fa
movq -0x18(%rbp), %rax
cmpl $0x7, 0x28(%rax)
je 0x273ff
jmp 0x275ca
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x20, 0x58(%rax)
jl 0x2741b
movq -0x20(%rbp), %rax
cmpl $0x29, 0x58(%rax)
jle 0x27420
jmp 0x275ca
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x60(%rax), %esi
callq 0x1ee20
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x5, (%rax)
je 0x2744b
movq -0x28(%rbp), %rax
cmpl $0xb, (%rax)
je 0x2744b
jmp 0x275ca
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %esi
callq 0x1ee20
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x3, (%rax)
je 0x27488
movq -0x30(%rbp), %rax
cmpl $0x4, (%rax)
je 0x27488
movq -0x30(%rbp), %rax
cmpl $0x5, (%rax)
je 0x27488
movq -0x30(%rbp), %rax
cmpl $0xb, (%rax)
je 0x27488
jmp 0x275ca
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x68(%rcx), %eax
jne 0x2749a
jmp 0x274b9
leaq 0x18314(%rip), %rdi     # 0x3f7b5
leaq 0x17f45(%rip), %rsi     # 0x3f3ed
movl $0x960, %edx            # imm = 0x960
leaq 0x18326(%rip), %rcx     # 0x3f7da
callq 0x31c0
movq -0x10(%rbp), %rdx
movl $0x80, %edi
movl $0x1a, %esi
callq 0x265e0
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movl 0x58(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x5c(%rcx), %rcx
movq %rcx, 0x5c(%rax)
movq -0x38(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x64(%rcx), %rcx
movq %rcx, 0x64(%rax)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x58(%rcx), %rcx
movq %rcx, 0x6c(%rax)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x60(%rcx), %rcx
movq %rcx, 0x74(%rax)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x2c(%rcx), %rcx
movq %rcx, 0x2c(%rax)
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq -0x38(%rbp), %rdx
movq 0x5c(%rax), %rsi
callq 0x267c0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq -0x38(%rbp), %rdx
movq 0x64(%rax), %rsi
callq 0x267c0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq -0x38(%rbp), %rdx
movq 0x6c(%rax), %rsi
callq 0x267c0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rax
movq -0x38(%rbp), %rdx
movq 0x74(%rax), %rsi
callq 0x267c0
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x20cf0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x68(%rax), %esi
callq 0x20ee0
movl $0xc, (%rax)
movq -0x10(%rbp), %rdi
callq 0x1cad0
movq -0x18(%rbp), %rdi
callq 0x1cad0
movq -0x8(%rbp), %rax
movl 0x610(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x610(%rax)
addq $0x40, %rsp
popq %rbp
retq