// File: Eronana[P]strawberry/src/ast_codegen.cpp
// Function: AST_ForStatement::codeGen(Symbol*)
DEF_AST_METHOD(ForStatement,AST_CODEGEN)
{
    int beginLabel=nextLabel();
    int endLabel=nextLabel();
    int continueLabel=nextLabel();
    continueStack.push(continueLabel);
    breakStack.push(endLabel);
    GET_SCOPE();
    PRINTF("; for statement\n");
    PRINTF("; init\n");
    CODEGEN(init);
    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("label_%d:\n",continueLabel);
    PRINTF("; loop expression\n");
    CODEGEN(loopExpr);
    PRINTF("pop\n");
    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, -0x30(%rbp)
callq 0x1a000
movl %eax, -0x14(%rbp)
callq 0x1a000
movl %eax, -0x18(%rbp)
callq 0x1a000
movl %eax, -0x1c(%rbp)
leaq 0x36461(%rip), %rdi     # 0x8a798
leaq -0x1c(%rbp), %rsi
callq 0x55580
leaq 0x364a1(%rip), %rdi     # 0x8a7e8
leaq -0x18(%rbp), %rsi
callq 0x55580
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq 0x36409(%rip), %rdi     # 0x8a768
leaq -0x28(%rbp), %rsi
callq 0x20310
movq %rax, %rdi
callq 0x203f0
movq %rax, -0x10(%rbp)
movl 0x36896(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x3688d(%rip)     # 0x8ac10
leaq 0x3655e(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x55a5(%rip), %rsi      # 0x59939
movb $0x0, %al
callq 0x74c0
movl 0x3686f(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36866(%rip)     # 0x8ac10
leaq 0x36537(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x558f(%rip), %rsi      # 0x5994a
movb $0x0, %al
callq 0x74c0
movq -0x30(%rbp), %rdi
addq $0x8, %rdi
callq 0x8f60
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movl 0x3682e(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36825(%rip)     # 0x8ac10
leaq 0x364f6(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x54d7(%rip), %rsi      # 0x598d6
movb $0x0, %al
callq 0x74c0
movl 0x36804(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x367fb(%rip)     # 0x8ac10
leaq 0x364cc(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x552c(%rip), %rsi      # 0x59952
movb $0x0, %al
callq 0x74c0
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0x8f60
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movl 0x367c3(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x367ba(%rip)     # 0x8ac10
leaq 0x3648b(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5406(%rip), %rsi      # 0x5986d
movb $0x0, %al
callq 0x74c0
movl 0x3679c(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36793(%rip)     # 0x8ac10
leaq 0x36464(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x53e4(%rip), %rsi      # 0x59875
movb $0x0, %al
callq 0x74c0
movl 0x36772(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36769(%rip)     # 0x8ac10
leaq 0x3643a(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x54ae(%rip), %rsi      # 0x59966
movb $0x0, %al
callq 0x74c0
movq -0x30(%rbp), %rdi
addq $0x20, %rdi
callq 0x8f60
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movl 0x36731(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36728(%rip)     # 0x8ac10
leaq 0x363f9(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x1c(%rbp), %edx
leaq 0x53da(%rip), %rsi      # 0x598d6
movb $0x0, %al
callq 0x74c0
movl 0x36707(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x366fe(%rip)     # 0x8ac10
leaq 0x363cf(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5450(%rip), %rsi      # 0x59973
movb $0x0, %al
callq 0x74c0
movq -0x30(%rbp), %rdi
addq $0x18, %rdi
callq 0x8f60
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movl 0x366c6(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x366bd(%rip)     # 0x8ac10
leaq 0x3638e(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5273(%rip), %rsi      # 0x597d7
movb $0x0, %al
callq 0x74c0
movl 0x3669f(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36696(%rip)     # 0x8ac10
leaq 0x36367(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x52e7(%rip), %rsi      # 0x59875
movb $0x0, %al
callq 0x74c0
movl 0x36675(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x3666c(%rip)     # 0x8ac10
leaq 0x3633d(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x531e(%rip), %rsi      # 0x598d6
movb $0x0, %al
callq 0x74c0
leaq 0x361d2(%rip), %rdi     # 0x8a798
callq 0x555b0
leaq 0x36216(%rip), %rdi     # 0x8a7e8
callq 0x555b0
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)