// File: luooofan[P]hblzbd_compiler/src/generate_ir.cpp
// Function: ast::IfElseStatement::GenerateIR(ir::ContextInfo&, std::vector<ir::IR*, std::allocator<ir::IR*>>&)
void IfElseStatement::GenerateIR(ir::ContextInfo &ctx, std::vector<ir::IR *> &gIRList) {
  std::string label_next = ir::NewLabel();
  if (nullptr == this->elsestmt_) {
    // if then
    ctx.true_label_.push("null");
    ctx.false_label_.push(label_next);
    this->cond_.GenerateIR(ctx, gIRList);
    ctx.true_label_.pop();
    ctx.false_label_.pop();
    this->thenstmt_.GenerateIR(ctx, gIRList);
  } else {
    // if then else
    std::string label_else = ir::NewLabel();
    ctx.true_label_.push("null");
    ctx.false_label_.push(label_else);
    this->cond_.GenerateIR(ctx, gIRList);
    ctx.true_label_.pop();
    ctx.false_label_.pop();
    this->thenstmt_.GenerateIR(ctx, gIRList);
    // genir(goto,next,-,-)
    gIRList.push_back(new ir::IR(IROpKind::GOTO, LABEL_OPN(label_next)));
    // genir(label,else,-,-)
    gIRList.push_back(new ir::IR(IROpKind::LABEL, LABEL_OPN(label_else)));
    this->elsestmt_->GenerateIR(ctx, gIRList);
  }
  gIRList.push_back(new ir::IR(IROpKind::LABEL, LABEL_OPN(label_next)));
}

