// File: /workspace/github_cpp_makefile_star2_O2/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 0x45b1
leaq -0xa8(%rbp), %rbx
movq %rbx, %rdi
callq 0xb340
movq %rbx, %rdi
callq 0xb622
cmpb $0x1, 0x180af(%rip)     # 0x1c299
jne 0x424e
leaq -0x4a8(%rbp), %rdi
callq 0x3180
leaq 0x18219(%rip), %rax     # 0x1c418
movq (%rax), %rdi
leaq -0x498(%rbp), %rsi
xorl %edx, %edx
callq 0x5194
leaq -0x490(%rbp), %rsi
leaq -0x2a8(%rbp), %rdi
callq 0x3380
movq 0x17d9e(%rip), %rdi     # 0x1bfc8
leaq -0x2a8(%rbp), %rsi
callq 0x31d0
leaq -0x2a8(%rbp), %rdi
callq 0x3448
leaq -0x4a8(%rbp), %rdi
callq 0x3190
pushq $0x48
popq %rdi
callq 0x3200
movq %rax, %r14
movq %rax, %rdi
callq 0x4904
movq %r14, -0x30(%rbp)
leaq -0x88(%rbp), %rsi
movq %r14, (%rsi)
leaq 0x181a2(%rip), %rax     # 0x1c418
movq (%rax), %rdi
callq 0x6164
cmpb $0x1, 0x18015(%rip)     # 0x1c29a
jne 0x4358
leaq -0x4a8(%rbp), %rdi
callq 0x3180
leaq -0x498(%rbp), %rbx
movq -0x30(%rbp), %rsi
movq %rbx, %rdi
callq 0x67aa
leaq 0x1803f(%rip), %r13     # 0x1c2f0
movq 0x18(%r13), %r15
addq $0x8, %r13
leaq -0x2a8(%rbp), %r14
leaq 0xdd5c(%rip), %r12      # 0x12023
cmpq %r13, %r15
je 0x431a
leaq 0x20(%r15), %rsi
movq %r14, %rdi
callq 0x466e
movq %rbx, %rdi
movq %r12, %rsi
callq 0x31f0
movq %rax, %rdi
movq %r14, %rsi
callq 0x31d0
movq %rax, %rdi
callq 0x3100
movq -0x288(%rbp), %rsi
movq %rbx, %rdi
callq 0x67aa
movq %r14, %rdi
callq 0x3448
movq %r15, %rdi
callq 0x3170
movq %rax, %r15
jmp 0x42c7
leaq -0x490(%rbp), %rsi
leaq -0x2a8(%rbp), %rdi
callq 0x3380
movq 0x17c94(%rip), %rdi     # 0x1bfc8
leaq -0x2a8(%rbp), %rsi
callq 0x31d0
leaq -0x2a8(%rbp), %rdi
callq 0x3448
leaq -0x4a8(%rbp), %rdi
callq 0x3190
leaq 0xdcce(%rip), %rsi      # 0x1202d
leaq -0x4a8(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x3230
leaq -0x48(%rbp), %rdi
movq %rdi, 0x8(%rdi)
movq %rdi, (%rdi)
andq $0x0, 0x10(%rdi)
leaq -0x30(%rbp), %rsi
callq 0x468e
leaq 0x17f62(%rip), %r13     # 0x1c2f0
movq 0x18(%r13), %r14
leaq -0x288(%rbp), %rbx
addq $0x8, %r13
leaq -0x2a8(%rbp), %r15
leaq -0x48(%rbp), %r12
cmpq %r13, %r14
je 0x43d9
leaq 0x20(%r14), %rsi
movq %r15, %rdi
callq 0x466e
movq %r12, %rdi
movq %rbx, %rsi
callq 0x468e
movq %r15, %rdi
callq 0x3448
movq %r14, %rdi
callq 0x3170
movq %rax, %r14
jmp 0x43a8
leaq -0x60(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x469e
leaq -0x4a8(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x4a13
leaq -0x60(%rbp), %rdi
callq 0x46d8
leaq -0x4a8(%rbp), %rdi
callq 0x3300
movl 0x17eaf(%rip), %eax     # 0x1c2c0
testl %eax, %eax
je 0x445e
cmpl $0x1, %eax
jne 0x44af
leaq 0x17ea3(%rip), %rsi     # 0x1c2c8
leaq -0x2a8(%rbp), %rdi
pushq $0x10
popq %rdx
callq 0x3420
movq -0x30(%rbp), %rsi
leaq -0x2a8(%rbp), %rdi
callq 0x82ce
leaq -0x2a8(%rbp), %rdi
callq 0x3300
leaq -0x2a8(%rbp), %rdi
callq 0x3340
jmp 0x44af
leaq -0x2a8(%rbp), %rdi
callq 0x3180
leaq -0x298(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x82ce
leaq -0x290(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x3380
movq 0x17b37(%rip), %rdi     # 0x1bfc8
leaq -0x80(%rbp), %rsi
callq 0x31d0
leaq -0x80(%rbp), %rdi
callq 0x3448
leaq -0x2a8(%rbp), %rdi
callq 0x3190
leaq -0x48(%rbp), %rdi
callq 0x46d8
leaq -0x4a8(%rbp), %rdi
callq 0x3340
leaq -0xa8(%rbp), %rdi
callq 0xb35e
xorl %eax, %eax
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x3448
jmp 0x44f7
jmp 0x44f4
movq %rax, %rbx
leaq -0x2a8(%rbp), %rdi
callq 0x3190
jmp 0x456b
jmp 0x4557
jmp 0x4557
jmp 0x4582
jmp 0x4552
jmp 0x4552
jmp 0x454b
jmp 0x4582
jmp 0x4552
jmp 0x4552
jmp 0x454b
movq %rax, %rbx
leaq -0x2a8(%rbp), %rdi
callq 0x3340
jmp 0x456b
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x46d8
jmp 0x456b
jmp 0x454b
jmp 0x454b
movq %rax, %rbx
movq %r14, %rdi
callq 0x31e0
jmp 0x459d
jmp 0x454b
movq %rax, %rbx
jmp 0x459d
jmp 0x4557
movq %rax, %rbx
jmp 0x4591
movq %rax, %rbx
jmp 0x456b
movq %rax, %rbx
leaq -0x2a8(%rbp), %rdi
callq 0x3448
leaq -0x48(%rbp), %rdi
callq 0x46d8
leaq -0x4a8(%rbp), %rdi
callq 0x3340
jmp 0x459d
movq %rax, %rbx
leaq -0x2a8(%rbp), %rdi
callq 0x3448
leaq -0x4a8(%rbp), %rdi
callq 0x3190
leaq -0xa8(%rbp), %rdi
callq 0xb35e
movq %rbx, %rdi
callq 0x33f0