// File: olly-larkin[P]mips-parser/src/main.cpp
// Function: main
int main(int argc, char* argv[]) {

	std::vector< std::vector<std::string> > commVector;
	std::cerr << std::endl;

	if (argc == 1) {
		std::cerr << "------------------------------------- " << std::endl;
		std::cerr << "*********** CONSOLE INPUT *********** " << std::endl;
		std::cerr << "------------------------------------- " << std::endl << std::endl;
		vecParser(std::cin, commVector);
	} else {
		std::string inFileName = argv[1];
		std::ifstream inFile(inFileName);
		if (!inFile.is_open()) {
			std::cerr << "Unable to open file." << std::endl << std::endl;
			std::exit(0);
		}
		vecParser(inFile, commVector);
		inFile.close();
	}

	std::cerr << std::endl << "Commands passed successfully." << std::endl;

	std::string outFileName;
	
	if (argc == 1) {
		std::cerr << "Please enter an output file name: ";
		std::cin >> outFileName;
	} else {
		outFileName = formatName(argv[1]);
		if (argc == 3) {
			std::string str = argv[2];
			if (str.back() == '#') {
				str.pop_back();
				outFileName = str + outFileName;
			} else
				outFileName = argv[2];
		}
	}

	std::ofstream outFile(outFileName, std::ios::binary);
	if (!outFile.is_open()) {
		std::cerr << "Unable to generate output file." << std::endl << std::endl;
		std::exit(5);
	}
	binGen(outFile, commVector);
	outFile.close();

	std::cerr << "Output file generated: " << outFileName << std::endl << std::endl;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5d0, %rsp            # imm = 0x5D0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5930
movq 0x15e37(%rip), %rdi     # 0x1aff0
movq 0x15df8(%rip), %rsi     # 0x1afb8
callq 0x3290
jmp 0x51c7
cmpl $0x1, -0x8(%rbp)
jne 0x52a8
movq 0x15e18(%rip), %rdi     # 0x1aff0
leaq 0xde25(%rip), %rsi      # 0x13004
callq 0x3250
movq %rax, -0x520(%rbp)
jmp 0x51ed
movq -0x520(%rbp), %rdi
movq 0x15dbd(%rip), %rsi     # 0x1afb8
callq 0x3290
jmp 0x5202
movq 0x15de7(%rip), %rdi     # 0x1aff0
leaq 0xde1b(%rip), %rsi      # 0x1302b
callq 0x3250
movq %rax, -0x528(%rbp)
jmp 0x521e
movq -0x528(%rbp), %rdi
movq 0x15d8c(%rip), %rsi     # 0x1afb8
callq 0x3290
jmp 0x5233
movq 0x15db6(%rip), %rdi     # 0x1aff0
leaq 0xddc3(%rip), %rsi      # 0x13004
callq 0x3250
movq %rax, -0x530(%rbp)
jmp 0x524f
movq -0x530(%rbp), %rdi
movq 0x15d5b(%rip), %rsi     # 0x1afb8
callq 0x3290
movq %rax, -0x538(%rbp)
jmp 0x526b
movq -0x538(%rbp), %rdi
movq 0x15d3f(%rip), %rsi     # 0x1afb8
callq 0x3290
jmp 0x5280
movq 0x15d51(%rip), %rdi     # 0x1afd8
leaq -0x28(%rbp), %rsi
callq 0x6010
jmp 0x5292
jmp 0x53ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x57ee
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x548(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x540(%rbp)
callq 0x3430
movq -0x548(%rbp), %rsi
movq -0x540(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x3330
jmp 0x52e0
leaq -0x59(%rbp), %rdi
callq 0x32b0
leaq -0x268(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movl $0x8, %edx
callq 0x33e0
jmp 0x5300
leaq -0x268(%rbp), %rdi
callq 0x33d0
movb %al, -0x549(%rbp)
jmp 0x5314
movb -0x549(%rbp), %al
testb $0x1, %al
jne 0x53ba
jmp 0x5324
movq 0x15cc5(%rip), %rdi     # 0x1aff0
leaq 0xdd20(%rip), %rsi      # 0x13052
callq 0x3250
movq %rax, -0x558(%rbp)
jmp 0x5340
movq -0x558(%rbp), %rdi
movq 0x15c6a(%rip), %rsi     # 0x1afb8
callq 0x3290
movq %rax, -0x560(%rbp)
jmp 0x535c
movq -0x560(%rbp), %rdi
movq 0x15c4e(%rip), %rsi     # 0x1afb8
callq 0x3290
jmp 0x5371
xorl %edi, %edi
callq 0x32c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x32b0
jmp 0x57ee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x53f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x30b0
jmp 0x53f1
leaq -0x268(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x6010
jmp 0x53cc
leaq -0x268(%rbp), %rdi
callq 0x3090
jmp 0x53da
leaq -0x268(%rbp), %rdi
callq 0x30b0
leaq -0x58(%rbp), %rdi
callq 0x31a0
jmp 0x53ff
leaq -0x58(%rbp), %rdi
callq 0x31a0
jmp 0x57ee
movq 0x15bea(%rip), %rdi     # 0x1aff0
movq 0x15bab(%rip), %rsi     # 0x1afb8
callq 0x3290
movq %rax, -0x568(%rbp)
jmp 0x541b
movq -0x568(%rbp), %rdi
leaq 0xdc3e(%rip), %rsi      # 0x13067
callq 0x3250
movq %rax, -0x570(%rbp)
jmp 0x5437
movq -0x570(%rbp), %rdi
movq 0x15b73(%rip), %rsi     # 0x1afb8
callq 0x3290
jmp 0x544c
leaq -0x288(%rbp), %rdi
callq 0x3340
cmpl $0x1, -0x8(%rbp)
jne 0x549e
movq 0x15b8b(%rip), %rdi     # 0x1aff0
leaq 0xdc19(%rip), %rsi      # 0x13085
callq 0x3250
jmp 0x5473
movq 0x15b5e(%rip), %rdi     # 0x1afd8
leaq -0x288(%rbp), %rsi
callq 0x32f0
jmp 0x5488
jmp 0x567e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x57e2
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x580(%rbp)
leaq -0x2c9(%rbp), %rdi
movq %rdi, -0x578(%rbp)
callq 0x3430
movq -0x580(%rbp), %rsi
movq -0x578(%rbp), %rdx
leaq -0x2c8(%rbp), %rdi
callq 0x3330
jmp 0x54dc
leaq -0x2a8(%rbp), %rdi
leaq -0x2c8(%rbp), %rsi
callq 0x5800
jmp 0x54f1
leaq -0x288(%rbp), %rdi
leaq -0x2a8(%rbp), %rsi
callq 0x32e0
leaq -0x2a8(%rbp), %rdi
callq 0x31a0
leaq -0x2c8(%rbp), %rdi
callq 0x31a0
leaq -0x2c9(%rbp), %rdi
callq 0x32b0
cmpl $0x3, -0x8(%rbp)
jne 0x567c
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x590(%rbp)
leaq -0x2f1(%rbp), %rdi
movq %rdi, -0x588(%rbp)
callq 0x3430
movq -0x590(%rbp), %rsi
movq -0x588(%rbp), %rdx
leaq -0x2f0(%rbp), %rdi
callq 0x3330
jmp 0x5570
leaq -0x2f1(%rbp), %rdi
callq 0x32b0
leaq -0x2f0(%rbp), %rdi
callq 0x31f0
movsbl (%rax), %eax
cmpl $0x23, %eax
jne 0x5658
leaq -0x2f0(%rbp), %rdi
movq %rdi, -0x598(%rbp)
callq 0x32d0
movq -0x598(%rbp), %rsi
leaq -0x318(%rbp), %rdi
leaq -0x288(%rbp), %rdx
callq 0x5950
jmp 0x55c3
leaq -0x288(%rbp), %rdi
leaq -0x318(%rbp), %rsi
callq 0x32e0
leaq -0x318(%rbp), %rdi
callq 0x31a0
jmp 0x5670
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
jmp 0x560d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x2c8(%rbp), %rdi
callq 0x31a0
leaq -0x2c9(%rbp), %rdi
callq 0x32b0
jmp 0x57e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x2f1(%rbp), %rdi
callq 0x32b0
jmp 0x57e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x2f0(%rbp), %rdi
callq 0x31a0
jmp 0x57e2
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
leaq -0x288(%rbp), %rdi
callq 0x3320
jmp 0x566e
jmp 0x5670
leaq -0x2f0(%rbp), %rdi
callq 0x31a0
jmp 0x567e
leaq -0x518(%rbp), %rdi
leaq -0x288(%rbp), %rsi
movl $0x4, %edx
callq 0x3450
jmp 0x5698
leaq -0x518(%rbp), %rdi
callq 0x3200
movb %al, -0x599(%rbp)
jmp 0x56ac
movb -0x599(%rbp), %al
testb $0x1, %al
jne 0x572c
jmp 0x56b8
movq 0x15931(%rip), %rdi     # 0x1aff0
leaq 0xd9e2(%rip), %rsi      # 0x130a8
callq 0x3250
movq %rax, -0x5a8(%rbp)
jmp 0x56d4
movq -0x5a8(%rbp), %rdi
movq 0x158d6(%rip), %rsi     # 0x1afb8
callq 0x3290
movq %rax, -0x5b0(%rbp)
jmp 0x56f0
movq -0x5b0(%rbp), %rdi
movq 0x158ba(%rip), %rsi     # 0x1afb8
callq 0x3290
jmp 0x5705
movl $0x5, %edi
callq 0x32c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x518(%rbp), %rdi
callq 0x3380
jmp 0x57e2
leaq -0x518(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x6dc0
jmp 0x573e
leaq -0x518(%rbp), %rdi
callq 0x3350
jmp 0x574c
movq 0x1589d(%rip), %rdi     # 0x1aff0
leaq 0xd96e(%rip), %rsi      # 0x130c8
callq 0x3250
movq %rax, -0x5b8(%rbp)
jmp 0x5768
movq -0x5b8(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x3230
movq %rax, -0x5c0(%rbp)
jmp 0x5784
movq -0x5c0(%rbp), %rdi
movq 0x15826(%rip), %rsi     # 0x1afb8
callq 0x3290
movq %rax, -0x5c8(%rbp)
jmp 0x57a0
movq -0x5c8(%rbp), %rdi
movq 0x1580a(%rip), %rsi     # 0x1afb8
callq 0x3290
jmp 0x57b5
leaq -0x518(%rbp), %rdi
callq 0x3380
leaq -0x288(%rbp), %rdi
callq 0x31a0
leaq -0x28(%rbp), %rdi
callq 0x59d0
movl -0x4(%rbp), %eax
addq $0x5d0, %rsp            # imm = 0x5D0
popq %rbp
retq
leaq -0x288(%rbp), %rdi
callq 0x31a0
leaq -0x28(%rbp), %rdi
callq 0x59d0
movq -0x30(%rbp), %rdi
callq 0x3420