// File: /workspace/github_cpp_makefile_star2_O3/protonpopsicle[P]lang/src/compiler/main.cpp
// Function: main
int main(int argc, char *argv[]) {
    if (argv[1] == 0) {
        fprintf(stderr, "missing argument 1: filename\n");
        return(0);
    }
    
    /*
    * Load source file
    */
    char *source = argv[1];
    FILE *fp = fopen(source, "r");
    if (fp == 0) {
        fprintf(stderr, "error opening file\n");
        return(0);
    }
    
    /*
    * Initialize compiler
    */
    Lexer *lexer = new Lexer(fp);
    ZoneMgr *zoneMgr = new ZoneMgr();
    ByteCoder *byteCoder = new ByteCoder(zoneMgr);
    Parser *parser = new Parser(lexer, zoneMgr, byteCoder);
    
    /*
    * Run compiler
    */
    try {
        parser->program();
    }
    catch (Error err) {
        fprintf(stderr, "near line %i: %s\n", lexer->line, err.msg.c_str());
    }
    
    /*
    * Print bytecode
    */
    std::string fname(source);
    size_t pos = fname.find_last_of(".");
    if (pos != -1) {
        fname = fname.substr(0, pos);
    }
    fname += ".lang";
    
    fp = fopen(fname.c_str(), "w");
    byteCoder->write(fp);
    fclose(fp);
    
    /*
    * Cleanup
    */
    delete lexer;
    delete zoneMgr;
    delete byteCoder;
    delete parser;
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq 0x8(%rsi), %rbp
testq %rbp, %rbp
je 0x5f9c
leaq 0x1441(%rip), %rsi      # 0x71bb
movq %rbp, %rdi
callq 0x21b0
testq %rax, %rax
je 0x5fa3
movq %rax, %rbx
movl $0x40, %edi
callq 0x2150
movq %rax, %r13
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3b60
movl $0x60, %edi
callq 0x2150
movq %rax, %r12
movq %rax, %rdi
callq 0x4f84
movl $0x70, %edi
callq 0x2150
movq %rax, %r14
movq %rax, %rdi
movq %r12, %rsi
callq 0x248c
movl $0x40, %edi
callq 0x2150
movq %rax, %r15
movq %rax, %rbx
movq %rax, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x44e0
movq %rbx, %rdi
callq 0x45f8
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
movq %rbp, %rdi
callq 0x20b0
leaq (%rax,%rbp), %rdx
leaq 0x8(%rsp), %rdi
movq %rbp, %rsi
callq 0x339c
leaq 0x1502(%rip), %rsi      # 0x7327
leaq 0x8(%rsp), %rdi
movl $0x1, %ecx
movq $-0x1, %rdx
callq 0x2290
cmpq $-0x1, %rax
je 0x5e82
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x2170
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rbp
movq %rbp, %rsi
callq 0x21c0
movq (%rbp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x5e82
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2160
leaq 0x14a0(%rip), %rsi      # 0x7329
leaq 0x8(%rsp), %rdi
callq 0x2270
movq 0x8(%rsp), %rdi
leaq 0x1490(%rip), %rsi      # 0x732f
callq 0x21b0
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
callq 0x2e42
movq %rbp, %rdi
callq 0x2140
movq %r13, %rdi
callq 0x41b4
movl $0x40, %esi
movq %r13, %rdi
callq 0x2160
leaq 0x20(%r12), %rdi
callq 0x5622
movq %r12, %rdi
addq $0x8, %rdi
callq 0x5552
movl $0x60, %esi
movq %r12, %rdi
callq 0x2160
movq 0x50(%r14), %rdi
testq %rdi, %rdi
je 0x5f07
movq 0x60(%r14), %rsi
subq %rdi, %rsi
callq 0x2160
movq 0x38(%r14), %rdi
testq %rdi, %rdi
je 0x5f1c
movq 0x48(%r14), %rsi
subq %rdi, %rsi
callq 0x2160
movq %r14, %rdi
addq $0x20, %rdi
callq 0x6070
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x5f3d
movq 0x18(%r14), %rsi
subq %rdi, %rsi
callq 0x2160
movl $0x70, %esi
movq %r14, %rdi
callq 0x2160
movq 0x20(%rbx), %rdi
addq $0x30, %r15
cmpq %r15, %rdi
je 0x5f62
movq (%r15), %rsi
incq %rsi
callq 0x2160
movl $0x40, %esi
movq %rbx, %rdi
callq 0x2160
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5f8b
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2160
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x237a
jmp 0x5f8b
callq 0x235e
jmp 0x5f8b
jmp 0x6046
movq %rax, (%rsp)
jmp 0x6066
movq %rax, (%rsp)
cmpl $0x1, %edx
jne 0x6066
movq (%rsp), %rdi
callq 0x21d0
leaq 0x58(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x3306
leaq 0x48(%rsp), %rdx
movq (%rsp), %rdi
movq %r13, %rsi
leaq 0x58(%rsp), %rcx
callq 0x230e
jmp 0x5dfc
movq %rax, %rdi
callq 0x2fb3
movq %rax, (%rsp)
movl $0x40, %esi
movq %rbx, %rdi
jmp 0x6061
movq %rax, (%rsp)
movl $0x70, %esi
movq %r14, %rdi
jmp 0x6061
movq %rax, (%rsp)
movl $0x60, %esi
movq %r12, %rdi
jmp 0x6061
movq %rax, (%rsp)
movl $0x40, %esi
movq %r13, %rdi
jmp 0x6061
movq %rax, (%rsp)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6066
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2160
movq (%rsp), %rdi
callq 0x2250
nop