// File: emr4378[P]FAT-File-System/FileSys.cpp
// Function: FileSys::copyFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, bool)
int FileSys::copyFile(string source, string dest, 
						bool sourceInFileSys, bool destInFileSys) {
	//struct dirent dirp;
	//DIR *dir;
	string fileName;
	int i;
	int ret = -2;
	if (source == dest) {
		ret = -3;
	} else {
		ret = -1;
		/*
			//apparently this doesn't work in Solaris; there is no d_type in the
			//dirent struct. AWESOME.

			if (source[source.size()-1] == '*') {
			source.erase(source.end()-1);
			cout << "Copy all " << endl;

			if (!sourceInFileSys) {
				dir = opendir(source.c_str());
				if (dir != NULL) {
					while ((dirp = readdir(dir)) != NULL) {
						if (dirp->d_type == 8 && dirp->d_name != "") {
							fileName = source;
							fileName.append(dirp->d_name);
							copyFile(fileName, dest, false, destInFileSys);
						}
					}
				}
			} else {
				int dirTableSize = getDirectoryFileCount(directoryTable);
				for (i = 0; i < dirTableSize; i++) {
					fileName = dest;
					fileName.append(directoryTable[i].name);
					copyFile(directoryTable[i].name, fileName, true, destInFileSys);
				}
			}
			//copy all
		} else {*/

		if (source[dest.size()-1] == '/' || source.empty()) {
			//directory source
			source.append(dest.substr(dest.find_last_of('/') + 1));
		}
		if (dest[source.size()-1] == '/' || dest.empty()) {
			//directory destination
			dest.append(source.substr(source.find_last_of('/') + 1));
		}
		if (!destInFileSys && sourceInFileSys) {
			//internal (fake/the FileSys) to external (real)
			ret = copyFileInToExt(source, dest);
		} else if (!sourceInFileSys && destInFileSys) {
			//external (real) to internal (fake/the FileSys)
			ret = copyFileExtToIn(source, dest);
		} else if (sourceInFileSys && destInFileSys) {
			//internal to internal
			ret = copyFileInternally(source, dest);
		}
	}
	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdx, -0x160(%rbp)
movq %rsi, -0x168(%rbp)
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %cl
movb %cl, -0x19(%rbp)
andb $0x1, %al
movb %al, -0x1a(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3430
movq -0x168(%rbp), %rdi
movq -0x160(%rbp), %rsi
movl $0xfffffffe, -0x48(%rbp) # imm = 0xFFFFFFFE
callq 0x6bd0
testb $0x1, %al
jne 0x4b47
jmp 0x4b53
movl $0xfffffffd, -0x48(%rbp) # imm = 0xFFFFFFFD
jmp 0x4f2e
movq -0x160(%rbp), %rdi
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
callq 0x31a0
movq -0x168(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x35c0
movq %rax, -0x178(%rbp)
jmp 0x4b81
movq -0x178(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x4ba5
movq -0x168(%rbp), %rdi
callq 0x3510
testb $0x1, %al
jne 0x4ba5
jmp 0x4c2b
movq -0x160(%rbp), %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
movq %rdx, -0x180(%rbp)
callq 0x3580
movq -0x160(%rbp), %rsi
movq -0x180(%rbp), %rcx
movq %rax, %rdx
incq %rdx
leaq -0x78(%rbp), %rdi
callq 0x32d0
jmp 0x4be3
movq -0x168(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x35a0
jmp 0x4bf5
leaq -0x78(%rbp), %rdi
callq 0x3180
jmp 0x4c2b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4f4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3180
jmp 0x4f4f
movq -0x168(%rbp), %rdi
callq 0x31a0
movq -0x160(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x35c0
movq %rax, -0x188(%rbp)
jmp 0x4c52
movq -0x188(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
je 0x4c76
movq -0x160(%rbp), %rdi
callq 0x3510
testb $0x1, %al
jne 0x4c76
jmp 0x4cf7
movq -0x168(%rbp), %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
movq %rdx, -0x190(%rbp)
callq 0x3580
movq -0x168(%rbp), %rsi
movq -0x190(%rbp), %rcx
movq %rax, %rdx
incq %rdx
leaq -0x98(%rbp), %rdi
callq 0x32d0
jmp 0x4cb7
movq -0x160(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x35a0
jmp 0x4ccc
leaq -0x98(%rbp), %rdi
callq 0x3180
jmp 0x4cf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3180
jmp 0x4f4f
testb $0x1, -0x1a(%rbp)
jne 0x4db4
testb $0x1, -0x19(%rbp)
je 0x4db4
movq -0x168(%rbp), %rsi
leaq -0xb8(%rbp), %rdi
callq 0x3120
jmp 0x4d20
movq -0x160(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x3120
jmp 0x4d35
movq -0x170(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x4f70
movl %eax, -0x194(%rbp)
jmp 0x4d57
movl -0x194(%rbp), %eax
movl %eax, -0x48(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3180
leaq -0xb8(%rbp), %rdi
callq 0x3180
jmp 0x4f2c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4da3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3180
leaq -0xb8(%rbp), %rdi
callq 0x3180
jmp 0x4f4f
testb $0x1, -0x19(%rbp)
jne 0x4e71
testb $0x1, -0x1a(%rbp)
je 0x4e71
movq -0x168(%rbp), %rsi
leaq -0xf8(%rbp), %rdi
callq 0x3120
jmp 0x4ddd
movq -0x160(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x3120
jmp 0x4df2
movq -0x170(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
leaq -0x118(%rbp), %rdx
callq 0x5270
movl %eax, -0x198(%rbp)
jmp 0x4e14
movl -0x198(%rbp), %eax
movl %eax, -0x48(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x3180
leaq -0xf8(%rbp), %rdi
callq 0x3180
jmp 0x4f2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4e60
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x3180
leaq -0xf8(%rbp), %rdi
callq 0x3180
jmp 0x4f4f
testb $0x1, -0x19(%rbp)
je 0x4f28
testb $0x1, -0x1a(%rbp)
je 0x4f28
movq -0x168(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0x3120
jmp 0x4e9a
movq -0x160(%rbp), %rsi
leaq -0x158(%rbp), %rdi
callq 0x3120
jmp 0x4eaf
movq -0x170(%rbp), %rdi
leaq -0x138(%rbp), %rsi
leaq -0x158(%rbp), %rdx
callq 0x5660
movl %eax, -0x19c(%rbp)
jmp 0x4ed1
movl -0x19c(%rbp), %eax
movl %eax, -0x48(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x3180
leaq -0x138(%rbp), %rdi
callq 0x3180
jmp 0x4f28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x4f1a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x3180
leaq -0x138(%rbp), %rdi
callq 0x3180
jmp 0x4f4f
jmp 0x4f2a
jmp 0x4f2c
jmp 0x4f2e
movl -0x48(%rbp), %eax
movl %eax, -0x1a0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x3180
movl -0x1a0(%rbp), %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x3180
movq -0x50(%rbp), %rdi
callq 0x3530
nopw %cs:(%rax,%rax)