// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, %r15
movq %rdi, %r14
leaq 0x18(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%rsi), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0x4e42
leaq 0x16a0(%rip), %rsi      # 0x8036
movq %rbx, %rdi
callq 0x2070
testl %eax, %eax
je 0x6a7b
leaq 0x189a(%rip), %rsi      # 0x8247
leaq 0x8(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x6b8d
leaq 0x1887(%rip), %rsi      # 0x824d
leaq 0x8(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x6a8b
leaq 0x1871(%rip), %rsi      # 0x8250
leaq 0x8(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x6a8b
leaq 0x185b(%rip), %rsi      # 0x8253
leaq 0x8(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x6bf9
leaq 0x1845(%rip), %rsi      # 0x8256
leaq 0x8(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x6c65
leaq 0x182f(%rip), %rsi      # 0x8259
leaq 0x8(%rsp), %rdi
callq 0x2070
testl %eax, %eax
je 0x6f0f
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq 0x4583(%rip), %rdi      # 0xafd0
callq 0x2240
movq %rax, %r14
leaq 0x181f(%rip), %rsi      # 0x827b
movl $0x2a, %edx
movq %rax, %rdi
callq 0x2240
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %r14, %rdi
callq 0x20c0
jmp 0x6ee4
movq 0x18(%r14), %rdi
xorl %ebx, %ebx
callq 0x4cd4
jmp 0x6ee4
leaq 0x58(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x38(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq %rax, 0x28(%r15)
je 0x6eac
leaq 0x20(%r15), %r12
leaq 0x48(%rsp), %rbp
leaq 0x28(%rsp), %rbx
movq %r12, %r13
cmpq $0x0, 0x30(%rsp)
jne 0x6b08
movq (%r13), %rax
cmpb $0x2d, (%rax)
je 0x6af1
cmpq $0x0, 0x50(%rsp)
movq %rbx, %rdi
cmoveq %rbp, %rdi
movq %r13, %rsi
callq 0x20f0
cmpq $0x0, 0x28(%r13)
leaq 0x20(%r13), %r13
jne 0x6acb
cmpq $0x0, 0x30(%rsp)
je 0x6c7c
movq (%r14), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rcx
movq %r12, %rdi
xorl %edx, %edx
callq 0x23a0
movq %rax, %r12
testq %rax, %rax
leaq 0x18(%rsp), %rbp
jne 0x6c9c
movq (%r14), %rax
movq 0x8(%rax), %rdx
incq %rdx
cmpq %rdx, 0x28(%r15)
jbe 0x6c8b
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rsi
movq $-0x1, %rcx
callq 0x2210
leaq 0x48(%rsp), %rdi
leaq 0x68(%rsp), %r13
movq %r13, %rsi
callq 0x2280
movq (%r13), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x6c9c
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x6c9c
movq (%r14), %rax
movq 0x8(%rax), %rdx
incq %rdx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq %rdx, 0x28(%r15)
jbe 0x6ee4
addq $0x20, %r15
movq 0x18(%r14), %rbx
leaq 0x148(%rsp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x2210
leaq 0x148(%rsp), %rsi
movq %rbx, %rdi
callq 0x31a8
movl %eax, %ebx
leaq 0x158(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6ee4
movq 0x158(%rsp), %rsi
jmp 0x6edc
movq (%r14), %rax
movq 0x8(%rax), %rdx
incq %rdx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq %rdx, 0x28(%r15)
jbe 0x6ee4
addq $0x20, %r15
movq 0x18(%r14), %rbx
leaq 0xe8(%rsp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x2210
leaq 0xe8(%rsp), %rsi
movq %rbx, %rdi
callq 0x40c6
movl %eax, %ebx
leaq 0xf8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6ee4
movq 0xf8(%rsp), %rsi
jmp 0x6edc
movq 0x18(%r14), %rdi
xorl %ebx, %ebx
movl $0x6, %esi
xorl %edx, %edx
callq 0x4960
jmp 0x6ee4
leaq 0x18(%rsp), %rbp
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x6eac
leaq 0x1576(%rip), %rsi      # 0x8208
leaq 0x48(%rsp), %rdi
callq 0x22c0
leaq 0x40(%r15), %rdi
movq (%r14), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rcx
xorl %edx, %edx
callq 0x23a0
movq %rax, %r13
testq %rax, %rax
jne 0x6d1e
movq (%r14), %rax
movq 0x8(%rax), %rdx
incq %rdx
cmpq %rdx, 0x48(%r15)
jae 0x6cdc
leaq 0x1538(%rip), %rsi      # 0x8208
leaq 0x28(%rsp), %rdi
callq 0x22c0
jmp 0x6d1e
leaq 0x68(%rsp), %rdi
leaq 0x28(%rsp), %rsi
movq $-0x1, %rcx
callq 0x2210
leaq 0x28(%rsp), %rdi
leaq 0x68(%rsp), %r15
movq %r15, %rsi
callq 0x2280
movq (%r15), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x6d1e
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x21f0
leaq 0x1528(%rip), %rsi      # 0x824d
leaq 0x8(%rsp), %rdi
callq 0x2070
testl %eax, %eax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
je 0x6dfb
leaq 0x150d(%rip), %rsi      # 0x8250
leaq 0x8(%rsp), %rdi
callq 0x2070
testl %eax, %eax
jne 0x6eac
movq 0x18(%r14), %rbx
leaq 0x118(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
leaq 0x108(%rsp), %rdi
callq 0x4e42
leaq 0x98(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x4e42
xorl %r8d, %r8d
testq %r13, %r13
sete %r8b
xorl %ecx, %ecx
testq %r12, %r12
sete %cl
leaq 0x108(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rbx, %rdi
callq 0x421a
movl %eax, %ebx
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x6dee
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x108(%rsp), %rdi
jmp 0x6e9c
movq 0x18(%r14), %rbx
leaq 0x138(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
leaq 0x128(%rsp), %rdi
callq 0x4e42
leaq 0xb8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdx
addq %rsi, %rdx
leaq 0xa8(%rsp), %rdi
callq 0x4e42
xorl %r8d, %r8d
testq %r13, %r13
sete %r8b
xorl %ecx, %ecx
testq %r12, %r12
sete %cl
leaq 0x128(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
movq %rbx, %rdi
callq 0x3416
movl %eax, %ebx
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x6e94
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x128(%rsp), %rdi
cmpq %r14, %rdi
je 0x6eac
movq (%r14), %rsi
incq %rsi
callq 0x21f0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x6ec8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x6ee4
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x6efb
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21f0
movl %ebx, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%r15), %rax
testq %rax, %rax
je 0x6a3c
movq (%r14), %rcx
movq 0x8(%rcx), %rdx
incq %rdx
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpq %rdx, %rax
jbe 0x6ee4
addq $0x20, %r15
movq 0x18(%r14), %rbx
leaq 0xc8(%rsp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x2210
leaq 0xc8(%rsp), %rsi
movq %rbx, %rdi
callq 0x43b8
movl %eax, %ebx
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6ee4
movq 0xd8(%rsp), %rsi
jmp 0x6edc
movq %rax, %rbx
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x70bb
movq 0xd8(%rsp), %rsi
jmp 0x70b3
jmp 0x7080
jmp 0x7080
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x6fd7
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x6fd7
movq %rax, %rbx
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
je 0x7083
movq 0x118(%rsp), %rsi
jmp 0x7051
movq %rax, %rbx
leaq 0xf8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x70bb
movq 0xf8(%rsp), %rsi
jmp 0x70b3
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x703c
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x703c
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r14, %rdi
je 0x7083
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x7083
movq %rax, %rbx
leaq 0x158(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x70bb
movq 0x158(%rsp), %rsi
jmp 0x70b3
jmp 0x7080
movq %rax, %rbx
jmp 0x70bb
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x709f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x70bb
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x70d7
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x23b0
nop