// File: /workspace/github_cpp_makefile_star2_O3/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 $0x1b8, %rsp            # imm = 0x1B8
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 0x180c8
movq %rsi, %rbx
movl %edi, %ebp
movq 0x8(%rsi), %rsi
leaq 0x90(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x1869c
leaq 0x3489(%rip), %rsi      # 0x1b4f7
leaq 0x90(%rsp), %rdi
callq 0x20a0
testl %eax, %eax
je 0x180d2
movq 0x8(%rbx), %rsi
leaq 0x50(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x1869c
leaq 0x3465(%rip), %rsi      # 0x1b4fe
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x20a0
testl %eax, %eax
sete %r15b
movq (%r14), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x180d5
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x180d5
callq 0x17fd8
jmp 0x18594
movb $0x1, %r15b
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x180f6
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
testb %r15b, %r15b
je 0x18267
movq 0x9ed2(%rip), %rbx      # 0x21fd8
leaq 0x33f5(%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 0x9e9b(%rip), %rdi      # 0x21fd8
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq 0x9e87(%rip), %rbx      # 0x21fd8
leaq 0x3407(%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 0x9e55(%rip), %rdi      # 0x21fd8
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq 0x9e41(%rip), %rbx      # 0x21fd8
leaq 0x3476(%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 0x9e0f(%rip), %rdi      # 0x21fd8
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq 0x9dfb(%rip), %rbx      # 0x21fd8
leaq 0x34b2(%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 0x9dc9(%rip), %rdi      # 0x21fd8
callq 0x2030
movq %rax, %rdi
callq 0x2140
movq 0x9db5(%rip), %rbx      # 0x21fd8
leaq 0x34fa(%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 0x9d83(%rip), %rdi      # 0x21fd8
callq 0x2030
movq %rax, %rdi
callq 0x2140
jmp 0x18594
movq 0x8(%rbx), %rsi
leaq 0x90(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x1869c
leaq 0x3527(%rip), %rsi      # 0x1b7ab
leaq 0x90(%rsp), %rdi
callq 0x20a0
testl %eax, %eax
je 0x182de
movq 0x8(%rbx), %rsi
leaq 0x50(%rsp), %rdi
leaq 0xe(%rsp), %rdx
callq 0x1869c
leaq 0x3504(%rip), %rsi      # 0x1b7b3
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x20a0
testl %eax, %eax
sete %r15b
movq (%r14), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x182e1
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x182e1
movb $0x1, %r15b
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x18306
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
testb %r15b, %r15b
je 0x1835b
movq 0x10(%rbx), %rsi
leaq 0x90(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x1869c
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0x2270
movq (%rbx), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x18356
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
movb $0x1, %r15b
jmp 0x183ae
cmpl $0x2, %ebp
jne 0x183ae
movq 0x8(%rbx), %rsi
leaq 0x90(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x1869c
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0x2270
movq (%rbx), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x183ab
movq 0xa0(%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 0xfa48
movl $0x338, %edi            # imm = 0x338
callq 0x21f0
movq %rax, %r15
movq %rax, %rdi
callq 0x10240
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 0x80(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x3bac
leaq 0x70(%rsp), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x2698
movl %eax, %ebp
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x1846f
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
testb %bpl, %bpl
je 0x18550
leaq 0x90(%rsp), %rdi
movq %rbx, %rsi
callq 0x31f0
leaq 0x90(%rsp), %rsi
movq %r12, %rdi
callq 0x2270
movq %r12, %rdi
addq $0x20, %rdi
leaq 0xb0(%rsp), %r13
movl $0x108, %edx            # imm = 0x108
movq %r13, %rsi
callq 0x2190
movq -0x20(%r13), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x184d5
movq 0xa0(%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 0x3bac
leaq 0x32bb(%rip), %rsi      # 0x1b7b7
leaq 0x30(%rsp), %rdi
callq 0x2380
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
callq 0x10b44
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x1852a
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %r14, %rcx
movq %r15, %r8
callq 0x4044
leaq 0x90(%rsp), %rdi
callq 0x49cc
movq %rbx, %rdi
callq 0x265c
movl $0x178, %esi            # imm = 0x178
movq %rbx, %rdi
callq 0x2200
movq %r14, %rdi
callq 0xfa5c
movl $0x20, %esi
movq %r14, %rdi
callq 0x2200
movq %r15, %rdi
callq 0x1075e
movl $0x338, %esi            # imm = 0x338
movq %r15, %rdi
callq 0x2200
leaq 0x20(%rsp), %r14
movq 0x10(%rsp), %rdi
cmpq %r14, %rdi
je 0x185ab
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %eax, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x18675
jmp 0x18675
jmp 0x185cb
movq %rax, %r12
movq 0x30(%rsp), %rdi
cmpq %r13, %rdi
je 0x18678
movq 0x40(%rsp), %rsi
jmp 0x18667
jmp 0x18675
jmp 0x18675
movq %rax, %r12
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
jmp 0x1865a
movq %rax, %r12
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x18678
movq 0x80(%rsp), %rsi
jmp 0x18667
movq %rax, %r12
movl $0x338, %esi            # imm = 0x338
movq %r15, %rdi
jmp 0x1866a
jmp 0x18675
movq %rax, %r12
movl $0x20, %esi
movq %r14, %rdi
jmp 0x1866a
jmp 0x18675
movq %rax, %r12
movl $0x178, %esi            # imm = 0x178
movq %rbx, %rdi
jmp 0x1866a
jmp 0x18675
jmp 0x18675
movq %rax, %r12
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x18678
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x18678
jmp 0x18675
jmp 0x18675
movq %rax, %r12
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x18694
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r12, %rdi
callq 0x2330