// File: /workspace/github_cpp_makefile_star2_O1/johan-bjareholt[P]lua-compiler/src/main.cc
// Function: main
int main(int argc, char** argv){
	parse_flags(argc, argv);
	
    // Grammar
    yy::parser parser;
	parser.parse();
    if (debug_grammar){
        std::stringstream ss;
        root->dump(ss);
        std::cout << ss.str();
    }

    // IR
	BBlock* start = new BBlock();
	BBlock* current = start;
	convertStatement(root, &current);
    if (debug_cfg){
        std::stringstream ss;
	    dumpCFG(ss, start);
        for (auto block : funcdefs){
            ss << "Function " << block.first << std::endl;
            dumpCFG(ss, block.second);
        }
        std::cout << ss.str();
    }
   
    // CFG dot graph
    std::ofstream outDotFile("graph.dot");
    std::list<BBlock*> outdotblocks;
    outdotblocks.push_back(start);
    for (auto block : funcdefs){
        outdotblocks.push_back(block.second);
    }
    dumpDot(outDotFile, outdotblocks);
    outDotFile.close();
	
    // Target output
    if (output_mode == OUTPUT_FILE){
        std::ofstream outFile(output_filename);
        outMainBlock(outFile, *start);
        outFile.close();
    }
    else if (output_mode == OUTPUT_STDOUT){
        std::stringstream ss;
        outMainBlock(ss, *start);
        std::cout << ss.str();
    }
	
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x488, %rsp            # imm = 0x488
callq 0x4a74
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0xd654
movq %rbx, %rdi
callq 0xd9d8
cmpb $0x1, 0x1ae4d(%rip)     # 0x1f2d9
jne 0x4517
leaq -0x4a8(%rbp), %rdi
callq 0x31a0
leaq 0x1afb3(%rip), %rax     # 0x1f458
movq (%rax), %rdi
leaq -0x498(%rbp), %rsi
xorl %edx, %edx
callq 0x5bbc
leaq -0x490(%rbp), %rsi
leaq -0x2a8(%rbp), %rdi
callq 0x3400
movq -0x2a8(%rbp), %rsi
movq -0x2a0(%rbp), %rdx
movq 0x1aaf2(%rip), %rdi     # 0x1efd0
callq 0x32b0
leaq -0x298(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x44f8
callq 0x3230
movq 0x1aa99(%rip), %rsi     # 0x1ef98
leaq -0x4a8(%rbp), %rdi
callq 0x31c0
leaq -0x428(%rbp), %rdi
callq 0x30c0
movl $0x48, %edi
callq 0x3260
movq %rax, %rbx
movq %rax, %rdi
callq 0x4e20
leaq -0x88(%rbp), %rsi
movq %rbx, (%rsi)
leaq 0x1af1b(%rip), %rax     # 0x1f458
movq (%rax), %rdi
callq 0x7313
cmpb $0x1, 0x1ad8e(%rip)     # 0x1f2da
movq %rbx, -0x30(%rbp)
jne 0x46aa
leaq -0x4a8(%rbp), %rdi
callq 0x31a0
leaq -0x498(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7ba8
leaq 0x1adb5(%rip), %r12     # 0x1f330
movq 0x18(%r12), %r15
addq $0x8, %r12
cmpq %r12, %r15
je 0x4645
leaq -0x298(%rbp), %r13
movq %r13, -0x2a8(%rbp)
movq 0x20(%r15), %rsi
movq 0x28(%r15), %rdx
addq %rsi, %rdx
leaq -0x2a8(%rbp), %rdi
callq 0x4baa
movq 0x40(%r15), %rax
movq %rax, -0x288(%rbp)
movl $0x9, %edx
movq %r14, %rdi
leaq 0x11a55(%rip), %rsi     # 0x16021
callq 0x32b0
movq -0x2a8(%rbp), %rsi
movq -0x2a0(%rbp), %rdx
movq %r14, %rdi
callq 0x32b0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3240
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3180
movq -0x288(%rbp), %rsi
movq %r14, %rdi
callq 0x7ba8
movq -0x2a8(%rbp), %rdi
cmpq %r13, %rdi
je 0x4631
callq 0x3230
movq %r15, %rdi
callq 0x3190
movq %rax, %r15
cmpq %r12, %rax
jne 0x4594
leaq -0x490(%rbp), %rsi
leaq -0x2a8(%rbp), %rdi
callq 0x3400
movq -0x2a8(%rbp), %rsi
movq -0x2a0(%rbp), %rdx
movq 0x1a963(%rip), %rdi     # 0x1efd0
callq 0x32b0
leaq -0x298(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movq -0x30(%rbp), %rbx
je 0x468b
callq 0x3230
movq 0x1a906(%rip), %rsi     # 0x1ef98
leaq -0x4a8(%rbp), %rdi
callq 0x31c0
leaq -0x428(%rbp), %rdi
callq 0x30c0
leaq 0x1197a(%rip), %rsi     # 0x1602b
leaq -0x4a8(%rbp), %rdi
movl $0x10, %edx
callq 0x3290
leaq -0x48(%rbp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
movq $0x0, 0x10(%rax)
movl $0x18, %edi
callq 0x3260
movq %rbx, 0x10(%rax)
leaq -0x48(%rbp), %rbx
movq %rax, %rdi
movq %rbx, %rsi
callq 0x3060
incq 0x10(%rbx)
leaq 0x1ac33(%rip), %rbx     # 0x1f330
movq 0x18(%rbx), %r14
addq $0x8, %rbx
cmpq %rbx, %r14
je 0x4786
leaq -0x298(%rbp), %r13
leaq -0x2a8(%rbp), %r15
leaq -0x48(%rbp), %r12
movq %r13, -0x2a8(%rbp)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x4baa
movq 0x40(%r14), %rax
movq %rax, -0x288(%rbp)
movl $0x18, %edi
callq 0x3260
movq -0x288(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq %rax, %rdi
movq %r12, %rsi
callq 0x3060
incq -0x38(%rbp)
movq -0x2a8(%rbp), %rdi
cmpq %r13, %rdi
je 0x4776
callq 0x3230
movq %r14, %rdi
callq 0x3190
movq %rax, %r14
cmpq %rbx, %rax
jne 0x471c
leaq -0x60(%rbp), %rdi
leaq -0x48(%rbp), %r14
movq %r14, %rsi
callq 0x4b54
movq -0x30(%rbp), %r12
leaq -0x4a8(%rbp), %rdi
leaq -0x60(%rbp), %r15
movq %r15, %rsi
callq 0x5068
movq -0x60(%rbp), %rdi
cmpq %r15, %rdi
je 0x47c6
movq (%rdi), %rbx
callq 0x3230
movq %rbx, %rdi
cmpq %r15, %rbx
jne 0x47b6
leaq -0x4a8(%rbp), %rdi
callq 0x3370
movl 0x1ab28(%rip), %eax     # 0x1f300
testl %eax, %eax
je 0x484b
cmpl $0x1, %eax
jne 0x48bb
leaq 0x1ab1c(%rip), %rsi     # 0x1f308
leaq -0x2a8(%rbp), %rdi
movl $0x10, %edx
callq 0x34a0
leaq -0x2a8(%rbp), %rdi
movq %r12, %rsi
callq 0x9442
leaq -0x2a8(%rbp), %rdi
callq 0x3370
movq 0x1a799(%rip), %rax     # 0x1efb8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x2a0(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x2a8(%rbp,%rcx)
callq 0x3200
leaq -0x1b0(%rbp), %rdi
jmp 0x48b6
leaq -0x2a8(%rbp), %rdi
callq 0x31a0
leaq -0x298(%rbp), %rdi
movq %r12, %rsi
callq 0x9442
leaq -0x290(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x3400
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq 0x1a74b(%rip), %rdi     # 0x1efd0
callq 0x32b0
leaq -0x70(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x489c
callq 0x3230
movq 0x1a6f5(%rip), %rsi     # 0x1ef98
leaq -0x2a8(%rbp), %rdi
callq 0x31c0
leaq -0x228(%rbp), %rdi
callq 0x30c0
movq -0x48(%rbp), %rdi
cmpq %r14, %rdi
je 0x48d4
movq (%rdi), %rbx
callq 0x3230
movq %rbx, %rdi
cmpq %r14, %rbx
jne 0x48c4
movq 0x1a6dd(%rip), %rax     # 0x1efb8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x4a0(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x4a8(%rbp,%rcx)
callq 0x3200
leaq -0x3b0(%rbp), %rdi
callq 0x30c0
leaq -0xa8(%rbp), %rdi
callq 0xd672
xorl %eax, %eax
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq -0x70(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4946
callq 0x3230
jmp 0x4946
jmp 0x4943
movq %rax, %r14
movq 0x1a64b(%rip), %rsi     # 0x1ef98
leaq -0x2a8(%rbp), %rdi
callq 0x31c0
leaq -0x228(%rbp), %rdi
callq 0x30c0
jmp 0x4a02
jmp 0x49e9
jmp 0x49e9
jmp 0x4976
jmp 0x49e4
jmp 0x49e4
jmp 0x49dd
movq %rax, %r14
leaq -0x298(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x4a3c
jmp 0x4a41
jmp 0x49e4
jmp 0x49e4
jmp 0x49dd
movq %rax, %r14
leaq -0x2a8(%rbp), %rdi
callq 0x33b0
jmp 0x4a02
movq %rax, %r14
movq -0x60(%rbp), %rdi
cmpq %r15, %rdi
je 0x4a02
movq (%rdi), %rbx
callq 0x3230
movq %rbx, %rdi
cmpq %r15, %rbx
jne 0x49b5
jmp 0x4a02
jmp 0x49dd
jmp 0x49dd
movq %rax, %r14
movq %rbx, %rdi
callq 0x3230
jmp 0x4a60
jmp 0x49dd
movq %rax, %r14
jmp 0x4a60
jmp 0x49e9
movq %rax, %r14
jmp 0x4a41
movq %rax, %r14
jmp 0x4a02
movq %rax, %r14
movq -0x2a8(%rbp), %rdi
cmpq %r13, %rdi
je 0x4a02
callq 0x3230
movq -0x48(%rbp), %rdi
leaq -0x48(%rbp), %r15
cmpq %r15, %rdi
je 0x4a1f
movq (%rdi), %rbx
callq 0x3230
movq %rbx, %rdi
cmpq %r15, %rbx
jne 0x4a0f
leaq -0x4a8(%rbp), %rdi
callq 0x33b0
jmp 0x4a60
movq %rax, %r14
movq -0x2a8(%rbp), %rdi
cmpq %r13, %rdi
je 0x4a41
callq 0x3230
movq 0x1a550(%rip), %rsi     # 0x1ef98
leaq -0x4a8(%rbp), %rdi
callq 0x31c0
leaq -0x428(%rbp), %rdi
callq 0x30c0
leaq -0xa8(%rbp), %rdi
callq 0xd672
movq %r14, %rdi
callq 0x3470