// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movl %r8d, %ebp
movl %ecx, %r12d
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq %rsi, %rdi
movq %rdx, %rsi
callq 0x43c9
testb %al, %al
je 0x314c
pushq $-0x3
popq %rbx
jmp 0x32bf
movq 0x8(%r14), %rax
movq (%r15), %rcx
cmpb $0x2f, -0x1(%rcx,%rax)
je 0x3163
movq 0x8(%r15), %rax
testq %rax, %rax
jne 0x31a4
pushq $0x2f
popq %rsi
pushq $-0x1
popq %r13
movq %r14, %rdi
movq %r13, %rdx
callq 0x2440
leaq 0x1(%rax), %rdx
leaq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %r13, %rcx
callq 0x2250
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2430
leaq 0x8(%rsp), %rdi
callq 0x2100
movq 0x8(%r15), %rax
movq (%r14), %rcx
cmpb $0x2f, -0x1(%rcx,%rax)
je 0x31b5
cmpq $0x0, 0x8(%r14)
jne 0x31f2
pushq $0x2f
popq %rsi
pushq $-0x1
popq %r13
movq %r15, %rdi
movq %r13, %rdx
callq 0x2440
leaq 0x1(%rax), %rdx
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rcx
callq 0x2250
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x2430
leaq 0x8(%rsp), %rdi
callq 0x2100
movl %r12d, %eax
xorb $0x1, %al
movl %eax, %ecx
orb %bpl, %cl
je 0x3213
xorb $0x1, %bpl
orb %bpl, %r12b
je 0x3249
orb %bpl, %al
je 0x327f
pushq $-0x1
jmp 0x3146
leaq 0xe8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x22f0
leaq 0xc8(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x22f0
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x335e
jmp 0x32ad
leaq 0xa8(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x22f0
leaq 0x88(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x22f0
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x3552
jmp 0x32ad
leaq 0x68(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x22f0
leaq 0x48(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x22f0
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x37d4
movl %eax, %ebx
movq %r15, %rdi
callq 0x2100
movq %r12, %rdi
callq 0x2100
leaq 0x28(%rsp), %rdi
callq 0x2100
movl %ebx, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x2100
jmp 0x32ef
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x3340
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x2100
jmp 0x330b
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x3340
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x2100
jmp 0x332a
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x3340
jmp 0x3338
jmp 0x3349
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x2100
jmp 0x334c
jmp 0x3349
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x23d0