// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movb $0x0, %al
callq 0x76d0
movl %eax, -0x24(%rbp)
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x8360
movq %rax, -0x30(%rbp)
leaq 0x102c9(%rip), %rax     # 0x1fdd8
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq $0x0, -0x40(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0xfb75
movq -0x30(%rbp), %rdi
callq 0xa410
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq 0x20(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpl $0xa, (%rax)
je 0xfb73
movq 0xa4ae(%rip), %rax      # 0x19ff8
movq (%rax), %rdi
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, %ecx
leaq 0xab74(%rip), %rax      # 0x1a6d0
movq (%rax,%rcx,8), %rdx
leaq 0x5f3f(%rip), %rsi      # 0x15aa6
movb $0x0, %al
callq 0x3120
callq 0x3040
jmp 0xfb75
movq -0x30(%rbp), %rdi
callq 0x8c80
xorl %edi, %edi
callq 0x7990
movb $0x0, -0x69(%rbp)
movb $0x0, -0x6a(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xfb98
movb $0x1, -0x6a(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0xfba9
cmpq $0x0, -0x18(%rbp)
je 0xfba9
movb $0x1, -0x69(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0xfd02
leaq -0x68(%rbp), %rdi
callq 0xc960
movq -0x40(%rbp), %rdi
cmpl $0x1, -0x1c(%rbp)
setge %al
movzbl %al, %edx
andl $0x1, %edx
leaq -0x68(%rbp), %rsi
movl $0x1, %ecx
callq 0xf6c0
testb $0x1, -0x69(%rbp)
je 0xfbf4
movq 0xa410(%rip), %rax      # 0x19ff8
movq (%rax), %rsi
leaq -0x68(%rbp), %rdi
callq 0xce60
testb $0x1, -0x6a(%rbp)
je 0xfc0d
movq 0xa3f7(%rip), %rax      # 0x19ff8
movq (%rax), %rsi
leaq -0x68(%rbp), %rdi
callq 0xce90
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0xfc9f
leaq 0x101b1(%rip), %rax     # 0x1fdd8
cmpl $0x0, (%rax)
jne 0xfc8e
cmpl $0x1, -0x1c(%rbp)
jne 0xfc8e
movq -0x10(%rbp), %rdi
leaq 0x5e97(%rip), %rsi      # 0x15ad4
movb $0x0, %al
callq 0x3120
movq -0x78(%rbp), %rax
cmpq $0x0, 0x50(%rax)
jne 0xfc63
movq -0x10(%rbp), %rdi
leaq 0x5e91(%rip), %rsi      # 0x15aeb
movb $0x0, %al
callq 0x3120
jmp 0xfc7d
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rax
movq 0x50(%rax), %rdx
leaq 0x5e7e(%rip), %rsi      # 0x15af4
movb $0x0, %al
callq 0x3120
movq -0x78(%rbp), %rdi
addq $0x20, %rdi
movq -0x10(%rbp), %rsi
callq 0x108c0
movq -0x78(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0xfc19
leaq 0x10132(%rip), %rax     # 0x1fdd8
cmpl $0x0, (%rax)
jne 0xfcc2
cmpl $0x2, -0x1c(%rbp)
jne 0xfcc2
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq -0x68(%rbp), %rsi
callq 0x11fc0
movq -0x40(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
je 0xfcf0
movq -0x78(%rbp), %rdi
addq $0x20, %rdi
callq 0x10880
movq -0x78(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x78(%rbp)
jmp 0xfcce
movq -0x40(%rbp), %rdi
callq 0xa0b0
leaq -0x68(%rbp), %rdi
callq 0xcdf0
leaq 0xbfaf(%rip), %rdi      # 0x1bcb8
callq 0x33f0
xorl %eax, %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)