// File: /workspace/github_cpp_makefile_star2_O2/luooofan[P]hblzbd_compiler/src/generate_ir.cpp
// Function: ast::WhileStatement::GenerateIR(ir::ContextInfo&, std::vector<ir::IR*, std::allocator<ir::IR*>>&)
void WhileStatement::GenerateIR(ir::ContextInfo &ctx, std::vector<ir::IR *> &gIRList) {
  std::string label_next = ir::NewLabel();
  std::string label_begin = ir::NewLabel();
  // genir(label,begin,-,-)
  gIRList.push_back(new ir::IR(IROpKind::LABEL, LABEL_OPN(label_begin)));
  ctx.true_label_.push("null");
  ctx.false_label_.push(label_next);
  this->cond_.GenerateIR(ctx, gIRList);
  ctx.true_label_.pop();
  ctx.false_label_.pop();

  // maybe useless
  ctx.break_label_.push(label_next);
  ctx.continue_label_.push(label_begin);

  this->bodystmt_.GenerateIR(ctx, gIRList);
  // genir(goto,begin,-,-)
  gIRList.push_back(new ir::IR(IROpKind::GOTO, LABEL_OPN(label_begin)));

  ctx.continue_label_.pop();
  ctx.break_label_.pop();

  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
leaq 0x28(%rsp), %rdi
callq 0x1d9bf
movl $0xe0, %edi
callq 0x8250
movq %rax, %r12
leaq 0xa8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x8390
leaq 0x148(%rsp), %rdi
pushq $0x2
popq %rsi
leaq 0xa8(%rsp), %rdx
callq 0x1ac46
movb $0x1, %bpl
pushq $0x7
popq %rsi
leaq 0x148(%rsp), %rdx
movq %r12, %rdi
callq 0x1abbe
leaq 0x8(%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
leaq 0x42c8b(%rip), %rsi     # 0x56c17
leaq 0x8(%rsp), %rdi
leaq 0x7(%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
leaq 0xa8(%r14), %r12
leaq 0x48(%rsp), %rsi
movq %r12, %rdi
callq 0x1d3f8
leaq 0xf8(%r14), %r13
leaq 0x28(%rsp), %rsi
movq %r13, %rdi
callq 0x1d3f8
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 0x88(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x8390
leaq 0x108(%rsp), %rdi
pushq $0x2
popq %rsi
leaq 0x88(%rsp), %rdx
callq 0x1ac46
movb $0x1, %bpl
pushq $0xb
popq %rsi
leaq 0x108(%rsp), %rdx
movq %r14, %rdi
callq 0x1abbe
leaq 0x8(%rsp), %rsi
movq %r14, (%rsi)
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0xe358
leaq 0x110(%rsp), %rdi
callq 0x8578
leaq 0x88(%rsp), %rdi
callq 0x8578
movq %r13, %rdi
callq 0x1d4d6
movq %r12, %rdi
callq 0x1d4d6
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 0x28(%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
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x141a3
jmp 0x1415b
jmp 0x14207
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x141ba
movq %rax, %rbx
jmp 0x141cc
jmp 0x14207
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x8578
jmp 0x1420a
jmp 0x14207
movq %rax, %rbx
movb $0x1, %bpl
jmp 0x141e6
movq %rax, %rbx
jmp 0x141f8
jmp 0x14207
movq %rax, %rbx
jmp 0x14214
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x8578
leaq 0x68(%rsp), %rdi
jmp 0x141c2
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x8578
leaq 0x88(%rsp), %rdi
callq 0x8578
testb %bpl, %bpl
je 0x1420a
movl $0xe0, %esi
movq %r14, %rdi
jmp 0x14200
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
callq 0x8578
leaq 0xa8(%rsp), %rdi
callq 0x8578
testb %bpl, %bpl
je 0x1420a
movl $0xe0, %esi
movq %r12, %rdi
callq 0x8260
jmp 0x1420a
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x8578
leaq 0x48(%rsp), %rdi
callq 0x8578
movq %rbx, %rdi
callq 0x84d0