// File: /workspace/github_c_makefile_star2_O3/sharmaeklavya2[P]cerplag/compiler.c
// Function: compiler_main
int compiler_main(FILE* ifp, FILE* ofp, FILE* sdfp, int level, int verbosity) {
    /*  level=0: semantic check only
        level=1: allow_codegen
        level=2: x86_code_gen
    */
    gsymb_t start_symb = init_parser();

    parse_tree_node* proot = build_parse_tree(ifp, start_symb);
    int parse_errors = error_count;
    ProgramNode* ast = NULL;
    SD mySD;

    if(parse_errors == 0) {
        build_ast(proot);
        ast = (ProgramNode*)proot->value->tree;
        if(ast->base.node_type != ASTN_Program) {
            fprintf(stderr, "Root node of AST is %s instead of ProgramNode", ASTN_STRS[ast->base.node_type]);
            abort();
        }
    }
    parse_tree_destroy(proot);
    destroy_parser(false);

    bool print_sd = false;
    bool print_entry_list = false;
    if(sdfp != NULL) {
        print_entry_list = true;
    }
    if(verbosity > 0 && sdfp != NULL) {
        print_sd = true;
    }
    if(parse_errors == 0) {
        SD_init(&mySD);
        compile_program(ast, &mySD, level>=1, true);
        if(print_sd) {
            SD_print(&mySD, stderr);
        }
        if(print_entry_list) {
            SD_print_sub(&mySD, stderr);
        }
        ModuleNode* node = ast->modules;
        while(node != NULL) {
            if(error_count == 0 && level == 1) {
                fprintf(ofp, "Intermediate code for ");
                if(node->name == NULL) {
                    fprintf(ofp, "driver:\n");
                }
                else {
                    fprintf(ofp, "module %s:\n", node->name);
                }
                ircode_print(&(node->base.ircode), ofp);
            }
            node = node->next;
        }

        if(error_count == 0 && level == 2) {
            compile_program_to_x86(ast, &mySD, ofp);
        }
        node = ast->modules;
        while(node != NULL) {
            ircode_clear(&(node->base.ircode));
            node = node->next;
        }
        destroy_ast((pAstNode)ast);
        SD_clear(&mySD);
    }

    pch_int_hmap_clear(&intern_table);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %r13d
movl %ecx, -0x2c(%rbp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq $0x0, -0x38(%rbp)
xorl %eax, %eax
callq 0x6a60
movq %r15, %rdi
movl %eax, %esi
callq 0x72c7
movq %rax, %r15
leaq 0xf131(%rip), %rax      # 0x1adb8
movl (%rax), %r12d
testl %r12d, %r12d
jne 0xbcad
movq %r15, %rdi
callq 0x871a
movq (%r15), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x38(%rbp)
movl (%rcx), %edi
cmpl $0xa, %edi
jne 0xbe1d
movq %r15, %rdi
callq 0x7951
xorl %edi, %edi
callq 0x6be6
testl %r12d, %r12d
jne 0xbe00
testq %rbx, %rbx
sete %r12b
testl %r13d, %r13d
setle %r13b
leaq -0x60(%rbp), %r15
movq %r15, %rdi
callq 0x9e2d
xorl %edx, %edx
cmpl $0x0, -0x2c(%rbp)
setg %dl
movq -0x38(%rbp), %rdi
movq %r15, %rsi
movl $0x1, %ecx
callq 0xb91c
orb %r12b, %r13b
jne 0xbd13
movq 0x92f3(%rip), %rax      # 0x14ff8
movq (%rax), %rsi
leaq -0x60(%rbp), %rdi
callq 0xa10f
jmp 0xbd18
testq %rbx, %rbx
je 0xbd2b
movq 0x92d9(%rip), %rax      # 0x14ff8
movq (%rax), %rsi
leaq -0x60(%rbp), %rdi
callq 0x37c3
movq -0x38(%rbp), %rax
movq 0x40(%rax), %r15
leaq 0xf07e(%rip), %rbx      # 0x1adb8
movl (%rbx), %eax
testq %r15, %r15
je 0xbdb8
movl -0x2c(%rbp), %r13d
xorl $0x1, %r13d
leaq 0x3d44(%rip), %r12      # 0xfa94
movl %r13d, %ecx
orl %eax, %ecx
jne 0xbdaf
movl $0x16, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x31d0
movq 0x50(%r15), %rdx
testq %rdx, %rdx
je 0xbd88
movq %r14, %rdi
leaq 0x3d35(%rip), %rsi      # 0xfab4
xorl %eax, %eax
callq 0x3140
jmp 0xbda1
movl $0x8, %esi
movl $0x1, %edx
leaq 0x3d12(%rip), %rdi      # 0xfaab
movq %r14, %rcx
callq 0x31d0
leaq 0x20(%r15), %rdi
movq %r14, %rsi
callq 0xc510
movl (%rbx), %eax
movq 0x48(%r15), %r15
testq %r15, %r15
jne 0xbd50
movl -0x2c(%rbp), %ecx
xorl $0x2, %ecx
orl %eax, %ecx
jne 0xbdd2
leaq -0x60(%rbp), %rsi
movq -0x38(%rbp), %rdi
movq %r14, %rdx
callq 0xd3ce
movq -0x38(%rbp), %rax
movq 0x40(%rax), %rbx
testq %rbx, %rbx
je 0xbdee
leaq 0x20(%rbx), %rdi
callq 0xc4eb
movq 0x48(%rbx), %rbx
jmp 0xbdda
movq -0x38(%rbp), %rdi
callq 0x85c7
leaq -0x60(%rbp), %rdi
callq 0xa0e5
leaq 0xae91(%rip), %rdi      # 0x16c98
callq 0x3ed7
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3967
nop