// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movl %r8d, -0x34(%rbp)
movl %ecx, %r15d
movq %rdx, -0x40(%rbp)
movq %rsi, %r14
movq %rdi, %r12
movq $0x0, -0x30(%rbp)
xorl %eax, %eax
callq 0x6a59
movq %r12, %rdi
movl %eax, %esi
callq 0x72b8
movq %rax, %r12
leaq 0xf06f(%rip), %rbx      # 0x1adb8
movl (%rbx), %r13d
testl %r13d, %r13d
jne 0xbd70
movq %r12, %rdi
callq 0x881e
movq (%r12), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x30(%rbp)
movl (%rcx), %edi
cmpl $0xa, %edi
jne 0xbed2
movq %r12, %rdi
callq 0x7946
xorl %edi, %edi
callq 0x6bea
testl %r13d, %r13d
jne 0xbeb5
cmpq $0x0, -0x40(%rbp)
sete %r13b
cmpl $0x0, -0x34(%rbp)
setle %r12b
leaq -0x68(%rbp), %rdi
callq 0x9f31
xorl %edx, %edx
testl %r15d, %r15d
setg %dl
movq -0x30(%rbp), %rdi
leaq -0x68(%rbp), %rsi
movl $0x1, %ecx
callq 0xb9e5
orb %r13b, %r12b
jne 0xbdd4
movq 0x9230(%rip), %rax      # 0x14ff8
movq (%rax), %rsi
leaq -0x68(%rbp), %rdi
callq 0xa1fa
cmpq $0x0, -0x40(%rbp)
je 0xbdee
movq 0x9216(%rip), %rax      # 0x14ff8
movq (%rax), %rsi
leaq -0x68(%rbp), %rdi
callq 0x37c4
movq -0x30(%rbp), %rax
movq 0x40(%rax), %r13
testq %r13, %r13
je 0xbe6c
leaq 0x3c92(%rip), %r12      # 0xfa94
cmpl $0x1, %r15d
jne 0xbe63
cmpl $0x0, (%rbx)
jne 0xbe63
movl $0x16, %esi
movl $0x1, %edx
movq %r12, %rdi
movq %r14, %rcx
callq 0x31d0
movq 0x50(%r13), %rdx
testq %rdx, %rdx
je 0xbe3e
movq %r14, %rdi
leaq 0x3c7f(%rip), %rsi      # 0xfab4
xorl %eax, %eax
callq 0x3140
jmp 0xbe57
movl $0x8, %esi
movl $0x1, %edx
leaq 0x3c5c(%rip), %rdi      # 0xfaab
movq %r14, %rcx
callq 0x31d0
leaq 0x20(%r13), %rdi
movq %r14, %rsi
callq 0xc5ac
movq 0x48(%r13), %r13
testq %r13, %r13
jne 0xbe02
cmpl $0x2, %r15d
jne 0xbe87
cmpl $0x0, (%rbx)
jne 0xbe87
leaq -0x68(%rbp), %rsi
movq -0x30(%rbp), %rdi
movq %r14, %rdx
callq 0xd456
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rbx
testq %rbx, %rbx
je 0xbea3
leaq 0x20(%rbx), %rdi
callq 0xc577
movq 0x48(%rbx), %rbx
jmp 0xbe8f
movq -0x30(%rbp), %rdi
callq 0x86cc
leaq -0x68(%rbp), %rdi
callq 0xa1d0
leaq 0xaddc(%rip), %rdi      # 0x16c98
callq 0x3ed7
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3968
nop