// File: /workspace/github_cpp_makefile_star2_O1/AndrewAlbert[P]Compiler-Theory/SourceCode/compiler.cpp
// Function: main
int main(int argc, char **argv){
	bool debug;
	string filename;
	if( (argc == 2) || (argc == 3) ){
		if( (string(argv[1]) == "--help") || (string(argv[1]) == "--h") ){
			cout << "\nThis is a compiler written for the University of Cincinnati class: EECE6083 Compiler Theory" << endl;
			cout << "\nThe compiler is an LL(1) recursive descent compiler and utilizes the C++ programming language to scan, parse, and type check the program and LLVM to generate the compiler backend." << endl;
			cout << "\nTo use this compiler, compile and then run from the command line using the arguments: [ --help | --h | --debug | --d ] filename." << endl;
			cout << "\nThe compiler will scan and parse your file and generate code if parsing is successful. Otherwise relevant errors and warnings will be shown." << endl;
			cout << "\n--debug or --d argument will print out each token as it is scanned and print out each scope's symbol table after the scope is exited." << endl;
			return 0;
		}
		else if( (string(argv[1]) == "--debug") || (string(argv[1]) == "--d") ){
			debug = true;
			filename = string(argv[2]);
		}
		else if(argc == 2){
			debug = false;
			filename = string(argv[1]);
		}	
	}
	else{
		commandError();
		return 0;
	}

	//Initialize scanner and symbol tables.
	Scanner *scanner = new Scanner;
	scopeTracker *scopes = new scopeTracker(debug);
	codeGenerator *gen = new codeGenerator;

	//Contains token currently being scanned/parsed
	token_type *token = new token_type;

	scanner->token = token;
	//Initialize scanner, then begin parsing if there are no errors
	if(scanner->InitScanner(filename, debug)){
		*token = scanner->getToken();
		gen->attachOutputFile( (filename) + ".c" );
		Parser parser(token, scanner, scopes, gen);
	}
	delete scanner;
	delete scopes;
	delete gen;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
leaq 0x20(%rsp), %r14
movq %r14, -0x10(%r14)
movq $0x0, -0x8(%r14)
movb $0x0, (%r14)
movl %edi, %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x18170
movq %rsi, %rbx
movl %edi, %ebp
movq 0x8(%rsi), %rsi
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x1876a
leaq 0x33cd(%rip), %rsi      # 0x1b4f7
leaq 0xb0(%rsp), %rdi
callq 0x20a0
movl %eax, %r14d
testl %eax, %eax
je 0x1817a
movq 0x8(%rbx), %rsi
leaq 0x90(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x1876a
leaq 0x33a3(%rip), %rsi      # 0x1b4fe
leaq 0x90(%rsp), %rdi
callq 0x20a0
testl %eax, %eax
sete %r15b
jmp 0x1817d
callq 0x18094
jmp 0x18668
movb $0x1, %r15b
testl %r14d, %r14d
je 0x181a3
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x181a3
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x181c4
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2200
testb %r15b, %r15b
je 0x18335
movq 0x9e04(%rip), %rbx      # 0x21fd8
leaq 0x3327(%rip), %rsi      # 0x1b502
movl $0x5c, %edx
movq %rbx, %rdi
leaq 0x20(%rsp), %r14
callq 0x2230
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x9dcd(%rip), %rdi      # 0x21fd8
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq 0x9db9(%rip), %rbx      # 0x21fd8
leaq 0x3339(%rip), %rsi      # 0x1b55f
movl $0xb4, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x9d87(%rip), %rdi      # 0x21fd8
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq 0x9d73(%rip), %rbx      # 0x21fd8
leaq 0x33a8(%rip), %rsi      # 0x1b614
movl $0x81, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x9d41(%rip), %rdi      # 0x21fd8
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq 0x9d2d(%rip), %rbx      # 0x21fd8
leaq 0x33e4(%rip), %rsi      # 0x1b696
movl $0x8d, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x9cfb(%rip), %rdi      # 0x21fd8
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq 0x9ce7(%rip), %rbx      # 0x21fd8
leaq 0x342c(%rip), %rsi      # 0x1b724
movl $0x86, %edx
movq %rbx, %rdi
callq 0x2230
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21d0
movsbl %al, %esi
movq 0x9cb5(%rip), %rdi      # 0x21fd8
callq 0x2030
movq %rax, %rdi
callq 0x2140
jmp 0x18668
movq 0x8(%rbx), %rsi
leaq 0xb0(%rsp), %rdi
leaq 0xd(%rsp), %rdx
callq 0x1876a
leaq 0x3459(%rip), %rsi      # 0x1b7ab
leaq 0xb0(%rsp), %rdi
callq 0x20a0
movl %eax, %r14d
testl %eax, %eax
je 0x18392
movq 0x8(%rbx), %rsi
leaq 0x70(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x1876a
leaq 0x3433(%rip), %rsi      # 0x1b7b3
leaq 0x70(%rsp), %rdi
callq 0x20a0
testl %eax, %eax
sete %r15b
jmp 0x18395
movb $0x1, %r15b
testl %r14d, %r14d
je 0x183bb
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x183bb
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x183e0
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2200
testb %r15b, %r15b
je 0x18435
movq 0x10(%rbx), %rsi
leaq 0xb0(%rsp), %rdi
leaq 0xd(%rsp), %rdx
callq 0x1876a
leaq 0x10(%rsp), %rdi
leaq 0xb0(%rsp), %rbx
movq %rbx, %rsi
callq 0x2270
movq (%rbx), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x18430
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2200
movb $0x1, %r15b
jmp 0x18488
cmpl $0x2, %ebp
jne 0x18488
movq 0x8(%rbx), %rsi
leaq 0xb0(%rsp), %rdi
leaq 0xd(%rsp), %rdx
callq 0x1876a
leaq 0x10(%rsp), %rdi
leaq 0xb0(%rsp), %rbx
movq %rbx, %rsi
callq 0x2270
movq (%rbx), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x18485
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %r15d, %r15d
movl $0x178, %edi            # imm = 0x178
callq 0x21f0
movq %rax, %rbx
movq %rax, %rdi
callq 0x261c
movl $0x20, %edi
callq 0x21f0
movq %rax, %r14
movzbl %r15b, %ebp
andl $0x1, %ebp
movq %rax, %rdi
movl %ebp, %esi
callq 0xfae8
movl $0x338, %edi            # imm = 0x338
callq 0x21f0
movq %rax, %r15
movq %rax, %rdi
callq 0x10318
movl $0x128, %edi            # imm = 0x128
callq 0x21f0
movq %rax, %r12
addq $0x10, %rax
movq %rax, (%r12)
movq $0x0, 0x8(%r12)
movb $0x0, 0x10(%r12)
movq %r12, 0x170(%rbx)
leaq 0x60(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0x3ba4
leaq 0x50(%rsp), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x2698
movl %eax, %ebp
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x18543
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
testb %bpl, %bpl
je 0x18624
leaq 0xb0(%rsp), %rdi
movq %rbx, %rsi
callq 0x31f0
leaq 0xb0(%rsp), %rsi
movq %r12, %rdi
callq 0x2270
movq %r12, %rdi
addq $0x20, %rdi
leaq 0xd0(%rsp), %r13
movl $0x108, %edx            # imm = 0x108
movq %r13, %rsi
callq 0x2190
movq -0x20(%r13), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x185a9
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x40(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0x3ba4
leaq 0x31e7(%rip), %rsi      # 0x1b7b7
leaq 0x30(%rsp), %rdi
callq 0x2380
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x10c20
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x185fe
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0xb0(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %rcx
movq %r15, %r8
callq 0x4030
leaq 0xb0(%rsp), %rdi
callq 0x49b8
movq %rbx, %rdi
callq 0x265c
movl $0x178, %esi            # imm = 0x178
movq %rbx, %rdi
callq 0x2200
movq %r14, %rdi
callq 0xfafc
movl $0x20, %esi
movq %r14, %rdi
callq 0x2200
movq %r15, %rdi
callq 0x10836
movl $0x338, %esi            # imm = 0x338
movq %r15, %rdi
callq 0x2200
leaq 0x20(%rsp), %r14
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x1867f
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %eax, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x18743
jmp 0x18743
jmp 0x1869f
movq %rax, %r12
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x18746
movq 0x40(%rsp), %rsi
jmp 0x18735
jmp 0x18743
jmp 0x18743
movq %rax, %r12
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
jmp 0x18728
movq %rax, %r12
movq 0x50(%rsp), %rdi
cmpq %r13, %rdi
je 0x18746
movq 0x60(%rsp), %rsi
jmp 0x18735
movq %rax, %r12
movl $0x338, %esi            # imm = 0x338
movq %r15, %rdi
jmp 0x18738
jmp 0x18743
movq %rax, %r12
movl $0x20, %esi
movq %r14, %rdi
jmp 0x18738
jmp 0x18743
movq %rax, %r12
movl $0x178, %esi            # imm = 0x178
movq %rbx, %rdi
jmp 0x18738
jmp 0x18743
jmp 0x18743
movq %rax, %r12
leaq 0xc0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x18746
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x18746
jmp 0x18743
jmp 0x18743
movq %rax, %r12
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x18762
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r12, %rdi
callq 0x2330