// Assembly:
subq $0x268, %rsp            # imm = 0x268
movq %rdi, 0x260(%rsp)
movq %rsi, 0x258(%rsp)
movq %rdx, 0x250(%rsp)
movq 0x260(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x230(%rsp), %rdi
callq 0x430a0
movq 0x58(%rsp), %rcx
xorl %eax, %eax
cmpq 0x20(%rcx), %rax
jne 0x29471
movq 0x258(%rsp), %rax
addq $0x148, %rax            # imm = 0x148
movq %rax, 0x48(%rsp)
leaq 0x20f(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x8680
movq 0x50(%rsp), %rdx
leaq 0xd18f3(%rip), %rsi     # 0xfac2e
leaq 0x210(%rsp), %rdi
callq 0xc570
jmp 0x2934a
movq 0x48(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x37480
jmp 0x2935e
leaq 0x210(%rsp), %rdi
callq 0x8728
leaq 0x20f(%rsp), %rdi
callq 0x83c0
movq 0x258(%rsp), %rdi
addq $0x198, %rdi            # imm = 0x198
leaq 0x230(%rsp), %rsi
callq 0x374b0
jmp 0x29396
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x258(%rsp), %rsi
movq 0x250(%rsp), %rdx
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0x293ba
movq 0x258(%rsp), %rdi
addq $0x148, %rdi            # imm = 0x148
callq 0x374e0
jmp 0x293d0
movq 0x258(%rsp), %rdi
addq $0x198, %rdi            # imm = 0x198
callq 0x374e0
jmp 0x293e6
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x258(%rsp), %rsi
movq 0x250(%rsp), %rdx
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0x2940a
jmp 0x29882
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
jmp 0x29446
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
leaq 0x210(%rsp), %rdi
callq 0x8728
leaq 0x20f(%rsp), %rdi
callq 0x83c0
jmp 0x299ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
jmp 0x299ae
leaq 0x1d8(%rsp), %rdi
callq 0x430a0
jmp 0x29480
movq 0x258(%rsp), %rax
addq $0x148, %rax            # imm = 0x148
movq %rax, 0x38(%rsp)
leaq 0x1b7(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0x8680
movq 0x40(%rsp), %rdx
leaq 0xd177d(%rip), %rsi     # 0xfac2e
leaq 0x1b8(%rsp), %rdi
callq 0xc570
jmp 0x294c0
movq 0x38(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x37480
jmp 0x294d4
leaq 0x1b8(%rsp), %rdi
callq 0x8728
leaq 0x1b7(%rsp), %rdi
callq 0x83c0
movq 0x258(%rsp), %rdi
addq $0x198, %rdi            # imm = 0x198
leaq 0x1d8(%rsp), %rsi
callq 0x374b0
jmp 0x2950c
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x258(%rsp), %rsi
movq 0x250(%rsp), %rdx
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0x29530
movq 0x258(%rsp), %rdi
addq $0x148, %rdi            # imm = 0x148
callq 0x374e0
jmp 0x29546
movq 0x258(%rsp), %rdi
addq $0x198, %rdi            # imm = 0x198
callq 0x374e0
jmp 0x2955c
movq 0x58(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x258(%rsp), %rsi
movq 0x250(%rsp), %rdx
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0x29580
movq 0x250(%rsp), %rax
movq %rax, 0x28(%rsp)
movl $0xe0, %edi
callq 0x8340
movq %rax, 0x30(%rsp)
jmp 0x2959e
movb $0x1, 0x147(%rsp)
leaq 0x148(%rsp), %rdi
leaq 0x230(%rsp), %rsi
callq 0x81a0
jmp 0x295bd
leaq 0x168(%rsp), %rdi
movl $0x2, %esi
leaq 0x148(%rsp), %rdx
callq 0x36d70
jmp 0x295d9
movq 0x30(%rsp), %rdi
movl $0xb, %esi
leaq 0x168(%rsp), %rdx
callq 0x36c00
jmp 0x295f2
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rax
movb $0x0, 0x147(%rsp)
movq %rax, 0x1a8(%rsp)
leaq 0x1a8(%rsp), %rsi
callq 0x185b0
jmp 0x2961b
leaq 0x168(%rsp), %rdi
callq 0x1f210
leaq 0x148(%rsp), %rdi
callq 0x8728
movq 0x250(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0xe0, %edi
callq 0x8340
movq %rax, 0x20(%rsp)
jmp 0x29653
movb $0x1, 0xd7(%rsp)
leaq 0xd8(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
callq 0x81a0
jmp 0x29672
leaq 0xf8(%rsp), %rdi
movl $0x2, %esi
leaq 0xd8(%rsp), %rdx
callq 0x36d70
jmp 0x2968e
movq 0x20(%rsp), %rdi
movl $0x7, %esi
leaq 0xf8(%rsp), %rdx
callq 0x36c00
jmp 0x296a7
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %rax
movb $0x0, 0xd7(%rsp)
movq %rax, 0x138(%rsp)
leaq 0x138(%rsp), %rsi
callq 0x185b0
jmp 0x296d0
leaq 0xf8(%rsp), %rdi
callq 0x1f210
leaq 0xd8(%rsp), %rdi
callq 0x8728
movq 0x58(%rsp), %rax
movq 0x20(%rax), %rdi
movq 0x258(%rsp), %rsi
movq 0x250(%rsp), %rdx
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0x2970e
leaq 0x1d8(%rsp), %rdi
callq 0x8728
jmp 0x29882
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
jmp 0x29757
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x8728
leaq 0x1b7(%rsp), %rdi
callq 0x83c0
jmp 0x29870
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
jmp 0x29870
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
jmp 0x297dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
jmp 0x297cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x1f210
leaq 0x148(%rsp), %rdi
callq 0x8728
testb $0x1, 0x147(%rsp)
jne 0x297e8
jmp 0x297f7
movq 0x30(%rsp), %rdi
movl $0xe0, %esi
callq 0x8350
jmp 0x29870
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
jmp 0x29853
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
jmp 0x29846
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x1f210
leaq 0xd8(%rsp), %rdi
callq 0x8728
testb $0x1, 0xd7(%rsp)
jne 0x2985f
jmp 0x2986e
movq 0x20(%rsp), %rdi
movl $0xe0, %esi
callq 0x8350
jmp 0x29870
leaq 0x1d8(%rsp), %rdi
callq 0x8728
jmp 0x299ae
movq 0x250(%rsp), %rax
movq %rax, 0x8(%rsp)
movl $0xe0, %edi
callq 0x8340
movq %rax, 0x10(%rsp)
jmp 0x298a0
movb $0x1, 0x67(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x230(%rsp), %rsi
callq 0x81a0
jmp 0x298b9
leaq 0x88(%rsp), %rdi
movl $0x2, %esi
leaq 0x68(%rsp), %rdx
callq 0x36d70
jmp 0x298d2
movq 0x10(%rsp), %rdi
movl $0x7, %esi
leaq 0x88(%rsp), %rdx
callq 0x36c00
jmp 0x298eb
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rax
movb $0x0, 0x67(%rsp)
movq %rax, 0xc8(%rsp)
leaq 0xc8(%rsp), %rsi
callq 0x185b0
jmp 0x29911
leaq 0x88(%rsp), %rdi
callq 0x1f210
leaq 0x68(%rsp), %rdi
callq 0x8728
leaq 0x230(%rsp), %rdi
callq 0x8728
addq $0x268, %rsp            # imm = 0x268
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
jmp 0x29994
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
jmp 0x2998a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x200(%rsp)
movl %eax, 0x1fc(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x1f210
leaq 0x68(%rsp), %rdi
callq 0x8728
testb $0x1, 0x67(%rsp)
jne 0x2999d
jmp 0x299ac
movq 0x10(%rsp), %rdi
movl $0xe0, %esi
callq 0x8350
jmp 0x299ae
leaq 0x230(%rsp), %rdi
callq 0x8728
movq 0x200(%rsp), %rdi
callq 0x8670
nopl (%rax,%rax)