// File: /workspace/github_c_makefile_star2_O3/cogbee[P]vmir-latest/src/vmir_transform.c
// Function: combine_binop_add_mul
static void
combine_binop_add_mul(ir_unit_t *iu, ir_instr_binary_t *add,
                      ir_instr_binary_t *mul, int side)
{

  const ir_value_t *a1 = value_get(iu, mul->lhs_value.value);
  const ir_type_t *ty = type_get(iu, mul->lhs_value.type);
  if(ty->it_code != IR_TYPE_INT32)
    return;

  ir_value_t *a2 = value_get(iu, mul->rhs_value.value);
  const int arg3 = side ? add->lhs_value.value : add->rhs_value.value;
  ir_value_t *a3 = value_get(iu, arg3);

  assert(a1->iv_type == a2->iv_type);
  assert(a1->iv_type == a3->iv_type);

  if(a1->iv_class != IR_VC_TEMPORARY && a1->iv_class != IR_VC_REGFRAME)
    return;
  if(a2->iv_class != IR_VC_TEMPORARY && a2->iv_class != IR_VC_REGFRAME)
    return;
  if(a3->iv_class != IR_VC_TEMPORARY && a3->iv_class != IR_VC_REGFRAME)
    return;

  ir_instr_ternary_t *mla =
    instr_add_after(sizeof(ir_instr_ternary_t), IR_IC_MLA,
                    &add->super);

  mla->super.ii_ret = add->super.ii_ret;
  mla->arg1 = mul->lhs_value;
  mla->arg2 = mul->rhs_value;
  mla->arg3.value = arg3;
  mla->arg3.type = mla->arg2.type;

  instr_bind_input(iu, mla->arg1, &mla->super);
  instr_bind_input(iu, mla->arg2, &mla->super);
  instr_bind_input(iu, mla->arg3, &mla->super);
  value_bind_return_value(iu, &mla->super);

  value_get(iu, mul->super.ii_ret.value)->iv_class = IR_VC_DEAD;

  instr_destroy(&add->super);
  instr_destroy(&mul->super);

  iu->iu_stats.mla_combine++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rdi, %rbx
movl 0x5c(%rdx), %r8d
movq 0x188(%rdi), %rdx
cmpq %r8, %rdx
jbe 0x17241
movl 0x60(%r14), %eax
cmpq %rax, 0x170(%rbx)
jbe 0x17259
movq %rsi, %r15
movq 0x168(%rbx), %rsi
leaq (%rax,%rax,4), %rax
cmpl $0x5, (%rsi,%rax,8)
jne 0x17232
movl 0x64(%r14), %eax
cmpq %rax, %rdx
jbe 0x17271
xorl %esi, %esi
testl %ecx, %ecx
sete %sil
movl 0x5c(%r15,%rsi,8), %r12d
cmpq %r12, %rdx
jbe 0x1728c
movq 0x180(%rbx), %rsi
movq (%rsi,%r8,8), %rdx
movq (%rsi,%rax,8), %rcx
movl 0x24(%rdx), %edi
cmpl 0x24(%rcx), %edi
jne 0x172ac
movq (%rsi,%r12,8), %rax
cmpl 0x24(%rax), %edi
jne 0x172cb
movl (%rdx), %edx
andl $-0x2, %edx
cmpl $0x4, %edx
jne 0x17232
movl (%rcx), %ecx
andl $-0x2, %ecx
cmpl $0x4, %ecx
jne 0x17232
movl (%rax), %eax
andl $-0x2, %eax
cmpl $0x4, %eax
jne 0x17232
movq 0x10(%r15), %rbp
movl $0x1, %edi
movl $0x70, %esi
callq 0x32f0
movq %rax, %r13
movl $0x1b, 0x28(%rax)
movq %rbp, 0x10(%rax)
movq (%r15), %rax
movq %rax, (%r13)
addq $0x18, %rbp
leaq 0x8(%rax), %rcx
testq %rax, %rax
cmoveq %rbp, %rcx
movq %r13, (%rcx)
movq %r13, (%r15)
movq %r15, 0x8(%r13)
movq 0x2c(%r15), %rax
movq %rax, 0x2c(%r13)
movq 0x5c(%r14), %rsi
movq %rsi, 0x58(%r13)
movq 0x64(%r14), %rax
movq %rax, 0x60(%r13)
movl %r12d, 0x68(%r13)
shrq $0x20, %rax
movl %eax, 0x6c(%r13)
movq %rbx, %rdi
movq %r13, %rdx
callq 0x16c71
movq 0x60(%r13), %rsi
movq %rbx, %rdi
movq %r13, %rdx
callq 0x16c71
movq 0x68(%r13), %rsi
movq %rbx, %rdi
movq %r13, %rdx
callq 0x16c71
movq %rbx, %rdi
movq %r13, %rsi
callq 0x11d54
movl 0x2c(%r14), %r8d
cmpq %r8, 0x188(%rbx)
jbe 0x17241
movq 0x180(%rbx), %rax
movq (%rax,%r8,8), %rax
movl $0xc, (%rax)
movq %r15, %rdi
callq 0xef31
movq %r14, %rdi
callq 0xef31
incl 0x614(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xe328(%rip), %rsi      # 0x25570
leaq 0xead5(%rip), %rcx      # 0x25d24
movq %rbx, %rdi
movl $0x143, %edx            # imm = 0x143
jmp 0x172a5
leaq 0xe85c(%rip), %rsi      # 0x25abc
leaq 0xe88e(%rip), %rcx      # 0x25af5
movq %rbx, %rdi
movl $0x7c, %edx
jmp 0x17287
leaq 0xe2f8(%rip), %rsi      # 0x25570
leaq 0xeaa5(%rip), %rcx      # 0x25d24
movq %rbx, %rdi
movl $0x143, %edx            # imm = 0x143
movl %eax, %r8d
jmp 0x172a5
leaq 0xe2dd(%rip), %rsi      # 0x25570
leaq 0xea8a(%rip), %rcx      # 0x25d24
movq %rbx, %rdi
movl $0x143, %edx            # imm = 0x143
movl %r12d, %r8d
xorl %eax, %eax
callq 0xca98
leaq 0xf1e6(%rip), %rdi      # 0x26499
leaq 0xeea4(%rip), %rsi      # 0x2615e
leaq 0xf1f3(%rip), %rcx      # 0x264b4
movl $0x98c, %edx            # imm = 0x98C
callq 0x31e0
leaq 0xf239(%rip), %rdi      # 0x2650b
leaq 0xee85(%rip), %rsi      # 0x2615e
leaq 0xf1d4(%rip), %rcx      # 0x264b4
movl $0x98d, %edx            # imm = 0x98D
callq 0x31e0