// File: Eronana[P]strawberry/src/ast_codegen.cpp
// Function: AST_CaseClause::codeGen(Symbol*)
DEF_AST_METHOD(CaseClause,AST_CODEGEN)
{
    int nextCaluse=nextLabel();
    if(expr)
    {
        PRINTF("dup\n");
        CODEGEN(expr);
        PRINTF("eq\n");
        PRINTF("istrue\n");
        PRINTF("jmp label_%d\n",nextCaluse);
        PRINTF("label_%d:\n",nextLabel());
        CODEGEN(stmtList);
    }
    else
    {
        int defaultLabel=nextLabel();
        int lastLabel=breakStack.top();
        defaultClauseStack.top()=defaultLabel;
        if(lastLabel+1==nextCaluse)PRINTF("jmp label_%d\n",nextCaluse);
        PRINTF("; default clause\n");
        PRINTF("label_%d:\n",defaultLabel);
        CODEGEN(stmtList);
    }
    PRINTF("jmp label_%d\n",nextCaluse+3);
    PRINTF("label_%d:\n",nextCaluse);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
callq 0x1a000
movq -0x28(%rbp), %rdi
movl %eax, -0x14(%rbp)
addq $0x8, %rdi
callq 0x1d8d0
testb $0x1, %al
jne 0x54a36
jmp 0x54b44
movl 0x361d4(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x361cb(%rip)     # 0x8ac10
leaq 0x35e9c(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x4d90(%rip), %rsi      # 0x597e6
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 0x36193(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x3618a(%rip)     # 0x8ac10
leaq 0x35e5b(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x4e3b(%rip), %rsi      # 0x598d2
movb $0x0, %al
callq 0x74c0
movl 0x3616c(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36163(%rip)     # 0x8ac10
leaq 0x35e34(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x4daf(%rip), %rsi      # 0x5986d
movb $0x0, %al
callq 0x74c0
movl 0x36145(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x3613c(%rip)     # 0x8ac10
leaq 0x35e0d(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x4d8d(%rip), %rsi      # 0x59875
movb $0x0, %al
callq 0x74c0
movl 0x3611b(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36112(%rip)     # 0x8ac10
leaq 0x35de3(%rip), %rax     # 0x8a8e8
movq (%rax), %rax
movq %rax, -0x30(%rbp)
callq 0x1a000
movq -0x30(%rbp), %rdi
movl %eax, %edx
leaq 0x4db8(%rip), %rsi      # 0x598d6
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)
jmp 0x54c14
callq 0x1a000
movl %eax, -0x18(%rbp)
leaq 0x35c95(%rip), %rdi     # 0x8a7e8
callq 0x555d0
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x34(%rbp)
leaq 0x35cce(%rip), %rdi     # 0x8a838
callq 0x555d0
movl -0x34(%rbp), %ecx
movl %ecx, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
cmpl -0x14(%rbp), %eax
jne 0x54ba9
movl 0x3608b(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36082(%rip)     # 0x8ac10
leaq 0x35d53(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x4cd3(%rip), %rsi      # 0x59875
movb $0x0, %al
callq 0x74c0
movl 0x36061(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36058(%rip)     # 0x8ac10
leaq 0x35d29(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
leaq 0x4de0(%rip), %rsi      # 0x599a9
movb $0x0, %al
callq 0x74c0
movl 0x3603a(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x36031(%rip)     # 0x8ac10
leaq 0x35d02(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x18(%rbp), %edx
leaq 0x4ce3(%rip), %rsi      # 0x598d6
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 0x35ff6(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x35fed(%rip)     # 0x8ac10
leaq 0x35cbe(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
addl $0x3, %edx
leaq 0x4c3b(%rip), %rsi      # 0x59875
movb $0x0, %al
callq 0x74c0
movl 0x35fc9(%rip), %eax     # 0x8ac10
addl $0x1, %eax
movl %eax, 0x35fc0(%rip)     # 0x8ac10
leaq 0x35c91(%rip), %rax     # 0x8a8e8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x4c72(%rip), %rsi      # 0x598d6
movb $0x0, %al
callq 0x74c0
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)