// File: emr4378[P]FAT-File-System/Shell.cpp
// Function: Shell::runFakeCommand(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*)
int Shell::runFakeCommand(string tokens[]) {
	int ret = -1;
	int i;
	string cmd = tokens[0];
	if (cmd == "ls") {
		fileSystem->printDirectoryTable();
		ret = 0;
	} else if (cmd == "touch") {
		if (tokens[1].size() > fakeFilePath->size() + 1) {
			ret = fileSystem->createFile(tokens[1].substr(fakeFilePath->size() + 1));
		}
	} else if (cmd == "cp" || cmd == "mv") {
		string sourceFile;
		string destFile;

		i = 1;
		while (!tokens[i].empty() && destFile.empty()) {
			if (tokens[i][0] != '-') {
				if (sourceFile.empty()) {
					sourceFile = tokens[i];
				} else {
					destFile = tokens[i];
				}
			}
			i++;
		}
		if (destFile.empty()) {
			ret = -1;
		} else {
			bool sourceInFake = false;
			bool destInFake = false;
			if (tokens[1].find(*fakeFilePath) == 0) {
				if (tokens[1].size() > fakeFilePath->size() + 1) {
					sourceFile = sourceFile.substr(fakeFilePath->size() + 1);
				} else {
					sourceFile = "";
				}
				sourceInFake = true;
			}

			if (tokens[2].find(*fakeFilePath) == 0) {
				if (tokens[2].size() >= fakeFilePath->size() + 1) {
					destFile = destFile.substr(fakeFilePath->size() + 1);
					destInFake = true;
				} else {
					destFile = "";
				}
				destInFake = true;
			}
		
			if (cmd == "cp") {
				ret = fileSystem->copyFile(sourceFile, destFile, 
											sourceInFake, destInFake);
			} else if (cmd == "mv") {
				ret = fileSystem->moveFile(sourceFile, destFile, 
											sourceInFake, destInFake);
			}
		}
	} else if (cmd == "rm") {
		if (tokens[1].size() > fakeFilePath->size() + 1) {
			ret = fileSystem->removeFile(tokens[1].substr(fakeFilePath->size() + 1));
		}
	} else if (cmd == "df") {
		fileSystem->printInfo(6, NULL);
		ret = 0;
	} else if (cmd == "cat" && !tokens[1].empty()) {
		if (tokens[1].size() > fakeFilePath->size() + 1) {
			ret = fileSystem->printFile(tokens[1].substr(fakeFilePath->size() + 1));
		}
	} else {
		cout << cmd << " command not supported by fake filesystem." << endl;
		ret = -1;
	}

	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rsi
leaq -0x38(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x3120
movq -0x1c0(%rbp), %rdi
leaq 0x168f(%rip), %rsi      # 0xc036
callq 0x6c90
movb %al, -0x1b1(%rbp)
jmp 0xa9b4
movb -0x1b1(%rbp), %al
testb $0x1, %al
jne 0xa9c0
jmp 0xa9ef
movq -0x1c8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x6890
jmp 0xa9d2
movl $0x0, -0x14(%rbp)
jmp 0xb2e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xb308
leaq 0x1851(%rip), %rsi      # 0xc247
leaq -0x38(%rbp), %rdi
callq 0x6c90
movb %al, -0x1c9(%rbp)
jmp 0xaa07
movb -0x1c9(%rbp), %al
testb $0x1, %al
jne 0xaa16
jmp 0xaae6
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x1c8(%rbp), %rax
movq %rcx, -0x1d8(%rbp)
movq (%rax), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x1d8(%rbp), %rax
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0xaae1
movq -0x1c8(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rax), %rax
movq %rax, -0x1e8(%rbp)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x1e0(%rbp)
callq 0x31a0
movq -0x1e0(%rbp), %rsi
movq %rax, %rdx
incq %rdx
leaq -0x68(%rbp), %rdi
movq $-0x1, %rcx
callq 0x32d0
jmp 0xaa9b
movq -0x1e8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x47a0
movl %eax, -0x1ec(%rbp)
jmp 0xaab3
movl -0x1ec(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3180
jmp 0xaae1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3180
jmp 0xb308
jmp 0xb2e5
leaq 0x1760(%rip), %rsi      # 0xc24d
leaq -0x38(%rbp), %rdi
callq 0x6c90
movb %al, -0x1ed(%rbp)
jmp 0xaafe
movb -0x1ed(%rbp), %al
testb $0x1, %al
jne 0xab31
jmp 0xab0a
leaq 0x173f(%rip), %rsi      # 0xc250
leaq -0x38(%rbp), %rdi
callq 0x6c90
movb %al, -0x1ee(%rbp)
jmp 0xab22
movb -0x1ee(%rbp), %al
testb $0x1, %al
jne 0xab31
jmp 0xb02c
leaq -0x88(%rbp), %rdi
callq 0x3430
leaq -0xa8(%rbp), %rdi
callq 0x3430
movl $0x1, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x18(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
callq 0x3510
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x1ef(%rbp)
jne 0xab85
leaq -0xa8(%rbp), %rdi
callq 0x3510
movb %al, -0x1ef(%rbp)
movb -0x1ef(%rbp), %al
testb $0x1, %al
jne 0xab94
jmp 0xac35
movq -0x10(%rbp), %rdi
movslq -0x18(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x35c0
movq %rax, -0x1f8(%rbp)
jmp 0xabb5
movq -0x1f8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
je 0xac27
leaq -0x88(%rbp), %rdi
callq 0x3510
testb $0x1, %al
jne 0xabd6
jmp 0xac06
movq -0x10(%rbp), %rsi
movslq -0x18(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rsi
leaq -0x88(%rbp), %rdi
callq 0x3050
jmp 0xabf3
jmp 0xac25
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xb00f
movq -0x10(%rbp), %rsi
movslq -0x18(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rsi
leaq -0xa8(%rbp), %rdi
callq 0x3050
jmp 0xac23
jmp 0xac25
jmp 0xac27
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xab50
leaq -0xa8(%rbp), %rdi
callq 0x3510
testb $0x1, %al
jne 0xac47
jmp 0xac53
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xaff2
movq -0x1c8(%rbp), %rax
movb $0x0, -0xa9(%rbp)
movb $0x0, -0xaa(%rbp)
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movq (%rax), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x35d0
cmpq $0x0, %rax
jne 0xad2f
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x1c8(%rbp), %rax
movq %rcx, -0x200(%rbp)
movq (%rax), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x200(%rbp), %rax
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0xad11
movq -0x1c8(%rbp), %rax
movq (%rax), %rdi
callq 0x31a0
movq %rax, %rdx
incq %rdx
leaq -0xd0(%rbp), %rdi
leaq -0x88(%rbp), %rsi
movq $-0x1, %rcx
callq 0x32d0
jmp 0xacf0
leaq -0x88(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x3390
leaq -0xd0(%rbp), %rdi
callq 0x3180
jmp 0xad28
leaq 0x14f0(%rip), %rsi      # 0xc208
leaq -0x88(%rbp), %rdi
callq 0x3420
jmp 0xad26
jmp 0xad28
movb $0x1, -0xa9(%rbp)
movq -0x1c8(%rbp), %rax
movq -0x10(%rbp), %rdi
addq $0x40, %rdi
movq (%rax), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x35d0
cmpq $0x0, %rax
jne 0xae04
movq -0x10(%rbp), %rdi
addq $0x40, %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x1c8(%rbp), %rax
movq %rcx, -0x208(%rbp)
movq (%rax), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x208(%rbp), %rax
addq $0x1, %rcx
cmpq %rcx, %rax
jb 0xade6
movq -0x1c8(%rbp), %rax
movq (%rax), %rdi
callq 0x31a0
movq %rax, %rdx
incq %rdx
leaq -0xf0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
movq $-0x1, %rcx
callq 0x32d0
jmp 0xadbe
leaq -0xa8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x3390
leaq -0xf0(%rbp), %rdi
callq 0x3180
movb $0x1, -0xaa(%rbp)
jmp 0xadfd
leaq 0x141b(%rip), %rsi      # 0xc208
leaq -0xa8(%rbp), %rdi
callq 0x3420
jmp 0xadfb
jmp 0xadfd
movb $0x1, -0xaa(%rbp)
leaq 0x1442(%rip), %rsi      # 0xc24d
leaq -0x38(%rbp), %rdi
callq 0x6c90
movb %al, -0x209(%rbp)
jmp 0xae1c
movb -0x209(%rbp), %al
testb $0x1, %al
jne 0xae2b
jmp 0xaefc
movq -0x1c8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x218(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3120
jmp 0xae52
leaq -0x130(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3120
jmp 0xae67
movq -0x218(%rbp), %rdi
movzbl -0xaa(%rbp), %r8d
movzbl -0xa9(%rbp), %ecx
andl $0x1, %ecx
andl $0x1, %r8d
leaq -0x110(%rbp), %rsi
leaq -0x130(%rbp), %rdx
callq 0x4ae0
movl %eax, -0x21c(%rbp)
jmp 0xae9f
movl -0x21c(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x3180
leaq -0x110(%rbp), %rdi
callq 0x3180
jmp 0xaff0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xaeeb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x3180
leaq -0x110(%rbp), %rdi
callq 0x3180
jmp 0xb00f
leaq 0x134d(%rip), %rsi      # 0xc250
leaq -0x38(%rbp), %rdi
callq 0x6c90
movb %al, -0x21d(%rbp)
jmp 0xaf14
movb -0x21d(%rbp), %al
testb $0x1, %al
jne 0xaf23
jmp 0xafee
movq -0x1c8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x228(%rbp)
leaq -0x150(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x3120
jmp 0xaf4a
leaq -0x170(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x3120
jmp 0xaf5f
movq -0x228(%rbp), %rdi
movzbl -0xaa(%rbp), %r8d
movzbl -0xa9(%rbp), %ecx
andl $0x1, %ecx
andl $0x1, %r8d
leaq -0x150(%rbp), %rsi
leaq -0x170(%rbp), %rdx
callq 0x5ca0
movl %eax, -0x22c(%rbp)
jmp 0xaf97
movl -0x22c(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x3180
leaq -0x150(%rbp), %rdi
callq 0x3180
jmp 0xafee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xafe0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x170(%rbp), %rdi
callq 0x3180
leaq -0x150(%rbp), %rdi
callq 0x3180
jmp 0xb00f
jmp 0xaff0
jmp 0xaff2
leaq -0xa8(%rbp), %rdi
callq 0x3180
leaq -0x88(%rbp), %rdi
callq 0x3180
jmp 0xb2e3
leaq -0xa8(%rbp), %rdi
callq 0x3180
leaq -0x88(%rbp), %rdi
callq 0x3180
jmp 0xb308
leaq 0x1220(%rip), %rsi      # 0xc253
leaq -0x38(%rbp), %rdi
callq 0x6c90
movb %al, -0x22d(%rbp)
jmp 0xb044
movb -0x22d(%rbp), %al
testb $0x1, %al
jne 0xb053
jmp 0xb12f
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x1c8(%rbp), %rax
movq %rcx, -0x238(%rbp)
movq (%rax), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x238(%rbp), %rax
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0xb12a
movq -0x1c8(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rax), %rax
movq %rax, -0x248(%rbp)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x240(%rbp)
callq 0x31a0
movq -0x240(%rbp), %rsi
movq %rax, %rdx
incq %rdx
leaq -0x190(%rbp), %rdi
movq $-0x1, %rcx
callq 0x32d0
jmp 0xb0db
movq -0x248(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x5a70
movl %eax, -0x24c(%rbp)
jmp 0xb0f6
movl -0x24c(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x3180
jmp 0xb12a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x3180
jmp 0xb308
jmp 0xb2e1
leaq 0x1120(%rip), %rsi      # 0xc256
leaq -0x38(%rbp), %rdi
callq 0x6c90
movb %al, -0x24d(%rbp)
jmp 0xb147
movb -0x24d(%rbp), %al
testb $0x1, %al
jne 0xb153
jmp 0xb17a
movq -0x1c8(%rbp), %rax
movq 0x18(%rax), %rdi
xorl %eax, %eax
movl %eax, %edx
movl $0x6, %esi
callq 0x6460
jmp 0xb16e
movl $0x0, -0x14(%rbp)
jmp 0xb2df
leaq 0x10d8(%rip), %rsi      # 0xc259
leaq -0x38(%rbp), %rdi
callq 0x6c90
movb %al, -0x24e(%rbp)
jmp 0xb192
movb -0x24e(%rbp), %al
testb $0x1, %al
jne 0xb1a1
jmp 0xb28c
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x3510
testb $0x1, %al
jne 0xb28c
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x1c8(%rbp), %rax
movq %rcx, -0x258(%rbp)
movq (%rax), %rdi
callq 0x31a0
movq %rax, %rcx
movq -0x258(%rbp), %rax
addq $0x1, %rcx
cmpq %rcx, %rax
jbe 0xb28a
movq -0x1c8(%rbp), %rax
movq (%rax), %rdi
movq 0x18(%rax), %rax
movq %rax, -0x268(%rbp)
movq -0x10(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x260(%rbp)
callq 0x31a0
movq -0x260(%rbp), %rsi
movq %rax, %rdx
incq %rdx
leaq -0x1b0(%rbp), %rdi
movq $-0x1, %rcx
callq 0x32d0
jmp 0xb23e
movq -0x268(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x5e50
movl %eax, -0x26c(%rbp)
jmp 0xb259
movl -0x26c(%rbp), %eax
movl %eax, -0x14(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x3180
jmp 0xb28a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x3180
jmp 0xb308
jmp 0xb2dd
movq 0x4d3d(%rip), %rdi      # 0xffd0
leaq -0x38(%rbp), %rsi
callq 0x3220
movq %rax, -0x278(%rbp)
jmp 0xb2a5
movq -0x278(%rbp), %rdi
leaq 0xfc8(%rip), %rsi       # 0xc27b
callq 0x3290
movq %rax, -0x280(%rbp)
jmp 0xb2c1
movq -0x280(%rbp), %rdi
movq 0x4cf1(%rip), %rsi      # 0xffc0
callq 0x32e0
jmp 0xb2d6
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xb2df
jmp 0xb2e1
jmp 0xb2e3
jmp 0xb2e5
jmp 0xb2e7
movl -0x14(%rbp), %eax
movl %eax, -0x284(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3180
movl -0x284(%rbp), %eax
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x3180
movq -0x40(%rbp), %rdi
callq 0x3530
nopw (%rax,%rax)