// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x160, %rsp            # imm = 0x160
movq %rsi, %r14
movq %rdi, %rbx
movq %rsp, %r15
movq %r15, %rdi
callq 0x22f0
leaq 0x8ac(%rip), %rsi       # 0x6036
movq %r15, %rdi
callq 0x43fc
testb %al, %al
je 0x57a7
movq 0x18(%rbx), %rdi
xorl %r15d, %r15d
callq 0x42b4
jmp 0x5b05
leaq 0xa99(%rip), %rsi       # 0x6247
movq %rsp, %rdi
callq 0x43fc
pushq $-0x1
popq %r15
testb %al, %al
je 0x580d
movq (%rbx), %rax
movq 0x8(%rax), %rdx
incq %rdx
cmpq %rdx, 0x28(%r14)
jbe 0x5b05
addq $0x20, %r14
movq 0x18(%rbx), %rbx
leaq 0xc0(%rsp), %rdi
pushq $-0x1
popq %rcx
movq %r14, %rsi
callq 0x2250
leaq 0xc0(%rsp), %rsi
movq %rbx, %rdi
callq 0x2f22
movl %eax, %r15d
leaq 0xc0(%rsp), %rdi
jmp 0x5b00
leaq 0xa39(%rip), %rsi       # 0x624d
movq %rsp, %rdi
callq 0x43fc
testb %al, %al
jne 0x5837
leaq 0xa29(%rip), %rsi       # 0x6250
movq %rsp, %rdi
callq 0x43fc
testb %al, %al
je 0x5909
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x20(%r14), %r15
leaq 0x40(%rsp), %r12
leaq 0x20(%rsp), %r13
cmpq $0x0, 0x8(%r15)
movq 0x28(%rsp), %rax
je 0x589b
testq %rax, %rax
jne 0x58a4
movq (%r15), %rax
cmpb $0x2d, (%rax)
je 0x5895
cmpq $0x0, 0x48(%rsp)
movq %r13, %rdi
cmoveq %r12, %rdi
movq %r15, %rsi
callq 0x2140
addq $0x20, %r15
jmp 0x5867
testq %rax, %rax
je 0x5aed
leaq 0x20(%r14), %rdi
movq (%rbx), %rsi
xorl %edx, %edx
callq 0x2450
movq %rax, %r15
testq %rax, %rax
jne 0x59a9
movq (%rbx), %rax
movq 0x8(%rax), %rdx
incq %rdx
cmpq %rdx, 0x28(%r14)
jbe 0x5998
leaq 0xa0(%rsp), %rdi
leaq 0x40(%rsp), %rsi
pushq $-0x1
popq %rcx
callq 0x2250
leaq 0x40(%rsp), %rdi
leaq 0xa0(%rsp), %r12
movq %r12, %rsi
callq 0x22b0
movq %r12, %rdi
callq 0x2100
jmp 0x59a9
leaq 0x943(%rip), %rsi       # 0x6253
movq %rsp, %rdi
callq 0x43fc
testb %al, %al
je 0x596b
movq (%rbx), %rax
movq 0x8(%rax), %rdx
incq %rdx
cmpq %rdx, 0x28(%r14)
jbe 0x5b05
addq $0x20, %r14
movq 0x18(%rbx), %rbx
leaq 0x80(%rsp), %rdi
pushq $-0x1
popq %rcx
movq %r14, %rsi
callq 0x2250
leaq 0x80(%rsp), %rsi
movq %rbx, %rdi
callq 0x3a02
movl %eax, %r15d
leaq 0x80(%rsp), %rdi
jmp 0x5b00
leaq 0x8e4(%rip), %rsi       # 0x6256
movq %rsp, %rdi
callq 0x43fc
testb %al, %al
je 0x5b21
movq 0x18(%rbx), %rdi
xorl %r15d, %r15d
pushq $0x6
popq %rsi
xorl %edx, %edx
callq 0x405a
jmp 0x5b05
leaq 0x869(%rip), %rsi       # 0x6208
leaq 0x40(%rsp), %rdi
callq 0x2410
leaq 0x40(%r14), %rdi
movq (%rbx), %rsi
xorl %edx, %edx
callq 0x2450
movq %rax, %r12
testq %rax, %rax
jne 0x5a14
movq (%rbx), %rax
movq 0x8(%rax), %rdx
incq %rdx
cmpq %rdx, 0x48(%r14)
jae 0x59e2
leaq 0x832(%rip), %rsi       # 0x6208
leaq 0x20(%rsp), %rdi
callq 0x2410
jmp 0x5a14
leaq 0xa0(%rsp), %rdi
leaq 0x20(%rsp), %rsi
pushq $-0x1
popq %rcx
callq 0x2250
leaq 0x20(%rsp), %rdi
leaq 0xa0(%rsp), %r14
movq %r14, %rsi
callq 0x22b0
movq %r14, %rdi
callq 0x2100
leaq 0x832(%rip), %rsi       # 0x624d
movq %rsp, %rdi
callq 0x43fc
testb %al, %al
je 0x5a77
movq 0x18(%rbx), %r13
leaq 0x140(%rsp), %rbx
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x22f0
leaq 0x120(%rsp), %r14
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x22f0
xorl %r8d, %r8d
testq %r12, %r12
sete %r8b
xorl %ecx, %ecx
testq %r15, %r15
sete %cl
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3104
jmp 0x5ad8
leaq 0x7d2(%rip), %rsi       # 0x6250
movq %rsp, %rdi
callq 0x43fc
testb %al, %al
je 0x5aed
movq 0x18(%rbx), %r13
leaq 0x100(%rsp), %rbx
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x22f0
leaq 0xe0(%rsp), %r14
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x22f0
xorl %r8d, %r8d
testq %r12, %r12
sete %r8b
xorl %ecx, %ecx
testq %r15, %r15
sete %cl
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3b2a
movl %eax, %r15d
movq %r14, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x2100
jmp 0x5af1
pushq $-0x1
popq %r15
leaq 0x20(%rsp), %rdi
callq 0x2100
leaq 0x40(%rsp), %rdi
callq 0x2100
movq %rsp, %rdi
callq 0x2100
movl %r15d, %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
leaq 0x731(%rip), %rsi       # 0x6259
movq %rsp, %rdi
callq 0x43fc
testb %al, %al
je 0x5b7b
movq 0x28(%r14), %rax
testq %rax, %rax
je 0x5b7b
movq (%rbx), %rcx
movq 0x8(%rcx), %rdx
incq %rdx
cmpq %rdx, %rax
jbe 0x5b05
addq $0x20, %r14
movq 0x18(%rbx), %rbx
leaq 0x60(%rsp), %rdi
pushq $-0x1
popq %rcx
movq %r14, %rsi
callq 0x2250
leaq 0x60(%rsp), %rsi
movq %rbx, %rdi
callq 0x3c26
movl %eax, %r15d
leaq 0x60(%rsp), %rdi
jmp 0x5b00
movq 0x344e(%rip), %rdi      # 0x8fd0
movq %rsp, %rsi
callq 0x21b0
leaq 0x6ea(%rip), %rsi       # 0x627b
movq %rax, %rdi
callq 0x2210
movq %rax, %rdi
callq 0x2110
jmp 0x5b05
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
jmp 0x5c2a
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
jmp 0x5c2a
jmp 0x5c18
jmp 0x5c18
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x2100
jmp 0x5bd6
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
jmp 0x5bfd
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x2100
jmp 0x5bf5
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x2100
jmp 0x5c1b
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
jmp 0x5c2a
jmp 0x5c18
movq %rax, %rbx
jmp 0x5c2f
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2100
leaq 0x40(%rsp), %rdi
callq 0x2100
movq %rsp, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x23d0
nop