// File: jasperandrew[P]cs350-project2/lab7.cpp
// Function: main
int main(int argc, char **argv)
{
	cout << "Greetings, [INSERT_SUBJECT_NAME_HERE]!\n"
	        "Welcome to the Log-Indexed File Emulator, or L.I.F.E.\n"
	        "Wait just a moment while we set up a few things...\n\n";
	
	initDrive();
	checkPointInit();
	readFileMap();
	cout << "\nDone! Now it's time for you to grab L.I.F.E. by the horns!\n"
	        "Enter a command, or enter 'help' for usage information.\n"
	        "\n{epic prompt} ";

  string command;
  vector<string> args;
  while(getline(cin, command))
	{
		args.clear();
		split(command, ' ', args);
		if(!command.empty()){
			if((args[0] == "import" || args[0] == "i") && args.size() == 3) 
			{
				import(args[1], args[2]);                                                 
			}
			else if((args[0] == "remove" || args[0] == "r") && args.size() == 2)
			{
				remove(args[1]);
			}
			else if((args[0] == "cat" || args[0] == "r") && args.size() == 2)
			{
				cat(args[1]);
			}
			else if((args[0] == "list" || args[0] == "l") && args.size() == 1)
			{
				list();
			}
			else if((args[0] == "exit" || args[0] == "q") && args.size() == 1)
			{
				cout << "Getting L.I.F.E. together...\n\n";
				writeCheckpoint();
				wbuffer.writeToDisk();
				writeFileMap();
				cout << "\nQuitting L.I.F.E.\n\u0CA0_\u0CA0\n";
				exit(0);
			}
			else if((args[0] == "overwrite" || args[0] == "o") && args.size() == 5)
			  {
			    cout<<"overwriting...\n";
			    overwrite(args[1],args[2], args[3],args[4]);
			  }
			else if((args[0] == "display" || args[0] == "d") && args.size() == 4)

			{
				cout<<"displaying...\n";
				//display(args[1],args[2], args[3]);
			}

			else if((args[0] == "help" || args[0] == "h"))
			{
				if(args.size() == 1){
					cout << "Thanks for calling L.I.F.E. help.\nHeaven knows we all need it from time to time.\nValid L.I.F.E. commands:\n"
									"\timport <filename> <lfs_filename>\n"
									"\tremove <lfs_filename>\n"
									"\tlist\n"
									"\texit\n"
									"For more details on a command, enter 'help <command>'.\n";
				}else if(args.size() == 2){
					if(args[1] == "import"){
						cout << "Usage: import <filepath> <lfs_filename>\n"
						        "Info:  Imports a file from a filepath to the DRIVE, using the given filename.\n";
					}
					else if(args[1] == "remove"){
						cout << "Usage: remove <lfs_filename>\n"
						        "Info:  Removes a file from the DRIVE.\n";
					}
					else if(args[1] == "list"){
						cout << "Usage: list\n"
						        "Info:  Lists the names and sizes of all files currently in the DRIVE.\n";
					}
					else if(args[1] == "exit"){
						cout << "Usage: exit\n"
						        "Info:  C'mon bro. Take a good guess.\n";
					}
					else if(args[1] == "help"){
						cout << "Usage: help <command>\n"
						        "Info:  Prints usage info for all commands, and optionally prints specific info for one command.\n";
					}else if(args[1] == "me"){
						cout << "You're not alone; many of us have had suicidal thoughts at some point in our lives. "
						        "Feeling suicidal is not a character defect, and it doesn't mean that you are crazy, or weak, or flawed. "
										"It only means that you have more pain than you can cope with right now. "
										"This pain seems overwhelming and permanent at the moment. "
										"But with time and support, you can overcome your problems and the pain and suicidal feelings will pass.\n"
										"If you’re feeling suicidal right now, please call for help!\n\n"
										"Call 1-800-273-TALK in the U.S.\n"
										"Or visit IASP(http://www.iasp.info/resources/Crisis_Centres) to find a helpline in your country. "
										"Alternatively, talk to someone you trust and let them know how bad things are.\n";
					}else{
						cout << "'" << args[1] << "' is not a command... Take your funny business elsewhere. This is a serious, real-world program.\n";
					}
				}else{
					cout << "Hey, don't get too crazy, now.\n";
				}
			}
			else
			{
				cout << "Invalid command and/or parameters. Enter 'help' for...y'know...help.\n";
			}
		}
		cout << "\n{epic prompt} ";
	}
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x70e8(%rip), %rdi      # 0xcfc8
leaq 0x3312(%rip), %rsi      # 0x91f9
callq 0x3220
callq 0x5530
callq 0x3a80
callq 0x3db0
movq 0x70c6(%rip), %rdi      # 0xcfc8
leaq 0x3382(%rip), %rsi      # 0x928b
callq 0x3220
leaq -0x30(%rbp), %rdi
callq 0x3330
leaq -0x48(%rbp), %rdi
callq 0x71b0
movq 0x70b9(%rip), %rdi      # 0xcfe0
leaq -0x30(%rbp), %rsi
callq 0x3060
movq %rax, -0x160(%rbp)
jmp 0x5f39
movq -0x160(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x32c0
movb %al, -0x161(%rbp)
jmp 0x5f57
movb -0x161(%rbp), %al
testb $0x1, %al
jne 0x5f66
jmp 0x68fd
leaq -0x48(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x71d0
movq -0x170(%rbp), %rdx
leaq -0x30(%rbp), %rdi
movl $0x20, %esi
callq 0x5da0
jmp 0x5f8d
leaq -0x30(%rbp), %rdi
callq 0x33f0
testb $0x1, %al
jne 0x68e3
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x335a(%rip), %rsi      # 0x930f
callq 0x6ed0
movb %al, -0x171(%rbp)
jmp 0x5fc2
movb -0x171(%rbp), %al
testb $0x1, %al
jne 0x6001
jmp 0x5fce
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x39e3(%rip), %rsi      # 0x99c8
callq 0x6ed0
movb %al, -0x172(%rbp)
jmp 0x5ff2
movb -0x172(%rbp), %al
testb $0x1, %al
jne 0x6001
jmp 0x60c0
leaq -0x48(%rbp), %rdi
callq 0x7210
cmpq $0x3, %rax
jne 0x60c0
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x71f0
movq %rax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x30f0
jmp 0x6030
leaq -0x48(%rbp), %rdi
movl $0x2, %esi
callq 0x71f0
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
callq 0x30f0
jmp 0x604f
leaq -0x78(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x4540
jmp 0x6061
leaq -0x98(%rbp), %rdi
callq 0x3170
leaq -0x78(%rbp), %rdi
callq 0x3170
jmp 0x68e1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x6922
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x60b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3170
leaq -0x78(%rbp), %rdi
callq 0x3170
jmp 0x6922
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x323f(%rip), %rsi      # 0x9316
callq 0x6ed0
movb %al, -0x173(%rbp)
jmp 0x60e4
movb -0x173(%rbp), %al
testb $0x1, %al
jne 0x6120
jmp 0x60f0
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x2f0b(%rip), %rsi      # 0x9012
callq 0x6ed0
movb %al, -0x174(%rbp)
jmp 0x6114
movb -0x174(%rbp), %al
testb $0x1, %al
jne 0x6120
jmp 0x618a
leaq -0x48(%rbp), %rdi
callq 0x7210
cmpq $0x2, %rax
jne 0x618a
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x71f0
movq %rax, %rsi
leaq -0xb8(%rbp), %rdi
callq 0x30f0
jmp 0x614e
leaq -0xb8(%rbp), %rdi
callq 0x4b30
jmp 0x615c
leaq -0xb8(%rbp), %rdi
callq 0x3170
jmp 0x68df
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x3170
jmp 0x6922
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x317c(%rip), %rsi      # 0x931d
callq 0x6ed0
movb %al, -0x175(%rbp)
jmp 0x61ae
movb -0x175(%rbp), %al
testb $0x1, %al
jne 0x61ea
jmp 0x61ba
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x2e41(%rip), %rsi      # 0x9012
callq 0x6ed0
movb %al, -0x176(%rbp)
jmp 0x61de
movb -0x176(%rbp), %al
testb $0x1, %al
jne 0x61ea
jmp 0x6254
leaq -0x48(%rbp), %rdi
callq 0x7210
cmpq $0x2, %rax
jne 0x6254
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x71f0
movq %rax, %rsi
leaq -0xd8(%rbp), %rdi
callq 0x30f0
jmp 0x6218
leaq -0xd8(%rbp), %rdi
callq 0x51e0
jmp 0x6226
leaq -0xd8(%rbp), %rdi
callq 0x3170
jmp 0x68dd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3170
jmp 0x6922
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x30b6(%rip), %rsi      # 0x9321
callq 0x6ed0
movb %al, -0x177(%rbp)
jmp 0x6278
movb -0x177(%rbp), %al
testb $0x1, %al
jne 0x62b4
jmp 0x6284
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x308b(%rip), %rsi      # 0x9326
callq 0x6ed0
movb %al, -0x178(%rbp)
jmp 0x62a8
movb -0x178(%rbp), %al
testb $0x1, %al
jne 0x62b4
jmp 0x62cf
leaq -0x48(%rbp), %rdi
callq 0x7210
cmpq $0x1, %rax
jne 0x62cf
callq 0x5120
jmp 0x62ca
jmp 0x68db
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x3042(%rip), %rsi      # 0x9328
callq 0x6ed0
movb %al, -0x179(%rbp)
jmp 0x62f3
movb -0x179(%rbp), %al
testb $0x1, %al
jne 0x632f
jmp 0x62ff
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x3017(%rip), %rsi      # 0x932d
callq 0x6ed0
movb %al, -0x17a(%rbp)
jmp 0x6323
movb -0x17a(%rbp), %al
testb $0x1, %al
jne 0x632f
jmp 0x638b
leaq -0x48(%rbp), %rdi
callq 0x7210
cmpq $0x1, %rax
jne 0x638b
movq 0x6c83(%rip), %rdi      # 0xcfc8
leaq 0x2fe3(%rip), %rsi      # 0x932f
callq 0x3220
jmp 0x6353
callq 0x3c20
jmp 0x635a
leaq 0x17540f(%rip), %rdi    # 0x17b770
callq 0x5ac0
jmp 0x6368
callq 0x3f90
jmp 0x636f
movq 0x6c52(%rip), %rdi      # 0xcfc8
leaq 0x2fd1(%rip), %rsi      # 0x934e
callq 0x3220
jmp 0x6384
xorl %edi, %edi
callq 0x32b0
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x2fc8(%rip), %rsi      # 0x936a
callq 0x6ed0
movb %al, -0x17b(%rbp)
jmp 0x63af
movb -0x17b(%rbp), %al
testb $0x1, %al
jne 0x63ee
jmp 0x63bb
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x2fa2(%rip), %rsi      # 0x9374
callq 0x6ed0
movb %al, -0x17c(%rbp)
jmp 0x63df
movb -0x17c(%rbp), %al
testb $0x1, %al
jne 0x63ee
jmp 0x6555
leaq -0x48(%rbp), %rdi
callq 0x7210
cmpq $0x5, %rax
jne 0x6555
movq 0x6bc0(%rip), %rdi      # 0xcfc8
leaq 0x2f67(%rip), %rsi      # 0x9376
callq 0x3220
jmp 0x6416
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x71f0
movq %rax, %rsi
leaq -0xf8(%rbp), %rdi
callq 0x30f0
jmp 0x6435
leaq -0x48(%rbp), %rdi
movl $0x2, %esi
callq 0x71f0
movq %rax, %rsi
leaq -0x118(%rbp), %rdi
callq 0x30f0
jmp 0x6454
leaq -0x48(%rbp), %rdi
movl $0x3, %esi
callq 0x71f0
movq %rax, %rsi
leaq -0x138(%rbp), %rdi
callq 0x30f0
jmp 0x6473
leaq -0x48(%rbp), %rdi
movl $0x4, %esi
callq 0x71f0
movq %rax, %rsi
leaq -0x158(%rbp), %rdi
callq 0x30f0
jmp 0x6492
leaq -0xf8(%rbp), %rdi
leaq -0x118(%rbp), %rsi
leaq -0x138(%rbp), %rdx
leaq -0x158(%rbp), %rcx
callq 0x4c40
jmp 0x64b5
leaq -0x158(%rbp), %rdi
callq 0x3170
leaq -0x138(%rbp), %rdi
callq 0x3170
leaq -0x118(%rbp), %rdi
callq 0x3170
leaq -0xf8(%rbp), %rdi
callq 0x3170
jmp 0x68d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x6544
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x6538
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x652c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x3170
leaq -0x138(%rbp), %rdi
callq 0x3170
leaq -0x118(%rbp), %rdi
callq 0x3170
leaq -0xf8(%rbp), %rdi
callq 0x3170
jmp 0x6922
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x2e1a(%rip), %rsi      # 0x9386
callq 0x6ed0
movb %al, -0x17d(%rbp)
jmp 0x6579
movb -0x17d(%rbp), %al
testb $0x1, %al
jne 0x65b5
jmp 0x6585
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x2df2(%rip), %rsi      # 0x938e
callq 0x6ed0
movb %al, -0x17e(%rbp)
jmp 0x65a9
movb -0x17e(%rbp), %al
testb $0x1, %al
jne 0x65b5
jmp 0x65de
leaq -0x48(%rbp), %rdi
callq 0x7210
cmpq $0x4, %rax
jne 0x65de
movq 0x69fd(%rip), %rdi      # 0xcfc8
leaq 0x2dbe(%rip), %rsi      # 0x9390
callq 0x3220
jmp 0x65d9
jmp 0x68d5
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x2daa(%rip), %rsi      # 0x939f
callq 0x6ed0
movb %al, -0x17f(%rbp)
jmp 0x6602
movb -0x17f(%rbp), %al
testb $0x1, %al
jne 0x6641
jmp 0x660e
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
callq 0x71f0
movq %rax, %rdi
leaq 0x2d7f(%rip), %rsi      # 0x93a4
callq 0x6ed0
movb %al, -0x180(%rbp)
jmp 0x6632
movb -0x180(%rbp), %al
testb $0x1, %al
jne 0x6641
jmp 0x68bc
leaq -0x48(%rbp), %rdi
callq 0x7210
cmpq $0x1, %rax
jne 0x666a
movq 0x6971(%rip), %rdi      # 0xcfc8
leaq 0x2d48(%rip), %rsi      # 0x93a6
callq 0x3220
jmp 0x6665
jmp 0x68ba
leaq -0x48(%rbp), %rdi
callq 0x7210
cmpq $0x2, %rax
jne 0x68a1
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x71f0
movq %rax, %rdi
leaq 0x2c7a(%rip), %rsi      # 0x930f
callq 0x6ed0
movb %al, -0x181(%rbp)
jmp 0x66a2
movb -0x181(%rbp), %al
testb $0x1, %al
jne 0x66ae
jmp 0x66c8
movq 0x6913(%rip), %rdi      # 0xcfc8
leaq 0x2dd1(%rip), %rsi      # 0x948d
callq 0x3220
jmp 0x66c3
jmp 0x689f
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x71f0
movq %rax, %rdi
leaq 0x2c36(%rip), %rsi      # 0x9316
callq 0x6ed0
movb %al, -0x182(%rbp)
jmp 0x66ed
movb -0x182(%rbp), %al
testb $0x1, %al
jne 0x66f9
jmp 0x6713
movq 0x68c8(%rip), %rdi      # 0xcfc8
leaq 0x2dfd(%rip), %rsi      # 0x9504
callq 0x3220
jmp 0x670e
jmp 0x689d
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x71f0
movq %rax, %rdi
leaq 0x2bf6(%rip), %rsi      # 0x9321
callq 0x6ed0
movb %al, -0x183(%rbp)
jmp 0x6738
movb -0x183(%rbp), %al
testb $0x1, %al
jne 0x6744
jmp 0x675e
movq 0x687d(%rip), %rdi      # 0xcfc8
leaq 0x2df6(%rip), %rsi      # 0x9548
callq 0x3220
jmp 0x6759
jmp 0x689b
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x71f0
movq %rax, %rdi
leaq 0x2bb2(%rip), %rsi      # 0x9328
callq 0x6ed0
movb %al, -0x184(%rbp)
jmp 0x6783
movb -0x184(%rbp), %al
testb $0x1, %al
jne 0x678f
jmp 0x67a9
movq 0x6832(%rip), %rdi      # 0xcfc8
leaq 0x2dfe(%rip), %rsi      # 0x959b
callq 0x3220
jmp 0x67a4
jmp 0x6899
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x71f0
movq %rax, %rdi
leaq 0x2bde(%rip), %rsi      # 0x939f
callq 0x6ed0
movb %al, -0x185(%rbp)
jmp 0x67ce
movb -0x185(%rbp), %al
testb $0x1, %al
jne 0x67da
jmp 0x67f4
movq 0x67e7(%rip), %rdi      # 0xcfc8
leaq 0x2de5(%rip), %rsi      # 0x95cd
callq 0x3220
jmp 0x67ef
jmp 0x6897
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x71f0
movq %rax, %rdi
leaq 0x2e38(%rip), %rsi      # 0x9644
callq 0x6ed0
movb %al, -0x186(%rbp)
jmp 0x6819
movb -0x186(%rbp), %al
testb $0x1, %al
jne 0x6825
jmp 0x683c
movq 0x679c(%rip), %rdi      # 0xcfc8
leaq 0x2e14(%rip), %rsi      # 0x9647
callq 0x3220
jmp 0x683a
jmp 0x6895
movq 0x6785(%rip), %rdi      # 0xcfc8
leaq 0x2874(%rip), %rsi      # 0x90be
callq 0x3220
movq %rax, -0x190(%rbp)
jmp 0x6858
leaq -0x48(%rbp), %rdi
movl $0x1, %esi
callq 0x71f0
movq -0x190(%rbp), %rdi
movq %rax, %rsi
callq 0x31f0
movq %rax, -0x198(%rbp)
jmp 0x687e
movq -0x198(%rbp), %rdi
leaq 0x3071(%rip), %rsi      # 0x98fd
callq 0x3220
jmp 0x6893
jmp 0x6895
jmp 0x6897
jmp 0x6899
jmp 0x689b
jmp 0x689d
jmp 0x689f
jmp 0x68b8
movq 0x6720(%rip), %rdi      # 0xcfc8
leaq 0x30b0(%rip), %rsi      # 0x995f
callq 0x3220
jmp 0x68b6
jmp 0x68b8
jmp 0x68ba
jmp 0x68d3
movq 0x6705(%rip), %rdi      # 0xcfc8
leaq 0x30b5(%rip), %rsi      # 0x997f
callq 0x3220
jmp 0x68d1
jmp 0x68d3
jmp 0x68d5
jmp 0x68d7
jmp 0x68d9
jmp 0x68db
jmp 0x68dd
jmp 0x68df
jmp 0x68e1
jmp 0x68e3
movq 0x66de(%rip), %rdi      # 0xcfc8
leaq 0x2a0e(%rip), %rsi      # 0x92ff
callq 0x3220
jmp 0x68f8
jmp 0x5f20
movl $0x0, -0x4(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x7230
leaq -0x30(%rbp), %rdi
callq 0x3170
movl -0x4(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x7230
leaq -0x30(%rbp), %rdi
callq 0x3170
movq -0x50(%rbp), %rdi
callq 0x3430
nopl (%rax)