// File: 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:
subq $0x228, %rsp            # imm = 0x228
movq %rdi, 0x220(%rsp)
movq %rsi, 0x218(%rsp)
movq %rdx, 0x210(%rsp)
movq 0x220(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0x430a0
leaq 0x1d0(%rsp), %rdi
callq 0x430a0
jmp 0x29a18
movq 0x210(%rsp), %rax
movq %rax, 0x30(%rsp)
movl $0xe0, %edi
callq 0x8340
movq %rax, 0x38(%rsp)
jmp 0x29a36
movb $0x1, 0x157(%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x81a0
jmp 0x29a55
leaq 0x178(%rsp), %rdi
movl $0x2, %esi
leaq 0x158(%rsp), %rdx
callq 0x36d70
jmp 0x29a71
movq 0x38(%rsp), %rdi
movl $0x7, %esi
leaq 0x178(%rsp), %rdx
callq 0x36c00
jmp 0x29a8a
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rax
movb $0x0, 0x157(%rsp)
movq %rax, 0x1b8(%rsp)
leaq 0x1b8(%rsp), %rsi
callq 0x185b0
jmp 0x29ab3
leaq 0x178(%rsp), %rdi
callq 0x1f210
leaq 0x158(%rsp), %rdi
callq 0x8728
movq 0x218(%rsp), %rax
addq $0x148, %rax            # imm = 0x148
movq %rax, 0x20(%rsp)
leaq 0x12f(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x8680
movq 0x28(%rsp), %rdx
leaq 0xd1130(%rip), %rsi     # 0xfac2e
leaq 0x130(%rsp), %rdi
callq 0xc570
jmp 0x29b0d
movq 0x20(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x37480
jmp 0x29b21
leaq 0x130(%rsp), %rdi
callq 0x8728
leaq 0x12f(%rsp), %rdi
callq 0x83c0
movq 0x218(%rsp), %rdi
addq $0x198, %rdi            # imm = 0x198
leaq 0x1f0(%rsp), %rsi
callq 0x374b0
jmp 0x29b59
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x218(%rsp), %rsi
movq 0x210(%rsp), %rdx
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0x29b7d
movq 0x218(%rsp), %rdi
addq $0x148, %rdi            # imm = 0x148
callq 0x374e0
jmp 0x29b93
movq 0x218(%rsp), %rdi
addq $0x198, %rdi            # imm = 0x198
callq 0x374e0
jmp 0x29ba9
movq 0x218(%rsp), %rdi
addq $0xa8, %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x374b0
jmp 0x29bc7
movq 0x218(%rsp), %rdi
addq $0xf8, %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x374b0
jmp 0x29be5
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x218(%rsp), %rsi
movq 0x210(%rsp), %rdx
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
jmp 0x29c09
movq 0x210(%rsp), %rax
movq %rax, 0x10(%rsp)
movl $0xe0, %edi
callq 0x8340
movq %rax, 0x18(%rsp)
jmp 0x29c27
movb $0x1, 0xbf(%rsp)
leaq 0xc0(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x81a0
jmp 0x29c46
leaq 0xe0(%rsp), %rdi
movl $0x2, %esi
leaq 0xc0(%rsp), %rdx
callq 0x36d70
jmp 0x29c62
movq 0x18(%rsp), %rdi
movl $0xb, %esi
leaq 0xe0(%rsp), %rdx
callq 0x36c00
jmp 0x29c7b
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rax
movb $0x0, 0xbf(%rsp)
movq %rax, 0x120(%rsp)
leaq 0x120(%rsp), %rsi
callq 0x185b0
jmp 0x29ca4
leaq 0xe0(%rsp), %rdi
callq 0x1f210
leaq 0xc0(%rsp), %rdi
callq 0x8728
movq 0x218(%rsp), %rdi
addq $0xf8, %rdi
callq 0x374e0
jmp 0x29cd4
movq 0x218(%rsp), %rdi
addq $0xa8, %rdi
callq 0x374e0
jmp 0x29cea
movq 0x210(%rsp), %rax
movq %rax, (%rsp)
movl $0xe0, %edi
callq 0x8340
movq %rax, 0x8(%rsp)
jmp 0x29d07
movb $0x1, 0x4f(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x81a0
jmp 0x29d20
leaq 0x70(%rsp), %rdi
movl $0x2, %esi
leaq 0x50(%rsp), %rdx
callq 0x36d70
jmp 0x29d36
movq 0x8(%rsp), %rdi
movl $0x7, %esi
leaq 0x70(%rsp), %rdx
callq 0x36c00
jmp 0x29d4c
movq (%rsp), %rdi
movq 0x8(%rsp), %rax
movb $0x0, 0x4f(%rsp)
movq %rax, 0xb0(%rsp)
leaq 0xb0(%rsp), %rsi
callq 0x185b0
jmp 0x29d71
leaq 0x70(%rsp), %rdi
callq 0x1f210
leaq 0x50(%rsp), %rdi
callq 0x8728
leaq 0x1d0(%rsp), %rdi
callq 0x8728
leaq 0x1f0(%rsp), %rdi
callq 0x8728
addq $0x228, %rsp            # imm = 0x228
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29f8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29f81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29e33
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29e26
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x1f210
leaq 0x158(%rsp), %rdi
callq 0x8728
testb $0x1, 0x157(%rsp)
jne 0x29e3f
jmp 0x29e4e
movq 0x38(%rsp), %rdi
movl $0xe0, %esi
callq 0x8350
jmp 0x29f81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29e8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0x130(%rsp), %rdi
callq 0x8728
leaq 0x12f(%rsp), %rdi
callq 0x83c0
jmp 0x29f81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29ef6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29ee9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x1f210
leaq 0xc0(%rsp), %rdi
callq 0x8728
testb $0x1, 0xbf(%rsp)
jne 0x29f02
jmp 0x29f11
movq 0x18(%rsp), %rdi
movl $0xe0, %esi
callq 0x8350
jmp 0x29f81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29f67
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
jmp 0x29f5d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1c8(%rsp)
movl %eax, 0x1c4(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x1f210
leaq 0x50(%rsp), %rdi
callq 0x8728
testb $0x1, 0x4f(%rsp)
jne 0x29f70
jmp 0x29f7f
movq 0x8(%rsp), %rdi
movl $0xe0, %esi
callq 0x8350
jmp 0x29f81
leaq 0x1d0(%rsp), %rdi
callq 0x8728
leaq 0x1f0(%rsp), %rdi
callq 0x8728
movq 0x1c8(%rsp), %rdi
callq 0x8670
nopl (%rax,%rax)