// File: /workspace/github_cpp_makefile_star2_O3/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 0x446d(%rip), %rbx      # 0x8fd0
leaq 0x169f(%rip), %rsi      # 0x6209
movl $0x91, %edx
movq %rbx, %rdi
callq 0x2240
callq 0x40e6
callq 0x2a47
callq 0x2c5c
leaq 0x170e(%rip), %rsi      # 0x629b
movl $0x83, %edx
movq %rbx, %rdi
callq 0x2240
leaq -0x150(%rbp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
leaq -0x40(%rbp), %rcx
movq %rax, 0x10(%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rcx)
leaq -0x160(%rbp), %r14
leaq -0x140(%rbp), %r12
movq 0x440f(%rip), %rcx      # 0x8fe0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %edx
movq 0x43f1(%rip), %rdi      # 0x8fe0
movq %r14, %rsi
callq 0x23d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x5280
movq %r14, %r15
movq -0x40(%rbp), %rbx
movq -0x38(%rbp), %r14
cmpq %rbx, %r14
je 0x4c3b
movq %rbx, %r13
movq (%r13), %rdi
addq $0x10, %r13
cmpq %r13, %rdi
je 0x4c2e
callq 0x21b0
addq $0x10, %r13
cmpq %r14, %r13
jne 0x4c1c
movq %rbx, -0x38(%rbp)
movq %r15, %r14
movq %r15, %rdi
movl $0x20, %esi
leaq -0x40(%rbp), %rdx
callq 0x4a57
cmpq $0x0, -0x158(%rbp)
je 0x5263
movq -0x40(%rbp), %rdi
leaq 0x16b7(%rip), %rsi      # 0x631f
callq 0x2090
testl %eax, %eax
je 0x4c8e
movq -0x40(%rbp), %rdi
leaq 0x1d5a(%rip), %rsi      # 0x69d6
callq 0x2090
testl %eax, %eax
je 0x4c8e
movq -0x40(%rbp), %rdi
jmp 0x4d27
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0x60, %rax
jne 0x4d27
leaq -0xf0(%rbp), %rax
movq %rax, -0x100(%rbp)
movq 0x20(%rdi), %rsi
movq 0x28(%rdi), %rdx
addq %rsi, %rdx
leaq -0x100(%rbp), %rdi
callq 0x55da
movq -0x40(%rbp), %rax
leaq -0x130(%rbp), %rcx
movq %rcx, -0x140(%rbp)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x55da
leaq -0x100(%rbp), %rdi
movq %r12, %rsi
callq 0x342a
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x4d14
callq 0x21b0
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
jmp 0x5001
leaq 0x15f8(%rip), %rsi      # 0x6326
callq 0x2090
testl %eax, %eax
je 0x4d51
movq -0x40(%rbp), %rdi
leaq 0x12e0(%rip), %rsi      # 0x6022
callq 0x2090
testl %eax, %eax
je 0x4d51
movq -0x40(%rbp), %rdi
jmp 0x4da6
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0x40, %rax
jne 0x4da6
leaq -0xd0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq 0x20(%rdi), %rsi
movq 0x28(%rdi), %rdx
addq %rsi, %rdx
leaq -0xe0(%rbp), %rdi
callq 0x55da
leaq -0xe0(%rbp), %rdi
callq 0x3826
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
jmp 0x5001
leaq 0x1580(%rip), %rsi      # 0x632d
callq 0x2090
testl %eax, %eax
je 0x4dd0
movq -0x40(%rbp), %rdi
leaq 0x1261(%rip), %rsi      # 0x6022
callq 0x2090
testl %eax, %eax
je 0x4dd0
movq -0x40(%rbp), %rdi
jmp 0x4e25
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0x40, %rax
jne 0x4e25
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq 0x20(%rdi), %rsi
movq 0x28(%rdi), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x55da
leaq -0xc0(%rbp), %rdi
callq 0x3e39
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
jmp 0x5001
leaq 0x1505(%rip), %rsi      # 0x6331
callq 0x2090
testl %eax, %eax
je 0x4e4f
movq -0x40(%rbp), %rdi
leaq 0x14f6(%rip), %rsi      # 0x6336
callq 0x2090
testl %eax, %eax
je 0x4e4f
movq -0x40(%rbp), %rdi
jmp 0x4e6a
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0x20, %rax
jne 0x4e6a
callq 0x3d6e
jmp 0x5263
leaq 0x14c7(%rip), %rsi      # 0x6338
callq 0x2090
testl %eax, %eax
je 0x4e94
movq -0x40(%rbp), %rdi
leaq 0x14b8(%rip), %rsi      # 0x633d
callq 0x2090
testl %eax, %eax
je 0x4e94
movq -0x40(%rbp), %rdi
jmp 0x4ea9
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0x20, %rax
je 0x52b5
leaq 0x14ca(%rip), %rsi      # 0x637a
callq 0x2090
testl %eax, %eax
je 0x4ed6
movq -0x40(%rbp), %rdi
leaq 0x14c0(%rip), %rsi      # 0x6384
callq 0x2090
testl %eax, %eax
je 0x4ed6
movq -0x40(%rbp), %rdi
jmp 0x5014
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
cmpq $0xa0, %rax
jne 0x5014
movl $0xf, %edx
movq 0x40d7(%rip), %rdi      # 0x8fd0
leaq 0x1486(%rip), %rsi      # 0x6386
callq 0x2240
movq -0x40(%rbp), %rax
leaq -0x90(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq -0xa0(%rbp), %rdi
callq 0x55da
movq -0x40(%rbp), %rax
leaq -0x70(%rbp), %rcx
movq %rcx, -0x80(%rbp)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
leaq -0x80(%rbp), %rdi
callq 0x55da
movq -0x40(%rbp), %rax
leaq -0x50(%rbp), %rcx
movq %rcx, -0x60(%rbp)
movq 0x60(%rax), %rsi
movq 0x68(%rax), %rdx
addq %rsi, %rdx
leaq -0x60(%rbp), %rdi
callq 0x55da
movq -0x40(%rbp), %rax
leaq -0x110(%rbp), %rcx
movq %rcx, -0x120(%rbp)
movq 0x80(%rax), %rsi
movq 0x88(%rax), %rdx
addq %rsi, %rdx
leaq -0x120(%rbp), %r15
movq %r15, %rdi
callq 0x55da
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x60(%rbp), %rdx
movq %r15, %rcx
callq 0x3979
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x4fcf
callq 0x21b0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x4fe1
callq 0x21b0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x4ff3
callq 0x21b0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x5263
callq 0x21b0
jmp 0x5263
leaq 0x137b(%rip), %rsi      # 0x6396
callq 0x2090
testl %eax, %eax
je 0x503e
movq -0x40(%rbp), %rdi
leaq 0x19d1(%rip), %rsi      # 0x6a00
callq 0x2090
testl %eax, %eax
je 0x503e
movq -0x40(%rbp), %rax
jmp 0x506a
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
movl $0xe, %r13d
movq 0x3f7a(%rip), %rdi      # 0x8fd0
leaq 0x1341(%rip), %rsi      # 0x639e
cmpq $0x80, %rcx
je 0x525b
movq %rax, %rdi
leaq 0x1339(%rip), %rsi      # 0x63ad
callq 0x2090
testl %eax, %eax
je 0x50a9
movq -0x40(%rbp), %rdi
leaq 0x132a(%rip), %rsi      # 0x63b2
callq 0x2090
movl $0x45, %r13d
movq 0x3f36(%rip), %rdi      # 0x8fd0
leaq 0x18ec(%rip), %rsi      # 0x698d
testl %eax, %eax
jne 0x525b
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq $0x1, %rax
je 0x51c9
cmpq $0x2, %rax
jne 0x51df
addq $0x20, %rdi
leaq 0x1248(%rip), %rsi      # 0x631f
callq 0x2090
movl $0x76, %r13d
testl %eax, %eax
je 0x51f5
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x122d(%rip), %rsi      # 0x6326
callq 0x2090
testl %eax, %eax
je 0x5205
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x121c(%rip), %rsi      # 0x6331
callq 0x2090
testl %eax, %eax
je 0x521b
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x1207(%rip), %rsi      # 0x6338
callq 0x2090
testl %eax, %eax
je 0x5231
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x1260(%rip), %rsi      # 0x63ad
callq 0x2090
movq 0x3e77(%rip), %rdi      # 0x8fd0
leaq 0x147b(%rip), %rsi      # 0x65db
testl %eax, %eax
je 0x525b
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x14db(%rip), %rsi      # 0x6652
callq 0x2090
testl %eax, %eax
je 0x5247
movl $0x1, %edx
movq 0x3e40(%rip), %rdi      # 0x8fd0
leaq 0xf37(%rip), %rsi       # 0x60ce
callq 0x2240
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
movq 0x3e21(%rip), %rdi      # 0x8fd0
callq 0x2240
movq %rax, %rdi
movl $0x61, %r13d
leaq 0x1747(%rip), %rsi      # 0x690b
jmp 0x525b
movl $0xe6, %r13d
movq 0x3dfa(%rip), %rdi      # 0x8fd0
leaq 0x11d7(%rip), %rsi      # 0x63b4
jmp 0x525b
movl $0x1f, %r13d
movq 0x3de4(%rip), %rdi      # 0x8fd0
leaq 0x177a(%rip), %rsi      # 0x696d
jmp 0x525b
movq 0x3dd4(%rip), %rdi      # 0x8fd0
leaq 0x1298(%rip), %rsi      # 0x649b
jmp 0x525b
movl $0x43, %r13d
movq 0x3dbe(%rip), %rdi      # 0x8fd0
leaq 0x12f9(%rip), %rsi      # 0x6512
jmp 0x525b
movl $0x52, %r13d
movq 0x3da8(%rip), %rdi      # 0x8fd0
leaq 0x1327(%rip), %rsi      # 0x6556
jmp 0x525b
movl $0x31, %r13d
movq 0x3d92(%rip), %rdi      # 0x8fd0
leaq 0x1364(%rip), %rsi      # 0x65a9
jmp 0x525b
movl $0x2b5, %r13d           # imm = 0x2B5
movq 0x3d7c(%rip), %rdi      # 0x8fd0
leaq 0x13fa(%rip), %rsi      # 0x6655
movq %r13, %rdx
callq 0x2240
movl $0xf, %edx
movq 0x3d61(%rip), %rdi      # 0x8fd0
leaq 0x1099(%rip), %rsi      # 0x630f
callq 0x2240
jmp 0x4bca
leaq -0x40(%rbp), %rdi
callq 0x5502
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x52a1
callq 0x21b0
xorl %eax, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3d14(%rip), %rdi      # 0x8fd0
leaq 0x107c(%rip), %rsi      # 0x633f
movl $0x1e, %edx
callq 0x2240
callq 0x2af5
leaq 0x172447(%rip), %rdi    # 0x177720
callq 0x4644
callq 0x2e03
movq 0x3ce6(%rip), %rdi      # 0x8fd0
leaq 0x106d(%rip), %rsi      # 0x635e
callq 0x21d0
xorl %edi, %edi
callq 0x2280
movq %rax, %rbx
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x5322
callq 0x21b0
jmp 0x5322
movq %rax, %rbx
jmp 0x5334
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x5334
callq 0x21b0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x534b
callq 0x21b0
jmp 0x534b
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
jmp 0x53b1
jmp 0x53bd
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
jmp 0x53b1
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
jmp 0x53b1
movq %rax, %rbx
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x53a3
callq 0x21b0
jmp 0x53a3
movq %rax, %rbx
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
cmpq %rax, %rdi
je 0x53c0
callq 0x21b0
jmp 0x53c0
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x5502
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x53e1
callq 0x21b0
movq %rbx, %rdi
callq 0x23a0
nop