// File: /workspace/github_cpp_makefile_star2_O1/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 0x44fd(%rip), %rbx      # 0x8fd0
leaq 0x172f(%rip), %rsi      # 0x6209
movl $0x91, %edx
movq %rbx, %rdi
callq 0x2240
callq 0x4057
callq 0x2a46
callq 0x2c0e
leaq 0x179e(%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 0x449f(%rip), %rcx      # 0x8fe0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %edx
movq 0x4481(%rip), %rdi      # 0x8fe0
movq %r14, %rsi
callq 0x23d0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x51d4
movq %r14, %r15
movq -0x40(%rbp), %rbx
movq -0x38(%rbp), %r14
cmpq %rbx, %r14
je 0x4bab
movq %rbx, %r13
movq (%r13), %rdi
addq $0x10, %r13
cmpq %r13, %rdi
je 0x4b9e
callq 0x21b0
addq $0x10, %r13
cmpq %r14, %r13
jne 0x4b8c
movq %rbx, -0x38(%rbp)
movq %r15, %r14
movq %r15, %rdi
movl $0x20, %esi
leaq -0x40(%rbp), %rdx
callq 0x49c7
cmpq $0x0, -0x158(%rbp)
je 0x51b7
movq -0x40(%rbp), %rdi
leaq 0x1747(%rip), %rsi      # 0x631f
callq 0x2090
testl %eax, %eax
je 0x4bf9
movq -0x40(%rbp), %rdi
leaq 0x1dea(%rip), %rsi      # 0x69d6
callq 0x2090
testl %eax, %eax
jne 0x4c92
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
cmpq $0x60, %rcx
jne 0x4c92
leaq -0xf0(%rbp), %rcx
movq %rcx, -0x100(%rbp)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq -0x100(%rbp), %rdi
callq 0x5524
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 0x5524
leaq -0x100(%rbp), %rdi
movq %r12, %rsi
callq 0x33dc
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x4c7f
callq 0x21b0
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
jmp 0x4f5a
movq -0x40(%rbp), %rdi
leaq 0x1689(%rip), %rsi      # 0x6326
callq 0x2090
testl %eax, %eax
je 0x4cba
movq -0x40(%rbp), %rdi
leaq 0x1371(%rip), %rsi      # 0x6022
callq 0x2090
testl %eax, %eax
jne 0x4d0f
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
cmpq $0x40, %rcx
jne 0x4d0f
leaq -0xd0(%rbp), %rcx
movq %rcx, -0xe0(%rbp)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq -0xe0(%rbp), %rdi
callq 0x5524
leaq -0xe0(%rbp), %rdi
callq 0x37d4
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
jmp 0x4f5a
movq -0x40(%rbp), %rdi
leaq 0x1613(%rip), %rsi      # 0x632d
callq 0x2090
testl %eax, %eax
je 0x4d37
movq -0x40(%rbp), %rdi
leaq 0x12f4(%rip), %rsi      # 0x6022
callq 0x2090
testl %eax, %eax
jne 0x4d8c
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
subq %rax, %rcx
cmpq $0x40, %rcx
jne 0x4d8c
leaq -0xb0(%rbp), %rcx
movq %rcx, -0xc0(%rbp)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq -0xc0(%rbp), %rdi
callq 0x5524
leaq -0xc0(%rbp), %rdi
callq 0x3daa
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
jmp 0x4f5a
movq -0x40(%rbp), %rdi
leaq 0x159a(%rip), %rsi      # 0x6331
callq 0x2090
testl %eax, %eax
je 0x4db4
movq -0x40(%rbp), %rdi
leaq 0x158b(%rip), %rsi      # 0x6336
callq 0x2090
testl %eax, %eax
jne 0x4dcc
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
cmpq $0x20, %rax
jne 0x4dcc
callq 0x3cdf
jmp 0x51b7
movq -0x40(%rbp), %rdi
leaq 0x1561(%rip), %rsi      # 0x6338
callq 0x2090
testl %eax, %eax
je 0x4df4
movq -0x40(%rbp), %rdi
leaq 0x1552(%rip), %rsi      # 0x633d
callq 0x2090
testl %eax, %eax
jne 0x4e06
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
cmpq $0x20, %rax
je 0x5209
movq -0x40(%rbp), %rdi
leaq 0x1569(%rip), %rsi      # 0x637a
callq 0x2090
testl %eax, %eax
je 0x4e32
movq -0x40(%rbp), %rdi
leaq 0x155f(%rip), %rsi      # 0x6384
callq 0x2090
testl %eax, %eax
jne 0x4f6d
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
cmpq $0xa0, %rax
jne 0x4f6d
movl $0xf, %edx
movq 0x417e(%rip), %rdi      # 0x8fd0
leaq 0x152d(%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 0x5524
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 0x5524
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 0x5524
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 0x5524
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x60(%rbp), %rdx
movq %r15, %rcx
callq 0x38f7
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x4f28
callq 0x21b0
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x4f3a
callq 0x21b0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x4f4c
callq 0x21b0
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x51b7
callq 0x21b0
jmp 0x51b7
movq -0x40(%rbp), %rdi
leaq 0x141e(%rip), %rsi      # 0x6396
callq 0x2090
testl %eax, %eax
je 0x4f95
movq -0x40(%rbp), %rdi
leaq 0x1a74(%rip), %rsi      # 0x6a00
callq 0x2090
testl %eax, %eax
jne 0x4fbd
movq -0x38(%rbp), %rax
subq -0x40(%rbp), %rax
movl $0xe, %r13d
movq 0x4026(%rip), %rdi      # 0x8fd0
leaq 0x13ed(%rip), %rsi      # 0x639e
cmpq $0x80, %rax
je 0x51af
movq -0x40(%rbp), %rdi
leaq 0x13e5(%rip), %rsi      # 0x63ad
callq 0x2090
testl %eax, %eax
je 0x4ffd
movq -0x40(%rbp), %rdi
leaq 0x13d6(%rip), %rsi      # 0x63b2
callq 0x2090
movl $0x45, %r13d
movq 0x3fe2(%rip), %rdi      # 0x8fd0
leaq 0x1998(%rip), %rsi      # 0x698d
testl %eax, %eax
jne 0x51af
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rax
subq %rdi, %rax
sarq $0x5, %rax
cmpq $0x1, %rax
je 0x511d
cmpq $0x2, %rax
jne 0x5133
addq $0x20, %rdi
leaq 0x12f4(%rip), %rsi      # 0x631f
callq 0x2090
movl $0x76, %r13d
testl %eax, %eax
je 0x5149
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x12d9(%rip), %rsi      # 0x6326
callq 0x2090
testl %eax, %eax
je 0x5159
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x12c8(%rip), %rsi      # 0x6331
callq 0x2090
testl %eax, %eax
je 0x516f
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x12b3(%rip), %rsi      # 0x6338
callq 0x2090
testl %eax, %eax
je 0x5185
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x130c(%rip), %rsi      # 0x63ad
callq 0x2090
movq 0x3f23(%rip), %rdi      # 0x8fd0
leaq 0x1527(%rip), %rsi      # 0x65db
testl %eax, %eax
je 0x51af
movq -0x40(%rbp), %rdi
addq $0x20, %rdi
leaq 0x1587(%rip), %rsi      # 0x6652
callq 0x2090
testl %eax, %eax
je 0x519b
movl $0x1, %edx
movq 0x3eec(%rip), %rdi      # 0x8fd0
leaq 0xfe3(%rip), %rsi       # 0x60ce
callq 0x2240
movq -0x40(%rbp), %rax
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
movq 0x3ecd(%rip), %rdi      # 0x8fd0
callq 0x2240
movq %rax, %rdi
movl $0x61, %r13d
leaq 0x17f3(%rip), %rsi      # 0x690b
jmp 0x51af
movl $0xe6, %r13d
movq 0x3ea6(%rip), %rdi      # 0x8fd0
leaq 0x1283(%rip), %rsi      # 0x63b4
jmp 0x51af
movl $0x1f, %r13d
movq 0x3e90(%rip), %rdi      # 0x8fd0
leaq 0x1826(%rip), %rsi      # 0x696d
jmp 0x51af
movq 0x3e80(%rip), %rdi      # 0x8fd0
leaq 0x1344(%rip), %rsi      # 0x649b
jmp 0x51af
movl $0x43, %r13d
movq 0x3e6a(%rip), %rdi      # 0x8fd0
leaq 0x13a5(%rip), %rsi      # 0x6512
jmp 0x51af
movl $0x52, %r13d
movq 0x3e54(%rip), %rdi      # 0x8fd0
leaq 0x13d3(%rip), %rsi      # 0x6556
jmp 0x51af
movl $0x31, %r13d
movq 0x3e3e(%rip), %rdi      # 0x8fd0
leaq 0x1410(%rip), %rsi      # 0x65a9
jmp 0x51af
movl $0x2b5, %r13d           # imm = 0x2B5
movq 0x3e28(%rip), %rdi      # 0x8fd0
leaq 0x14a6(%rip), %rsi      # 0x6655
movq %r13, %rdx
callq 0x2240
movl $0xf, %edx
movq 0x3e0d(%rip), %rdi      # 0x8fd0
leaq 0x1145(%rip), %rsi      # 0x630f
callq 0x2240
jmp 0x4b3a
leaq -0x40(%rbp), %rdi
callq 0x5456
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x51f5
callq 0x21b0
xorl %eax, %eax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x3dc0(%rip), %rdi      # 0x8fd0
leaq 0x1128(%rip), %rsi      # 0x633f
movl $0x1e, %edx
callq 0x2240
callq 0x2af0
leaq 0x1724f3(%rip), %rdi    # 0x177720
callq 0x45b4
callq 0x2db5
movq 0x3d92(%rip), %rdi      # 0x8fd0
leaq 0x1119(%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 0x5276
callq 0x21b0
jmp 0x5276
movq %rax, %rbx
jmp 0x5288
movq %rax, %rbx
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x5288
callq 0x21b0
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x529f
callq 0x21b0
jmp 0x529f
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
jmp 0x5305
jmp 0x5311
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
jmp 0x5305
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
leaq -0xd0(%rbp), %rax
jmp 0x5305
movq %rax, %rbx
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x52f7
callq 0x21b0
jmp 0x52f7
movq %rax, %rbx
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
cmpq %rax, %rdi
je 0x5314
callq 0x21b0
jmp 0x5314
movq %rax, %rbx
leaq -0x40(%rbp), %rdi
callq 0x5456
movq -0x160(%rbp), %rdi
leaq -0x150(%rbp), %rax
cmpq %rax, %rdi
je 0x5335
callq 0x21b0
movq %rbx, %rdi
callq 0x23a0
nop