// File: /workspace/github_cpp_makefile_star2_O1/kram[P]kram/src/main.cpp
// Function: main
int main(int argc, char** argv) {

	bool debug = false;
	std::string file = "";

	// Parse arguments
	// This probable needs to become way more advanced in the future, but it is enough for now...
	if (argc > 1) {
		for (int i = 1; i < argc; i++) {
			std::string arg(argv[i]);

			if (arg.substr(0, 2) == "--") {

				if (arg == "--debug") {
					debug = true;
				} else if (arg == "--help") {
					kr_print_help();
					exit(0);
				} else if (arg == "--version") {
					kr_print_version();
					exit(0);
				}

			} else {
				file = arg;
			}
		}
	} else {
		kr_print_help();
		exit(0);
	}

	// Define output stream
	kram_output_stream = new Output(std::cout);

	lexer::Lexer lexer;
	std::vector<lexer::Token*> tokens = lexer.parse_file(file);

	if (debug) {
		lexer::Lexer::print(tokens);
	}

	Parser parser (tokens);
	std::vector<Instruction*> instructions = parser.run();

	if (debug) {
		std::cout << "Printing ins:\n";

		for (Instruction* ins : instructions) {
			ins->print();
			std::cout << "--------\n";
		}
	}

	VM vm;
	vm.boot(instructions);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa88, %rsp            # imm = 0xA88
movq %rsi, %rbx
movl %edi, %r14d
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xff8f(%rip), %rdx      # 0x13908
leaq 0x8(%rsp), %rdi
movq %rdx, %rsi
callq 0x47cc
cmpl $0x2, %r14d
jl 0x3d62
movl %r14d, %ebp
movl $0x1, %r12d
movq $0x0, (%rsp)
leaq 0x230(%rsp), %r14
leaq 0x128(%rsp), %r15
movq (%rbx,%r12,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x30f0
movl $0x2, %ecx
movq %r15, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x3280
movq %r15, %rdi
leaq 0xf6d4(%rip), %rsi      # 0x130b0
callq 0x30a0
movl %eax, %r13d
movq 0x128(%rsp), %rdi
leaq 0x138(%rsp), %rax
cmpq %rax, %rdi
je 0x39fe
callq 0x3230
testl %r13d, %r13d
je 0x3a12
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x3150
jmp 0x3a5a
movq %r14, %rdi
leaq 0xf697(%rip), %rsi      # 0x130b3
callq 0x30a0
testl %eax, %eax
je 0x3a54
movq %r14, %rdi
leaq 0xf68c(%rip), %rsi      # 0x130bb
callq 0x30a0
testl %eax, %eax
je 0x3d56
movq %r14, %rdi
leaq 0xf67c(%rip), %rsi      # 0x130c2
callq 0x30a0
testl %eax, %eax
jne 0x3a5a
jmp 0x3d4f
movb $0x1, %al
movq %rax, (%rsp)
movq 0x230(%rsp), %rdi
leaq 0x240(%rsp), %rax
cmpq %rax, %rdi
je 0x3a74
callq 0x3230
incq %r12
cmpq %r12, %rbp
jne 0x39b1
movl $0x110, %edi            # imm = 0x110
callq 0x3260
movq %rax, %r14
movq 0x1853c(%rip), %rax     # 0x1bfd0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq 0xe8(%rax,%rcx), %rsi
movq %r14, %rdi
callq 0x30e0
movq %r14, 0x18786(%rip)     # 0x1c238
leaq 0xc0(%rsp), %rdi
callq 0x4894
leaq 0xb0(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0xa0(%rsp), %rdi
callq 0x473c
leaq 0x40(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
callq 0x4ace
movq 0xa0(%rsp), %rdi
cmpq %r14, %rdi
je 0x3b11
callq 0x3230
movq (%rsp), %rbx
testb $0x1, %bl
je 0x3b4b
leaq 0x88(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x3e60
leaq 0x88(%rsp), %rdi
callq 0x5604
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x3b4b
callq 0x3230
leaq 0x70(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x3e60
leaq 0x128(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xd9bc
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x3b7b
callq 0x3230
leaq 0x28(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0xdda2
testb $0x1, %bl
je 0x3bea
movq 0x18437(%rip), %rdi     # 0x1bfd0
leaq 0xf52c(%rip), %rsi      # 0x130cc
movl $0xe, %edx
callq 0x32a0
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %r12
cmpq %r12, %r15
je 0x3bea
movq 0x18410(%rip), %rbx     # 0x1bfd0
leaq 0xf514(%rip), %r14      # 0x130db
movq (%r15), %rdi
xorl %esi, %esi
callq 0x3ee0
movl $0x9, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32a0
addq $0x8, %r15
cmpq %r12, %r15
jne 0x3bc7
xorps %xmm0, %xmm0
movaps %xmm0, 0x230(%rsp)
xorl %eax, %eax
movq %rax, 0x240(%rsp)
movq %rax, 0xa60(%rsp)
movl %eax, 0xa68(%rsp)
movq %rax, 0xa70(%rsp)
movl %eax, 0xa78(%rsp)
movq %rax, 0xa80(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x450e
leaq 0x230(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x968c
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x3c55
callq 0x3230
movq 0xa60(%rsp), %rdi
testq %rdi, %rdi
je 0x3c8f
callq 0x3230
xorl %eax, %eax
movq %rax, 0xa60(%rsp)
movl %eax, 0xa68(%rsp)
movq %rax, 0xa70(%rsp)
movl %eax, 0xa78(%rsp)
movq %rax, 0xa80(%rsp)
movq 0x230(%rsp), %rdi
testq %rdi, %rdi
je 0x3ca1
callq 0x3230
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3cb0
callq 0x3230
leaq 0x1f8(%rsp), %rdi
callq 0x4644
leaq 0x1c0(%rsp), %rdi
callq 0x4644
leaq 0x188(%rsp), %rdi
callq 0x4644
leaq 0x150(%rsp), %rbx
movq %rbx, %rdi
callq 0x4644
movq -0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x3cf5
callq 0x3230
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3d04
callq 0x3230
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3d1a
callq 0x3230
leaq 0xc0(%rsp), %rdi
callq 0x46a6
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x3d3b
callq 0x3230
xorl %eax, %eax
addq $0xa88, %rsp            # imm = 0xA88
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x38a1
jmp 0x3d5b
callq 0x380c
xorl %edi, %edi
callq 0x32c0
callq 0x380c
jmp 0x3d5b
jmp 0x3de3
movq %rax, %rbx
movq 0x88(%rsp), %rdi
jmp 0x3dad
jmp 0x3db9
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x3d91
callq 0x3230
jmp 0x3d91
movq %rax, %rbx
leaq 0x230(%rsp), %rdi
callq 0x458e
jmp 0x3de6
movq %rax, %rbx
jmp 0x3df5
movq %rax, %rbx
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x3e02
callq 0x3230
jmp 0x3e02
movq %rax, %rbx
jmp 0x3e02
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
cmpq %r14, %rdi
jne 0x3e0c
jmp 0x3e11
movq %rax, %rbx
jmp 0x3e11
jmp 0x3e22
movq %rax, %rbx
movq %r14, %rdi
jmp 0x3e3f
jmp 0x3e22
jmp 0x3e27
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x3df5
callq 0x3230
leaq 0x128(%rsp), %rdi
callq 0x45b6
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3e11
callq 0x3230
leaq 0xc0(%rsp), %rdi
callq 0x45f4
jmp 0x3e44
jmp 0x3e27
movq %rax, %rbx
jmp 0x3e44
movq %rax, %rbx
movq 0x230(%rsp), %rdi
leaq 0x240(%rsp), %rax
cmpq %rax, %rdi
je 0x3e44
callq 0x3230
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x3e58
callq 0x3230
movq %rbx, %rdi
callq 0x33c0