// File: /workspace/github_cpp_makefile_star2_O3/luooofan[P]hblzbd_compiler/src/generate_ir.cpp
// Function: ast::BinaryExpression::GenerateIR(ir::ContextInfo&, std::vector<ir::IR*, std::allocator<ir::IR*>>&)
void BinaryExpression::GenerateIR(ir::ContextInfo &ctx, std::vector<ir::IR *> &gIRList) {
  ir::Opn opn1, opn2;
  IROpKind op;

  auto number = dynamic_cast<Number *>(lhs_.get());
  auto number2 = dynamic_cast<Number *>(&rhs_);
  if ((nullptr != number && number->value_ == 0) || (nullptr != number2 && number2->value_ == 0)) {
    switch (op_) {
      case MUL:
      case DIV:  // 实际上0不能作为div和mod的rhs
      case MOD:
        ctx.opn_ = ir::Opn(OpnType::Imm, 0);
        ctx.shape_.clear();
        return;
    }
  }

  lhs_->GenerateIR(ctx, gIRList);
  opn1 = ctx.opn_;
  CHECK_OPN_INT("lhs exp");

  rhs_.GenerateIR(ctx, gIRList);
  opn2 = ctx.opn_;
  CHECK_OPN_INT("rhs exp");

  if (opn1.type_ == OpnType::Imm && opn2.type_ == OpnType::Imm) {
    int result;
    int num1 = opn1.imm_num_, num2 = opn2.imm_num_;
    switch (op_) {
      case ADD:
        result = num1 + num2;
        break;
      case SUB:
        result = num1 - num2;
        break;
      case MUL:
        result = num1 * num2;
        break;
      case DIV:
        result = num1 / num2;
        break;
      case MOD:
        result = num1 % num2;
        break;
      default:
        // printf("mystery operator code: %d", op_);
        MyAssert(0);
        break;
    }
    ctx.opn_ = ir::Opn(OpnType::Imm, result);
  } else {
    switch (op_) {
      case ADD:
        op = IROpKind::ADD;
        break;
      case SUB:
        op = IROpKind::SUB;
        break;
      case MUL:
        op = IROpKind::MUL;
        break;
      case DIV:
        op = IROpKind::DIV;
        break;
      case MOD:
        op = IROpKind::MOD;
        break;
      default:
        // printf("mystery operator code: %d", op_);
        MyAssert(0);
        break;
    }
    const std::string &res_temp_var = ir::NewTemp();
    // NOTE: 中间变量栈偏移-1 并且不维护scope的dynamic offset
    ir::gScopes[ctx.scope_id_].symbol_table_.insert({res_temp_var, {false, false}});

    ir::Opn temp = ir::Opn(OpnType::Var, res_temp_var, ctx.scope_id_);
    ctx.opn_ = temp;
    gIRList.push_back(new ir::IR(op, opn1, opn2, temp));
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
movl $0x4, %eax
leaq 0x160(%rsp), %rdi
movl %eax, -0x18(%rdi)
movq %rdi, -0x10(%rdi)
movw $0x2d, %cx
movw %cx, (%rdi)
movl $0x1, %edx
movq %rdx, -0x8(%rdi)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %esi, 0x10(%rdi)
xorl %r13d, %r13d
movq %r13, 0x18(%rdi)
movl %esi, 0x20(%rdi)
leaq 0x120(%rsp), %rdi
movl %eax, -0x18(%rdi)
movq %rdi, -0x10(%rdi)
movw %cx, (%rdi)
movq %rdx, -0x8(%rdi)
movl %esi, 0x10(%rdi)
movq %r13, 0x18(%rdi)
movl %esi, 0x20(%rdi)
movq 0x10(%r12), %r15
testq %r15, %r15
je 0x14631
leaq 0x7983b(%rip), %rsi     # 0x8de58
leaq 0x7952c(%rip), %rdx     # 0x8db50
movq %r15, %rdi
xorl %ecx, %ecx
callq 0x8320
movq %rax, %r13
movq 0x20(%r12), %rdi
testq %rdi, %rdi
je 0x14652
leaq 0x79816(%rip), %rsi     # 0x8de58
leaq 0x79507(%rip), %rdx     # 0x8db50
xorl %ecx, %ecx
callq 0x8320
jmp 0x14654
xorl %eax, %eax
testq %r13, %r13
je 0x14660
cmpl $0x0, 0xc(%r13)
je 0x1466b
testq %rax, %rax
je 0x146cb
cmpl $0x0, 0xc(%rax)
jne 0x146cb
movl $0xfffffefb, %eax       # imm = 0xFFFFFEFB
addl 0xc(%r12), %eax
cmpl $0x2, %eax
ja 0x146cb
leaq 0x28(%rsp), %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x1279c
leaq 0x8(%r14), %rdi
leaq 0x28(%rsp), %rsi
callq 0x289a2
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x146b4
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x50(%r14), %rax
cmpq %rax, 0x58(%r14)
je 0x14d5e
movq %rax, 0x58(%r14)
jmp 0x14d5e
movq (%r15), %rax
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq *0x10(%rax)
leaq 0x8(%r14), %r15
leaq 0x148(%rsp), %rdi
movq %r15, %rsi
callq 0x288be
movq 0x50(%r14), %rax
cmpq 0x58(%r14), %rax
movq %r15, 0x20(%rsp)
je 0x14858
cmpl $0x4, 0x8(%r14)
jne 0x14858
movl 0x8(%r12), %ebp
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0xc6dc
leaq 0x5abbc(%rip), %rsi     # 0x6f2f0
movq %rsp, %rdi
callq 0x8590
leaq 0x5a791(%rip), %rsi     # 0x6eed4
movq %rsp, %rdi
callq 0x8590
leaq 0xa8(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1477b
movq %rdx, 0x98(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xa8(%rsp)
jmp 0x14783
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq %rbx, %r15
movq 0x8(%rax), %rdx
leaq 0x98(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x5a3d9(%rip), %rsi     # 0x6eb85
callq 0x8590
leaq 0x38(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x147d8
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0x147de
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
leaq 0x28(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl %ebp, %edi
callq 0x2b6aa
movq 0x28(%rsp), %rdi
cmpq %rbx, %rdi
je 0x14818
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x98(%rsp), %rdi
cmpq %r13, %rdi
movq %r15, %rbx
je 0x14838
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x82a0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
movq 0x20(%rsp), %r15
je 0x14858
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x20(%r12), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movq %rbx, %rdx
callq *0x10(%rax)
leaq 0x108(%rsp), %rdi
movq %r15, %rsi
callq 0x288be
movq 0x50(%r14), %rax
cmpq 0x58(%r14), %rax
je 0x149de
cmpl $0x4, 0x8(%r14)
jne 0x149de
movl 0x8(%r12), %ebp
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
movq %rsp, %rdi
callq 0xc6dc
leaq 0x5aa36(%rip), %rsi     # 0x6f2f0
movq %rsp, %rdi
callq 0x8590
leaq 0x5a550(%rip), %rsi     # 0x6ee19
movq %rsp, %rdi
callq 0x8590
leaq 0xa8(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x14901
movq %rdx, 0x98(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xa8(%rsp)
jmp 0x14909
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq %rbx, %r15
movq 0x8(%rax), %rdx
leaq 0x98(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x5a253(%rip), %rsi     # 0x6eb85
callq 0x8590
leaq 0x38(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1495e
movq %rdx, 0x28(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x38(%rsp)
jmp 0x14964
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
leaq 0x28(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl %ebp, %edi
callq 0x2b6aa
movq 0x28(%rsp), %rdi
cmpq %rbx, %rdi
je 0x1499e
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x98(%rsp), %rdi
cmpq %r13, %rdi
movq %r15, %rbx
je 0x149be
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x82a0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
movq 0x20(%rsp), %r15
je 0x149de
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x82a0
cmpl $0x1, 0x148(%rsp)
jne 0x14a2a
cmpl $0x1, 0x108(%rsp)
jne 0x14a2a
movl $0xfffffefe, %edx       # imm = 0xFFFFFEFE
addl 0xc(%r12), %edx
cmpl $0x5, %edx
ja 0x14e25
movl 0x14c(%rsp), %eax
movl 0x10c(%rsp), %ecx
leaq 0x5a0a2(%rip), %rsi     # 0x6eabc
movslq (%rsi,%rdx,4), %rdx
addq %rsi, %rdx
jmpq *%rdx
addl %eax, %ecx
jmp 0x14d25
movl $0xfffffefe, %eax       # imm = 0xFFFFFEFE
addl 0xc(%r12), %eax
cmpl $0x6, %eax
jae 0x14dba
movl $0x3b, %ecx
btl %eax, %ecx
jae 0x14dba
movl %eax, %eax
leaq 0x5a0e0(%rip), %rcx     # 0x6eb34
movl (%rcx,%rax,4), %ebp
movq %rsp, %rdi
callq 0x28564
movslq (%r14), %r12
leaq 0x7ab0f(%rip), %rax     # 0x8f578
shlq $0x6, %r12
addq (%rax), %r12
leaq 0x98(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x25368
leaq 0x28(%rsp), %rdi
movq %rsp, %rsi
leaq 0x98(%rsp), %rdx
callq 0x255fe
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x26bbc
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x14ac0
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x14ad7
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x14aee
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
leaq 0x38(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14b09
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x14b26
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x14b43
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x14b60
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x82a0
movq %rbx, %r15
leaq 0xf8(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe8(%rsp), %rdi
callq 0xc6dc
movl (%r14), %ebx
leaq 0x30(%rsp), %rdi
movl $0x0, -0x8(%rdi)
leaq 0x40(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0xe8(%rsp), %rsi
movq 0xf0(%rsp), %rdx
addq %rsi, %rdx
callq 0xc6dc
movl %ebx, 0x50(%rsp)
movq $0x0, 0x58(%rsp)
movl $0xffffffff, 0x60(%rsp) # imm = 0xFFFFFFFF
movq 0xe8(%rsp), %rdi
cmpq %r13, %rdi
je 0x14beb
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0x288be
movq %r15, %rbx
movl $0xe0, %edi
callq 0x8290
movq %rax, %r14
leaq 0x188(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x28816
leaq 0x208(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x28816
leaq 0x1c8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x28816
movb $0x1, %r15b
leaq 0x188(%rsp), %rdx
leaq 0x208(%rsp), %rcx
leaq 0x1c8(%rsp), %r8
movq %r14, %rdi
movl %ebp, %esi
callq 0x256ba
leaq 0x98(%rsp), %rsi
movq %r14, (%rsi)
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x11182
leaq 0x1e0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14ca2
movq 0x1e0(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x220(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14cc3
movq 0x220(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14ce4
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x14cfb
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14d5e
movq 0x10(%rsp), %rsi
jmp 0x14d56
cltd
idivl %ecx
movl %edx, %ecx
jmp 0x14d25
imull %eax, %ecx
jmp 0x14d25
cltd
idivl %ecx
jmp 0x14d23
subl %ecx, %eax
movl %eax, %ecx
leaq 0x28(%rsp), %rdi
movl $0x1, %esi
movl %ecx, %edx
callq 0x1279c
leaq 0x28(%rsp), %rsi
movq %r15, %rdi
callq 0x289a2
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14d5e
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x14d83
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x150(%rsp), %rdi
leaq 0x160(%rsp), %rax
cmpq %rax, %rdi
je 0x14da8
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x82a0
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x7a227(%rip), %rdi     # 0x8efe8
leaq 0x593a0(%rip), %rsi     # 0x6e168
movl $0x8, %edx
callq 0x8330
movq 0x7a20f(%rip), %rdi     # 0x8efe8
leaq 0x59db3(%rip), %rsi     # 0x6eb93
movl $0x13, %edx
callq 0x8330
movq 0x7a1f7(%rip), %rdi     # 0x8efe8
leaq 0x5a5c8(%rip), %rsi     # 0x6f3c0
movl $0x1, %edx
callq 0x8330
movq 0x7a1df(%rip), %rdi     # 0x8efe8
movl $0x11a, %esi            # imm = 0x11A
callq 0x8520
movq %rax, %rdi
callq 0x8180
movl $0xff, %edi
callq 0x8380
movq 0x7a1bc(%rip), %rdi     # 0x8efe8
leaq 0x59335(%rip), %rsi     # 0x6e168
movl $0x8, %edx
callq 0x8330
movq 0x7a1a4(%rip), %rdi     # 0x8efe8
leaq 0x59d48(%rip), %rsi     # 0x6eb93
movl $0x13, %edx
callq 0x8330
movq 0x7a18c(%rip), %rdi     # 0x8efe8
leaq 0x5a55d(%rip), %rsi     # 0x6f3c0
movl $0x1, %edx
callq 0x8330
movq 0x7a174(%rip), %rdi     # 0x8efe8
movl $0x103, %esi            # imm = 0x103
callq 0x8520
movq %rax, %rdi
callq 0x8180
jmp 0x14e1b
jmp 0x1507b
jmp 0x14f37
jmp 0x1507b
movq %rax, %rbp
movb $0x1, %r15b
jmp 0x14ff3
movq %rax, %rbp
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1503a
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1503a
movq %rax, %rbp
jmp 0x1503a
jmp 0x14ed9
movq %rax, %rbp
jmp 0x15047
movq %rax, %rbp
movq 0xe8(%rsp), %rdi
cmpq %r13, %rdi
je 0x1505e
movq 0xf8(%rsp), %rsi
jmp 0x15056
jmp 0x14f28
movq %rax, %rbp
leaq 0x28(%rsp), %rdi
callq 0x254bc
jmp 0x14f16
movq %rax, %rbp
leaq 0x98(%rsp), %rdi
callq 0x2551a
jmp 0x1505e
movq %rax, %rbp
jmp 0x1505e
jmp 0x1507b
jmp 0x14f66
movq %rax, %rbp
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1507e
movq 0x40(%rsp), %rsi
jmp 0x15071
jmp 0x14f82
jmp 0x1507b
jmp 0x14fa4
jmp 0x14fb5
jmp 0x1507b
movq %rax, %rbp
movq 0x28(%rsp), %rdi
cmpq %rbx, %rdi
je 0x14f85
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x14f85
movq %rax, %rbp
movq 0x98(%rsp), %rdi
cmpq %r13, %rdi
je 0x14fa7
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x14fa7
movq %rax, %rbp
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
jmp 0x15067
movq %rax, %rbp
movq (%rsp), %rdi
cmpq %r15, %rdi
jne 0x1506c
jmp 0x1507e
jmp 0x1507b
movq %rax, %rbp
leaq 0x1e0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x14ff3
movq 0x1e0(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x220(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15014
movq 0x220(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x15035
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x82a0
testb %r15b, %r15b
je 0x15047
movl $0xe0, %esi
movq %r14, %rdi
callq 0x82a0
movq 0x30(%rsp), %rdi
cmpq %r12, %rdi
je 0x1505e
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x82a0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1507e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x82a0
jmp 0x1507e
movq %rax, %rbp
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x150a3
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x82a0
movq 0x150(%rsp), %rdi
leaq 0x160(%rsp), %rax
cmpq %rax, %rdi
je 0x150c8
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x82a0
movq %rbp, %rdi
callq 0x8540