// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq 0x8(%rsi), %r13
testq %r13, %r13
je 0x55aa
leaq 0xd89(%rip), %rsi       # 0x61bb
movq %r13, %rdi
callq 0x21c0
testq %rax, %rax
je 0x55bf
movq %rax, %r14
pushq $0x40
popq %rdi
callq 0x2170
movq %rax, %rbx
movq %rax, %rdi
movq %r14, %rsi
callq 0x36d0
pushq $0x60
popq %rdi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
callq 0x47a8
pushq $0x70
popq %rdi
callq 0x2170
movq %rax, %r15
movq %rax, %rdi
movq %r14, %rsi
callq 0x23dc
pushq $0x40
popq %rdi
callq 0x2170
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x3f1c
movq %r12, %rdi
callq 0x400a
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %r13, %rsi
callq 0x2ca6
leaq 0xe4f(%rip), %rsi       # 0x6311
leaq 0x8(%rsp), %rdi
pushq $-0x1
popq %rdx
callq 0x2150
cmpq $-0x1, %rax
je 0x5503
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x2190
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %r13
movq %r13, %rsi
callq 0x21d0
movq %r13, %rdi
callq 0x20c0
leaq 0xe09(%rip), %rsi       # 0x6313
leaq 0x8(%rsp), %rdi
callq 0x22b0
movq 0x8(%rsp), %rdi
leaq 0xdf9(%rip), %rsi       # 0x6319
callq 0x21c0
movq %rax, %r13
movq %r15, %rdi
movq %rax, %rsi
callq 0x2b42
movq %r13, %rdi
callq 0x2160
movq %rbx, %rdi
callq 0x3bf0
pushq $0x40
popq %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2180
movq %r14, %rdi
callq 0x5698
pushq $0x60
popq %rsi
movq %r14, %rdi
callq 0x2180
movq %r15, %rdi
callq 0x56b2
pushq $0x70
popq %rsi
movq %r15, %rdi
callq 0x2180
movq %r12, %rdi
addq $0x20, %rdi
callq 0x20c0
movq %r12, %rdi
movq %r13, %rsi
callq 0x2180
leaq 0x8(%rsp), %rdi
callq 0x20c0
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x4a2f(%rip), %rax      # 0x9fe0
movq (%rax), %rcx
leaq 0xd12(%rip), %rdi       # 0x62cd
pushq $0x1d
jmp 0x55d2
movq 0x4a1a(%rip), %rax      # 0x9fe0
movq (%rax), %rcx
leaq 0xd1b(%rip), %rdi       # 0x62eb
pushq $0x13
popq %rsi
pushq $0x1
popq %rdx
callq 0x22c0
jmp 0x5599
jmp 0x5682
movq %rax, %rbp
jmp 0x568f
movq %rax, %rbp
cmpl $0x1, %edx
jne 0x568f
movq %rbp, %rdi
callq 0x21e0
leaq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x2200
movq %rbp, %rdi
callq 0x20a0
movq 0x49c6(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl 0x3c(%rbx), %edx
leaq 0x8(%rsp), %rbp
movq (%rbp), %rcx
leaq 0xccf(%rip), %rsi       # 0x62ff
xorl %eax, %eax
callq 0x2210
movq %rbp, %rdi
callq 0x20c0
callq 0x2270
jmp 0x54a9
movq %rax, %rdi
callq 0x2d05
movq %rax, %rbp
pushq $0x40
popq %rsi
movq %r12, %rdi
jmp 0x567b
movq %rax, %rbp
pushq $0x70
popq %rsi
movq %r15, %rdi
jmp 0x567b
movq %rax, %rbp
pushq $0x60
popq %rsi
movq %r14, %rdi
jmp 0x567b
movq %rax, %rbp
pushq $0x40
popq %rsi
movq %rbx, %rdi
callq 0x2180
jmp 0x568f
movq %rax, %rbp
leaq 0x8(%rsp), %rdi
callq 0x20c0
movq %rbp, %rdi
callq 0x2290
nop