// File: Eronana[P]strawberry/src/ast_codegen.cpp
// Function: AST_IfStatement::codeGen(Symbol*)
DEF_AST_METHOD(IfStatement,AST_CODEGEN)
{
    PRINTF("; if statement\n");
    CODEGEN(expr);
    PRINTF("istrue\n");
    int jmpLabel=nextLabel();
    int elseLabel;
    if(elseStatement)elseLabel=nextLabel();
    else elseLabel=jmpLabel;
    PRINTF("jmp label_%d\n",elseLabel);
    PRINTF("; true branch\n");
    CODEGEN(statement);
    if(elseStatement)
    {
        PRINTF("jmp label_%d\n",jmpLabel);
        PRINTF("label_%d:\n",elseLabel);
        PRINTF("; else branch\n");
        CODEGEN(elseStatement);
    }
    PRINTF("label_%d:\n",jmpLabel);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x20(%rbp)
movl 0x36b72(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36b69(%rip)     # 0x8ac10
leaq 0x3683a(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5862(%rip), %rsi      # 0x5991a
movb $0x0, %al
callq 0x74c0
movq -0x20(%rbp), %rdi
addq $0x8, %rdi
callq 0x8f60
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movl 0x36b31(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36b28(%rip)     # 0x8ac10
leaq 0x367f9(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5774(%rip), %rsi      # 0x5986d
movb $0x0, %al
callq 0x74c0
callq 0x1a000
movq -0x20(%rbp), %rdi
movl %eax, -0x14(%rbp)
addq $0x18, %rdi
callq 0x1d8d0
testb $0x1, %al
jne 0x5411b
jmp 0x54125
callq 0x1a000
movl %eax, -0x18(%rbp)
jmp 0x5412b
movl -0x14(%rbp), %eax
movl %eax, -0x18(%rbp)
movl 0x36adf(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36ad6(%rip)     # 0x8ac10
leaq 0x367a7(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x5727(%rip), %rsi      # 0x59875
movb $0x0, %al
callq 0x74c0
movl 0x36ab5(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36aac(%rip)     # 0x8ac10
leaq 0x3677d(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x5786(%rip), %rsi      # 0x598fb
movb $0x0, %al
callq 0x74c0
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
callq 0x8f60
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
callq 0x1d8d0
testb $0x1, %al
jne 0x541ac
jmp 0x54241
movl 0x36a5e(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36a55(%rip)     # 0x8ac10
leaq 0x36726(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x56a6(%rip), %rsi      # 0x59875
movb $0x0, %al
callq 0x74c0
movl 0x36a34(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36a2b(%rip)     # 0x8ac10
leaq 0x366fc(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x56dd(%rip), %rsi      # 0x598d6
movb $0x0, %al
callq 0x74c0
movl 0x36a0a(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36a01(%rip)     # 0x8ac10
leaq 0x366d2(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x570a(%rip), %rsi      # 0x5992a
movb $0x0, %al
callq 0x74c0
movq -0x20(%rbp), %rdi
addq $0x18, %rdi
callq 0x8f60
movq %rax, %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
callq *0x18(%rax)
movl 0x369c9(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x369c0(%rip)     # 0x8ac10
leaq 0x36691(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x5672(%rip), %rsi      # 0x598d6
movb $0x0, %al
callq 0x74c0
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)