// File: /workspace/github_cpp_makefile_star2_O1/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 0x5fe0
leaq 0x13fd(%rip), %rsi      # 0x71bb
movq %rbp, %rdi
callq 0x21b0
testq %rax, %rax
je 0x5fe7
movq %rax, %rbx
movl $0x40, %edi
callq 0x2150
movq %rax, %r13
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3b90
movl $0x60, %edi
callq 0x2150
movq %rax, %r12
movq %rax, %rdi
callq 0x4fc0
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 0x4514
movq %rbx, %rdi
callq 0x462c
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 0x33d4
leaq 0x14be(%rip), %rsi      # 0x7327
leaq 0x8(%rsp), %rdi
movl $0x1, %ecx
movq $-0x1, %rdx
callq 0x2290
cmpq $-0x1, %rax
je 0x5ec6
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 0x5ec6
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2160
leaq 0x145c(%rip), %rsi      # 0x7329
leaq 0x8(%rsp), %rdi
callq 0x2270
movq 0x8(%rsp), %rdi
leaq 0x144c(%rip), %rsi      # 0x732f
callq 0x21b0
movq %rax, %rbp
movq %r14, %rdi
movq %rax, %rsi
callq 0x2e48
movq %rbp, %rdi
callq 0x2140
movq %r13, %rdi
callq 0x41e8
movl $0x40, %esi
movq %r13, %rdi
callq 0x2160
leaq 0x20(%r12), %rdi
callq 0x5658
movq %r12, %rdi
addq $0x8, %rdi
callq 0x558e
movl $0x60, %esi
movq %r12, %rdi
callq 0x2160
movq 0x50(%r14), %rdi
testq %rdi, %rdi
je 0x5f4b
movq 0x60(%r14), %rsi
subq %rdi, %rsi
callq 0x2160
movq 0x38(%r14), %rdi
testq %rdi, %rdi
je 0x5f60
movq 0x48(%r14), %rsi
subq %rdi, %rsi
callq 0x2160
movq %r14, %rdi
addq $0x20, %rdi
callq 0x60b4
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x5f81
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 0x5fa6
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 0x5fcf
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 0x5fcf
callq 0x235e
jmp 0x5fcf
jmp 0x608a
movq %rax, (%rsp)
jmp 0x60aa
movq %rax, (%rsp)
cmpl $0x1, %edx
jne 0x60aa
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 0x3344
leaq 0x48(%rsp), %rdx
movq (%rsp), %rdi
movq %r13, %rsi
leaq 0x58(%rsp), %rcx
callq 0x230e
jmp 0x5e40
movq %rax, %rdi
callq 0x2fb9
movq %rax, (%rsp)
movl $0x40, %esi
movq %rbx, %rdi
jmp 0x60a5
movq %rax, (%rsp)
movl $0x70, %esi
movq %r14, %rdi
jmp 0x60a5
movq %rax, (%rsp)
movl $0x60, %esi
movq %r12, %rdi
jmp 0x60a5
movq %rax, (%rsp)
movl $0x40, %esi
movq %r13, %rdi
jmp 0x60a5
movq %rax, (%rsp)
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x60aa
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2160
movq (%rsp), %rdi
callq 0x2250
nop