// File: /workspace/github_c_makefile_star2_O0/cogbee[P]vmir-latest/src/vmir_transform.c
// Function: combine_branch_with_compare
static void
combine_branch_with_compare(ir_unit_t *iu, ir_instr_br_t *br)
{
  ir_instr_t *iip;
  if(br->condition.value == -1)
    return;

  iip = combine_get_upstream_instruction(iu, br->condition, &br->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 *ty = type_get(iu, cmp->lhs_value.type);
  if(!(ty->it_code == IR_TYPE_INT8 ||
       ty->it_code == IR_TYPE_INT32 ||
       ty->it_code == IR_TYPE_POINTER))
    return;

  assert(iip->ii_ret.value == br->condition.value);

  ir_instr_cmp_branch_t *icb =
    instr_add_after(sizeof(ir_instr_cmp_branch_t), IR_IC_CMP_BRANCH,
                    &br->super);

  icb->op = cmp->op;
  icb->lhs_value = cmp->lhs_value;
  icb->rhs_value = cmp->rhs_value;
  icb->true_branch = br->true_branch;
  icb->false_branch = br->false_branch;

  instr_bind_input(iu, icb->lhs_value, &icb->super);
  instr_bind_input(iu, icb->rhs_value, &icb->super);

  value_get(iu, br->condition.value)->iv_class = IR_VC_DEAD;

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

  iu->iu_stats.cmp_branch_combine++;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x58(%rax)
jne 0x2713f
jmp 0x272ba
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rdx
movq 0x58(%rax), %rsi
callq 0x275d0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x27169
movq -0x18(%rbp), %rax
cmpl $0x7, 0x28(%rax)
je 0x2716e
jmp 0x272ba
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x20, 0x58(%rax)
jl 0x2718a
movq -0x20(%rbp), %rax
cmpl $0x29, 0x58(%rax)
jle 0x2718f
jmp 0x272ba
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x60(%rax), %esi
callq 0x1ee20
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x3, (%rax)
je 0x271c3
movq -0x28(%rbp), %rax
cmpl $0x5, (%rax)
je 0x271c3
movq -0x28(%rbp), %rax
cmpl $0xb, (%rax)
je 0x271c3
jmp 0x272ba
movq -0x18(%rbp), %rax
movl 0x2c(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jne 0x271d5
jmp 0x271f4
leaq 0x184e4(%rip), %rdi     # 0x3f6c0
leaq 0x1820a(%rip), %rsi     # 0x3f3ed
movl $0x92e, %edx            # imm = 0x92E
leaq 0x184fa(%rip), %rcx     # 0x3f6e9
callq 0x31c0
movq -0x10(%rbp), %rdx
movl $0x78, %edi
movl $0x19, %esi
callq 0x265e0
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movl 0x58(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x58(%rax)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x5c(%rcx), %rcx
movq %rcx, 0x5c(%rax)
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x64(%rcx), %rcx
movq %rcx, 0x64(%rax)
movq -0x10(%rbp), %rax
movl 0x60(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x6c(%rax)
movq -0x10(%rbp), %rax
movl 0x64(%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x70(%rax)
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq -0x30(%rbp), %rdx
movq 0x5c(%rax), %rsi
callq 0x267c0
movq -0x8(%rbp), %rdi
movq -0x30(%rbp), %rax
movq -0x30(%rbp), %rdx
movq 0x64(%rax), %rsi
callq 0x267c0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x58(%rax), %esi
callq 0x20ee0
movl $0xc, (%rax)
movq -0x10(%rbp), %rdi
callq 0x1cad0
movq -0x18(%rbp), %rdi
callq 0x1cad0
movq -0x8(%rbp), %rax
movl 0x60c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x60c(%rax)
addq $0x30, %rsp
popq %rbp
retq