// File: Eronana[P]strawberry/src/ast_codegen.cpp
// Function: AST_WhileStatement::codeGen(Symbol*)
DEF_AST_METHOD(WhileStatement,AST_CODEGEN)
{
    int beginLabel=nextLabel();
    int endLabel=nextLabel();
    continueStack.push(beginLabel);
    breakStack.push(endLabel);
    GET_SCOPE();
    PRINTF("; while statement\n");
    PRINTF("label_%d:\n",beginLabel);
    PRINTF("; check expression\n");
    CODEGEN(expr);
    PRINTF("istrue\n");
    PRINTF("jmp label_%d\n",endLabel);
    PRINTF("; statement\n");
    CODEGEN(statement);
    PRINTF("jmp label_%d\n",beginLabel);
    PRINTF("label_%d:\n",endLabel);

    continueStack.pop();
    breakStack.pop();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
callq 0x1a000
movl %eax, -0x14(%rbp)
callq 0x1a000
movl %eax, -0x18(%rbp)
leaq 0x35f79(%rip), %rdi     # 0x8a798
leaq -0x14(%rbp), %rsi
callq 0x55580
leaq 0x35fb9(%rip), %rdi     # 0x8a7e8
leaq -0x18(%rbp), %rsi
callq 0x55580
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq 0x35f21(%rip), %rdi     # 0x8a768
leaq -0x20(%rbp), %rsi
callq 0x20310
movq %rax, %rdi
callq 0x203f0
movq %rax, -0x10(%rbp)
movl 0x363ae(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x363a5(%rip)     # 0x8ac10
leaq 0x36076(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x511a(%rip), %rsi      # 0x59996
movb $0x0, %al
callq 0x74c0
movl 0x36387(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x3637e(%rip)     # 0x8ac10
leaq 0x3604f(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x5030(%rip), %rsi      # 0x598d6
movb $0x0, %al
callq 0x74c0
movl 0x3635d(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36354(%rip)     # 0x8ac10
leaq 0x36025(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5085(%rip), %rsi      # 0x59952
movb $0x0, %al
callq 0x74c0
movq -0x28(%rbp), %rdi
addq $0x8, %rdi
callq 0x8f60
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movl 0x3631c(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36313(%rip)     # 0x8ac10
leaq 0x35fe4(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x4f5f(%rip), %rsi      # 0x5986d
movb $0x0, %al
callq 0x74c0
movl 0x362f5(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x362ec(%rip)     # 0x8ac10
leaq 0x35fbd(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x4f3d(%rip), %rsi      # 0x59875
movb $0x0, %al
callq 0x74c0
movl 0x362cb(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x362c2(%rip)     # 0x8ac10
leaq 0x35f93(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5007(%rip), %rsi      # 0x59966
movb $0x0, %al
callq 0x74c0
movq -0x28(%rbp), %rdi
addq $0x10, %rdi
callq 0x8f60
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movl 0x3628a(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36281(%rip)     # 0x8ac10
leaq 0x35f52(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x4ed2(%rip), %rsi      # 0x59875
movb $0x0, %al
callq 0x74c0
movl 0x36260(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36257(%rip)     # 0x8ac10
leaq 0x35f28(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x4f09(%rip), %rsi      # 0x598d6
movb $0x0, %al
callq 0x74c0
leaq 0x35dbd(%rip), %rdi     # 0x8a798
callq 0x555b0
leaq 0x35e01(%rip), %rdi     # 0x8a7e8
callq 0x555b0
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)