// File: /workspace/github_c_makefile_star2_O2/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, %ebx
movl %ecx, -0x2c(%rbp)
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %r15
movq $0x0, -0x38(%rbp)
xorl %eax, %eax
callq 0x5f58
movq %r15, %rdi
movl %eax, %esi
callq 0x675c
movq %rax, %r15
leaq 0xf03f(%rip), %rax      # 0x19db8
movl (%rax), %r12d
testl %r12d, %r12d
jne 0xada0
movq %r15, %rdi
callq 0x7afb
movq (%r15), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x38(%rbp)
movl (%rcx), %eax
cmpq $0xa, %rax
jne 0xaf01
movq %r15, %rdi
callq 0x6d9f
xorl %edi, %edi
callq 0x6109
testl %r12d, %r12d
jne 0xaee4
testq %r13, %r13
sete %r15b
testl %ebx, %ebx
setle %r12b
leaq -0x60(%rbp), %rbx
movq %rbx, %rdi
callq 0x9143
xorl %edx, %edx
cmpl $0x0, -0x2c(%rbp)
setg %dl
pushq $0x1
popq %rcx
movq -0x38(%rbp), %rdi
movq %rbx, %rsi
callq 0xaa72
orb %r15b, %r12b
jne 0xae03
movq 0x9203(%rip), %rax      # 0x13ff8
movq (%rax), %rsi
leaq -0x60(%rbp), %rdi
callq 0x9422
jmp 0xae08
testq %r13, %r13
je 0xae1b
movq 0x91e9(%rip), %rax      # 0x13ff8
movq (%rax), %rsi
leaq -0x60(%rbp), %rdi
callq 0x942f
movq -0x38(%rbp), %rax
leaq 0x40(%rax), %r12
movl -0x2c(%rbp), %r13d
xorl $0x1, %r13d
pushq $0x1
popq %rbx
movq %r12, %r15
movq (%r15), %r15
leaq 0xef7d(%rip), %rax      # 0x19db8
movl (%rax), %eax
testq %r15, %r15
je 0xae9f
orl %r13d, %eax
jne 0xae99
leaq 0x3c46(%rip), %rdi      # 0xea94
pushq $0x16
popq %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x31c0
movq 0x50(%r15), %rdx
testq %rdx, %rdx
je 0xae78
movq %r14, %rdi
leaq 0x3c45(%rip), %rsi      # 0xeab4
xorl %eax, %eax
callq 0x3130
jmp 0xae8d
leaq 0x3c2c(%rip), %rdi      # 0xeaab
pushq $0x8
popq %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x31c0
leaq 0x20(%r15), %rdi
movq %r14, %rsi
callq 0xb5a5
addq $0x48, %r15
jmp 0xae31
movl -0x2c(%rbp), %ecx
xorl $0x2, %ecx
orl %eax, %ecx
jne 0xaec9
leaq -0x60(%rbp), %rsi
movq -0x38(%rbp), %rdi
movq %r14, %rdx
callq 0xc41a
jmp 0xaec9
leaq 0x20(%r12), %rdi
callq 0xb583
addq $0x48, %r12
movq (%r12), %r12
testq %r12, %r12
jne 0xaebb
movq -0x38(%rbp), %rdi
callq 0x79c0
leaq -0x60(%rbp), %rdi
callq 0x93fb
leaq 0xadad(%rip), %rdi      # 0x15c98
callq 0x338a
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x90f0(%rip), %rcx      # 0x13ff8
movq (%rcx), %rdi
leaq 0x979e(%rip), %rcx      # 0x146b0
movq (%rcx,%rax,8), %rdx
leaq 0x3b49(%rip), %rsi      # 0xea66
xorl %eax, %eax
callq 0x3130
callq 0x3050
nopl (%rax)