// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movl %r8d, %ebp
movl %ecx, 0x14(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
leaq 0xa8(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x8(%rsi), %rbx
movq 0x8(%rdx), %r12
cmpq %r12, %rbx
jne 0x34d6
movl $0xfffffffd, %r13d      # imm = 0xFFFFFFFD
testq %rbx, %rbx
je 0x3768
movq (%r14), %rsi
movq (%r15), %rdi
movq %rbx, %rdx
callq 0x2200
testl %eax, %eax
je 0x3768
testq %rbx, %rbx
je 0x34e6
movq (%r15), %rax
cmpb $0x2f, -0x1(%rax,%r12)
jne 0x353f
movq %r14, %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
callq 0x2420
leaq 0x1(%rax), %rdx
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
movq $-0x1, %rcx
callq 0x2210
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r15, %rdi
callq 0x2080
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x353f
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x8(%r15), %rax
movq (%r14), %rcx
cmpb $0x2f, -0x1(%rcx,%rax)
je 0x3554
cmpq $0x0, 0x8(%r14)
jne 0x35ad
movq %r15, %rdi
movl $0x2f, %esi
movq $-0x1, %rdx
callq 0x2420
leaq 0x1(%rax), %rdx
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x2210
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
movq %r14, %rdi
callq 0x2080
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x35ad
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21f0
movl 0x14(%rsp), %edx
movl %edx, %eax
xorb $0x1, %al
movl %eax, %ecx
orb %bpl, %cl
je 0x365b
xorb $0x1, %bpl
orb %bpl, %dl
je 0x36dd
orb %bpl, %al
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jne 0x3768
leaq 0xc8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x4e76
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rdi
callq 0x4e76
leaq 0xb8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x3e1a
movl %eax, %r13d
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x364e
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0xb8(%rsp), %rdi
jmp 0x3757
leaq 0x108(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0xf8(%rsp), %rdi
callq 0x4e76
leaq 0x88(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x4e76
leaq 0xf8(%rsp), %rsi
leaq 0x78(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x38a4
movl %eax, %r13d
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x36d3
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0xf8(%rsp), %rdi
jmp 0x3757
leaq 0xe8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0xd8(%rsp), %rdi
callq 0x4e76
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x4e76
leaq 0xd8(%rsp), %rsi
leaq 0x58(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x3b16
movl %eax, %r13d
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x374f
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0xd8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3768
movq (%r12), %rsi
incq %rsi
callq 0x21f0
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x378d
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x21f0
movl %r13d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x37c1
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x37c1
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3877
movq 0xc8(%rsp), %rsi
jmp 0x3868
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x37fe
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x37fe
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3877
movq 0xe8(%rsp), %rsi
jmp 0x3868
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x3837
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x3837
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3877
movq 0x108(%rsp), %rsi
jmp 0x3868
jmp 0x3852
jmp 0x3874
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3877
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x3877
jmp 0x3874
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x389c
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x23b0