// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq 0x418a(%rip), %rbx      # 0x7fc8
leaq 0x13c4(%rip), %rsi      # 0x5209
movq %rbx, %rdi
callq 0x21e0
callq 0x3856
callq 0x2844
callq 0x29f8
leaq 0x1438(%rip), %rsi      # 0x529b
movq %rbx, %rdi
callq 0x21e0
leaq -0x50(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %r14
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
leaq -0x60(%rbp), %r12
leaq -0x140(%rbp), %rbx
movq 0x4143(%rip), %rdi      # 0x7fe0
movq %r12, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x438e
movq %r14, %rdi
callq 0x478a
movq %r12, %rdi
pushq $0x20
popq %rsi
movq %r14, %rdx
callq 0x3d6d
cmpq $0x0, -0x58(%rbp)
je 0x4017
movq -0x40(%rbp), %rdi
leaq 0x143c(%rip), %rsi      # 0x531f
callq 0x45e5
testb %al, %al
jne 0x3f00
movq -0x40(%rbp), %rdi
leaq 0x1ae1(%rip), %rsi      # 0x59d8
callq 0x45e5
testb %al, %al
je 0x3f57
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rsi, %rax
cmpq $0x60, %rax
jne 0x3f5b
addq $0x20, %rsi
leaq -0x120(%rbp), %rdi
callq 0x22c0
movq -0x40(%rbp), %rsi
addq $0x40, %rsi
leaq -0x160(%rbp), %r15
movq %r15, %rdi
callq 0x22c0
leaq -0x120(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x2ef5
movq %r15, %rdi
callq 0x20f0
jmp 0x400f
movq -0x40(%rbp), %rsi
movq %rsi, %rdi
leaq 0x13c1(%rip), %rsi      # 0x5326
callq 0x45e5
testb %al, %al
jne 0x3f82
movq -0x40(%rbp), %rdi
leaq 0x10a9(%rip), %rsi      # 0x5022
callq 0x45e5
testb %al, %al
je 0x3fb4
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x3fb8
addq $0x20, %rsi
leaq -0x100(%rbp), %rdi
callq 0x22c0
leaq -0x100(%rbp), %r13
movq %r13, %rdi
callq 0x3230
jmp 0x400f
movq -0x40(%rbp), %rsi
movq %rsi, %rdi
leaq 0x136b(%rip), %rsi      # 0x532d
callq 0x45e5
testb %al, %al
jne 0x3fdf
movq -0x40(%rbp), %rdi
leaq 0x104c(%rip), %rsi      # 0x5022
callq 0x45e5
testb %al, %al
je 0x402f
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rsi, %rax
cmpq $0x40, %rax
jne 0x4033
addq $0x20, %rsi
leaq -0xe0(%rbp), %rdi
callq 0x22c0
leaq -0xe0(%rbp), %r13
movq %r13, %rdi
callq 0x3643
movq %r13, %rdi
callq 0x20f0
movq 0x3faa(%rip), %rdi      # 0x7fc8
leaq 0x12ea(%rip), %rsi      # 0x530f
callq 0x21e0
jmp 0x3e96
movq -0x40(%rbp), %rsi
movq %rsi, %rdi
leaq 0x12f4(%rip), %rsi      # 0x5331
callq 0x45e5
testb %al, %al
jne 0x405a
movq -0x40(%rbp), %rdi
leaq 0x12e5(%rip), %rsi      # 0x5336
callq 0x45e5
testb %al, %al
je 0x4072
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0x20, %rax
jne 0x4076
callq 0x359b
jmp 0x4017
movq -0x40(%rbp), %rdi
leaq 0x12bb(%rip), %rsi      # 0x5338
callq 0x45e5
testb %al, %al
jne 0x409a
movq -0x40(%rbp), %rdi
leaq 0x12ac(%rip), %rsi      # 0x533d
callq 0x45e5
testb %al, %al
je 0x40b0
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0x20, %rax
jne 0x40b4
jmp 0x43b4
movq -0x40(%rbp), %rdi
leaq 0x12bf(%rip), %rsi      # 0x537a
callq 0x45e5
testb %al, %al
jne 0x40dc
movq -0x40(%rbp), %rdi
leaq 0x12b5(%rip), %rsi      # 0x5384
callq 0x45e5
testb %al, %al
je 0x4197
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0xa0, %rax
jne 0x419b
movq 0x3ece(%rip), %rdi      # 0x7fc8
leaq 0x1285(%rip), %rsi      # 0x5386
callq 0x21e0
movq -0x40(%rbp), %rsi
addq $0x20, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x22c0
movq -0x40(%rbp), %rsi
addq $0x40, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x22c0
movq %r12, %r14
movq -0x40(%rbp), %rsi
addq $0x60, %rsi
leaq -0x80(%rbp), %rdi
callq 0x22c0
movq -0x40(%rbp), %rsi
subq $-0x80, %rsi
movq %rbx, %rdi
callq 0x22c0
movq %rbx, %r12
leaq -0xc0(%rbp), %r13
movq %r13, %rdi
leaq -0xa0(%rbp), %r15
movq %r15, %rsi
leaq -0x80(%rbp), %rbx
movq %rbx, %rdx
movq %r12, %rcx
callq 0x3309
movq %r12, %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x20f0
movq %r12, %rbx
movq %r14, %r12
leaq -0x40(%rbp), %r14
jmp 0x3f4a
movq -0x40(%rbp), %rdi
leaq 0x11f4(%rip), %rsi      # 0x5396
callq 0x45e5
testb %al, %al
jne 0x41bf
movq -0x40(%rbp), %rdi
leaq 0x11e8(%rip), %rsi      # 0x539e
callq 0x45e5
testb %al, %al
je 0x41e6
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
movq 0x3df7(%rip), %rdi      # 0x7fc8
leaq 0x11c8(%rip), %rsi      # 0x53a0
cmpq $0x80, %rcx
jne 0x41ea
jmp 0x4384
movq -0x40(%rbp), %rax
movq %rax, %rdi
leaq 0x11bb(%rip), %rsi      # 0x53af
callq 0x45e5
testb %al, %al
jne 0x4223
movq -0x40(%rbp), %rdi
leaq 0x11ac(%rip), %rsi      # 0x53b4
callq 0x45e5
movq 0x3db4(%rip), %rdi      # 0x7fc8
leaq 0x1774(%rip), %rsi      # 0x598f
testb %al, %al
je 0x4384
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
movq 0x3d8f(%rip), %rdi      # 0x7fc8
leaq 0x1176(%rip), %rsi      # 0x53b6
cmpq $0x1, %rcx
je 0x4384
cmpq $0x2, %rcx
jne 0x4376
addq $0x20, %rax
movq %rax, %rdi
leaq 0x10bd(%rip), %rsi      # 0x531f
callq 0x45e5
movq 0x3d5a(%rip), %rdi      # 0x7fc8
leaq 0x1228(%rip), %rsi      # 0x549d
testb %al, %al
jne 0x4384
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x109a(%rip), %rsi      # 0x5326
callq 0x45e5
movq 0x3d30(%rip), %rdi      # 0x7fc8
leaq 0x1275(%rip), %rsi      # 0x5514
testb %al, %al
jne 0x4384
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x107b(%rip), %rsi      # 0x5331
callq 0x45e5
movq 0x3d06(%rip), %rdi      # 0x7fc8
leaq 0x128f(%rip), %rsi      # 0x5558
testb %al, %al
jne 0x4384
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x1058(%rip), %rsi      # 0x5338
callq 0x45e5
movq 0x3cdc(%rip), %rdi      # 0x7fc8
leaq 0x12b8(%rip), %rsi      # 0x55ab
testb %al, %al
jne 0x4384
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x10a5(%rip), %rsi      # 0x53af
callq 0x45e5
movq 0x3cb2(%rip), %rdi      # 0x7fc8
leaq 0x12c0(%rip), %rsi      # 0x55dd
testb %al, %al
jne 0x4384
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x1324(%rip), %rsi      # 0x5654
callq 0x45e5
movq 0x3c8c(%rip), %rdi      # 0x7fc8
leaq 0x1314(%rip), %rsi      # 0x5657
testb %al, %al
jne 0x4384
movq 0x3c7a(%rip), %rdi      # 0x7fc8
leaq 0xd79(%rip), %rsi       # 0x50ce
callq 0x21e0
movq -0x40(%rbp), %rsi
addq $0x20, %rsi
movq %rax, %rdi
callq 0x21c0
movq %rax, %rdi
leaq 0x1599(%rip), %rsi      # 0x590d
jmp 0x4384
movq 0x3c4b(%rip), %rdi      # 0x7fc8
leaq 0x15eb(%rip), %rsi      # 0x596f
callq 0x21e0
jmp 0x4017
leaq -0x40(%rbp), %rdi
callq 0x4798
leaq -0x60(%rbp), %rdi
callq 0x20f0
xorl %eax, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3c0d(%rip), %rdi      # 0x7fc8
leaq 0xf7d(%rip), %rsi       # 0x533f
callq 0x21e0
callq 0x28de
leaq 0x17234d(%rip), %rdi    # 0x176720
callq 0x3b92
callq 0x2b3e
movq 0x3be4(%rip), %rdi      # 0x7fc8
leaq 0xf73(%rip), %rsi       # 0x535e
callq 0x21e0
xorl %edi, %edi
callq 0x2260
movq %rax, %rbx
jmp 0x441e
movq %rax, %rbx
jmp 0x4415
movq %rax, %rbx
jmp 0x442a
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x20f0
leaq -0x80(%rbp), %rdi
callq 0x20f0
leaq -0xa0(%rbp), %rdi
callq 0x20f0
leaq -0xc0(%rbp), %rdi
jmp 0x4468
jmp 0x446f
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
jmp 0x4468
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
jmp 0x4468
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
callq 0x20f0
jmp 0x4461
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x20f0
jmp 0x4472
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x4798
leaq -0x60(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2390