// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x48(%rsp), %rdi
callq 0x1d9bf
cmpq $0x0, 0x20(%r15)
je 0x13ce9
leaq 0x8(%rsp), %rdi
callq 0x1d9bf
leaq 0x430ad(%rip), %rsi     # 0x56c17
leaq 0x28(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0xa292
leaq 0x148(%r14), %r12
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x1d120
leaq 0x28(%rsp), %rdi
callq 0x8578
leaq 0x198(%r14), %r13
leaq 0x8(%rsp), %rsi
movq %r13, %rdi
callq 0x1d3f8
movq 0x10(%r15), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movq %rbx, %rdx
callq *0x10(%rax)
movq %r12, %rdi
callq 0x1d4d6
movq %r13, %rdi
callq 0x1d4d6
movq 0x18(%r15), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movq %rbx, %rdx
callq *0x10(%rax)
movl $0xe0, %edi
callq 0x8250
movq %rax, %r12
leaq 0xa8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x8390
leaq 0x148(%rsp), %rdi
pushq $0x2
popq %rsi
leaq 0xa8(%rsp), %rdx
callq 0x1ac46
movb $0x1, %bpl
pushq $0xb
popq %rsi
leaq 0x148(%rsp), %rdx
movq %r12, %rdi
callq 0x1abbe
leaq 0x28(%rsp), %rsi
movq %r12, (%rsi)
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0xe358
leaq 0x150(%rsp), %rdi
callq 0x8578
leaq 0xa8(%rsp), %rdi
callq 0x8578
movl $0xe0, %edi
callq 0x8250
movq %rax, %r12
leaq 0x88(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8390
leaq 0x108(%rsp), %rdi
pushq $0x2
popq %rsi
leaq 0x88(%rsp), %rdx
callq 0x1ac46
movb $0x1, %bpl
pushq $0x7
popq %rsi
leaq 0x108(%rsp), %rdx
movq %r12, %rdi
callq 0x1abbe
leaq 0x28(%rsp), %rsi
movq %r12, (%rsi)
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0xe358
leaq 0x110(%rsp), %rdi
callq 0x8578
leaq 0x88(%rsp), %rdi
callq 0x8578
movq 0x20(%r15), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movq %rbx, %rdx
callq *0x10(%rax)
leaq 0x8(%rsp), %rdi
callq 0x8578
jmp 0x13d61
leaq 0x42f27(%rip), %rsi     # 0x56c17
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0xa292
leaq 0x148(%r14), %r12
leaq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x1d120
leaq 0x8(%rsp), %rdi
callq 0x8578
leaq 0x198(%r14), %r13
leaq 0x48(%rsp), %rsi
movq %r13, %rdi
callq 0x1d3f8
movq 0x10(%r15), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movq %rbx, %rdx
callq *0x10(%rax)
movq %r12, %rdi
callq 0x1d4d6
movq %r13, %rdi
callq 0x1d4d6
movq 0x18(%r15), %rdi
movq (%rdi), %rax
movq %r14, %rsi
movq %rbx, %rdx
callq *0x10(%rax)
movl $0xe0, %edi
callq 0x8250
movq %rax, %r14
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x8390
leaq 0xc8(%rsp), %rdi
pushq $0x2
popq %rsi
leaq 0x68(%rsp), %rdx
callq 0x1ac46
movb $0x1, %bpl
pushq $0x7
popq %rsi
leaq 0xc8(%rsp), %rdx
movq %r14, %rdi
callq 0x1abbe
leaq 0x8(%rsp), %rsi
movq %r14, (%rsi)
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0xe358
leaq 0xd0(%rsp), %rdi
callq 0x8578
leaq 0x68(%rsp), %rdi
callq 0x8578
leaq 0x48(%rsp), %rdi
callq 0x8578
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x13ebe
jmp 0x13e3d
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x13e55
jmp 0x13e0b
jmp 0x13ebe
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x13e6f
movq %rax, %rbx
jmp 0x13e81
jmp 0x13ebe
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x8578
jmp 0x13ec1
jmp 0x13ebe
jmp 0x13e3d
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x13ea0
movq %rax, %rbx
jmp 0x13eaf
jmp 0x13e3d
movq %rax, %rbx
jmp 0x13ecb
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x8578
leaq 0x88(%rsp), %rdi
jmp 0x13e77
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x8578
leaq 0xa8(%rsp), %rdi
callq 0x8578
testb %bpl, %bpl
je 0x13ec1
movl $0xe0, %esi
movq %r12, %rdi
callq 0x8260
jmp 0x13ec1
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x8578
leaq 0x68(%rsp), %rdi
callq 0x8578
testb %bpl, %bpl
je 0x13ecb
movl $0xe0, %esi
movq %r14, %rdi
callq 0x8260
jmp 0x13ecb
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8578
leaq 0x48(%rsp), %rdi
callq 0x8578
movq %rbx, %rdi
callq 0x84d0
nop