// File: /workspace/github_cpp_makefile_star2_O2/baziotis[P]minijava-cpp/ast.cpp
// Function: expr_print(Expression*)
void expr_print(Expression *e) {
    LOG_SCOPE;
    if (!e) return;
    switch (e->kind) {
    case EXPR::PLUS:
    case EXPR::MINUS:
    case EXPR::TIMES:
    case EXPR::CMP:
    case EXPR::AND:
    case EXPR::ARR_LOOK:
    {
        BinaryExpression *be = (BinaryExpression*) e;
        debug_print("(");
        printf("%s\n", expr_name(be->kind));
        expr_print(be->e1);
        expr_print(be->e2);
        debug_line(")");
    } break;
    case EXPR::THIS:
    {
        debug_line("(ThisExpression)");
    } break;
    case EXPR::INT_LIT:
    case EXPR::BOOL_LIT:
    {
        debug_print("(");
        printf("%s %d)\n", expr_name(e->kind), e->lit_val);
    } break;
    case EXPR::MSG_SEND:
    {
        BinaryExpression *be = (BinaryExpression*) e;
        debug_print("(MessageSend\n");
        expr_print(be->e1);
        // For some reason, debug_line does not work here
        debug_print("- Id: %s\n", be->msd->id);
        debug_print("- Expression list:\n");
        for (Expression* e2 : be->msd->expr_list) {
            expr_print(e2);
        }
        debug_print(")\n");
    } break;
    case EXPR::ID:
    {
        debug_print("(");
        printf("%s %s)\n", expr_name(e->kind), e->id);
    } break;
    case EXPR::UNDEFINED:
    {
        debug_print("(");
        printf("Undefined ");
        red_on();
        printf("(Error)");
        red_off();
        printf(")\n");
    } break;
    case EXPR::ARR_LEN:
    case EXPR::ARR_ALLOC:
    case EXPR::NOT:
    {
        debug_print("(%s\n", expr_name(e->kind));
        expr_print(e->e1);
        debug_line(")");
    } break;
    default: printf("Expression print error: %s\n", expr_name(e->kind)); assert(0);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xf(%rsp), %rdi
callq 0x3108
testq %rbx, %rbx
je 0x2707
movl 0x4(%rbx), %edi
cmpq $0xe, %rdi
ja 0x271b
leaq 0xbaf2(%rip), %rax      # 0xe04c
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq 0xdfe8(%rip), %rdi      # 0x10552
xorl %eax, %eax
callq 0x317b
movl 0x4(%rbx), %edi
callq 0x2438
movq %rax, %rdi
callq 0x2190
movq 0x10(%rbx), %rdi
callq 0x2527
movq 0x18(%rbx), %rdi
callq 0x2527
leaq 0xe281(%rip), %rdi      # 0x1081b
xorl %eax, %eax
callq 0x3228
jmp 0x2707
callq 0x2438
leaq 0xbcc2(%rip), %rdi      # 0xe274
movq %rax, %rsi
xorl %eax, %eax
callq 0x317b
movq 0x10(%rbx), %rdi
callq 0x2527
leaq 0xe24f(%rip), %rdi      # 0x1081b
jmp 0x266c
leaq 0xdf7a(%rip), %rdi      # 0x10552
xorl %eax, %eax
callq 0x317b
movl 0x4(%rbx), %edi
callq 0x2438
movl 0x10(%rbx), %edx
leaq 0xbc3c(%rip), %rdi      # 0xe22d
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
jmp 0x2707
leaq 0xbc2e(%rip), %rdi      # 0xe235
xorl %eax, %eax
callq 0x317b
movq 0x10(%rbx), %rdi
callq 0x2527
movq 0x18(%rbx), %rax
movq (%rax), %rsi
leaq 0xbc1e(%rip), %rdi      # 0xe243
xorl %eax, %eax
callq 0x317b
leaq 0xbc1a(%rip), %rdi      # 0xe24d
xorl %eax, %eax
callq 0x317b
movq 0x18(%rbx), %rax
movq 0x10(%rax), %rbx
movq 0x18(%rax), %r14
shlq $0x3, %rbx
xorl %r15d, %r15d
cmpq %r15, %rbx
je 0x26f9
movq (%r14,%r15), %rdi
callq 0x2527
addq $0x8, %r15
jmp 0x264d
leaq 0xbbb0(%rip), %rdi      # 0xe21c
xorl %eax, %eax
callq 0x3228
jmp 0x2707
leaq 0xded3(%rip), %rdi      # 0x10552
xorl %eax, %eax
callq 0x317b
movl 0x4(%rbx), %edi
callq 0x2438
movq 0x10(%rbx), %rdx
leaq 0xbbc8(%rip), %rdi      # 0xe261
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
jmp 0x2707
leaq 0xdea6(%rip), %rdi      # 0x10552
xorl %eax, %eax
callq 0x317b
leaq 0xbbaf(%rip), %rdi      # 0xe269
xorl %eax, %eax
callq 0x2030
leaq 0xbe37(%rip), %rdi      # 0xe4ff
xorl %eax, %eax
callq 0x2030
leaq 0xbcbb(%rip), %rdi      # 0xe391
xorl %eax, %eax
callq 0x2030
leaq 0xbe21(%rip), %rdi      # 0xe505
xorl %eax, %eax
callq 0x2030
leaq 0xe129(%rip), %rdi      # 0x1081b
callq 0x2190
jmp 0x2707
leaq 0xe9b4(%rip), %rdi      # 0x110b4
xorl %eax, %eax
callq 0x317b
leaq 0xf(%rsp), %rdi
callq 0x311c
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
callq 0x2438
leaq 0xbb52(%rip), %rdi      # 0xe279
movq %rax, %rsi
xorl %eax, %eax
callq 0x2030
leaq 0xdeda(%rip), %rdi      # 0x10612
leaq 0xbb56(%rip), %rsi      # 0xe295
leaq 0xbb57(%rip), %rcx      # 0xe29d
pushq $0x64
popq %rdx
callq 0x20b0
jmp 0x2754
jmp 0x2754
jmp 0x2754
movq %rax, %rbx
leaq 0xf(%rsp), %rdi
callq 0x311c
movq %rbx, %rdi
callq 0x21c0
nop