// File: /workspace/github_cpp_makefile_star2_O3/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
movq %rdx, %r14
movq %rsi, %r15
leaq 0xa8(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq 0x8(%rsi), %rbx
movq 0x8(%rdx), %r13
cmpq %r13, %rbx
jne 0x3487
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
testq %rbx, %rbx
je 0x3727
movl %r8d, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movq %rdi, 0x10(%rsp)
movq (%r14), %rsi
movq (%r15), %r12
movq %r12, %rdi
movq %rbx, %rdx
callq 0x2200
testl %eax, %eax
jne 0x3498
jmp 0x3727
movl %r8d, 0x8(%rsp)
movl %ecx, 0xc(%rsp)
movq %rdi, 0x10(%rsp)
movq (%r15), %r12
testq %rbx, %rbx
je 0x34a5
cmpb $0x2f, -0x1(%r12,%r13)
jne 0x3502
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 0x34fe
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x8(%r15), %rbx
movq (%r14), %rax
cmpb $0x2f, -0x1(%rax,%rbx)
movl 0xc(%rsp), %ebx
movl 0x8(%rsp), %ebp
je 0x351b
cmpq $0x0, 0x8(%r14)
jne 0x3574
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 0x3574
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21f0
movl %ebx, %eax
xorb $0x1, %al
movl %eax, %ecx
orb %bpl, %cl
je 0x361c
xorb $0x1, %bpl
orb %bpl, %bl
je 0x369d
orb %bpl, %al
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jne 0x3727
leaq 0xc8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x4e42
leaq 0x48(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rdi
callq 0x4e42
leaq 0xb8(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq 0x10(%rsp), %rdi
callq 0x3dd0
movl %eax, %ebp
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x360f
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0xb8(%rsp), %rdi
jmp 0x3716
leaq 0x108(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0xf8(%rsp), %rdi
callq 0x4e42
leaq 0x88(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x78(%rsp), %rdi
callq 0x4e42
leaq 0xf8(%rsp), %rsi
leaq 0x78(%rsp), %rdx
movq 0x10(%rsp), %rdi
callq 0x3862
movl %eax, %ebp
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x3693
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0xf8(%rsp), %rdi
jmp 0x3716
leaq 0xe8(%rsp), %r12
movq %r12, -0x10(%r12)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0xd8(%rsp), %rdi
callq 0x4e42
leaq 0x68(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x4e42
leaq 0xd8(%rsp), %rsi
leaq 0x58(%rsp), %rdx
movq 0x10(%rsp), %rdi
callq 0x3ad2
movl %eax, %ebp
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x370e
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0xd8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3727
movq (%r12), %rsi
incq %rsi
callq 0x21f0
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x374c
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x21f0
movl %ebp, %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 0x377f
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x377f
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3835
movq 0xc8(%rsp), %rsi
jmp 0x3826
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r15, %rdi
je 0x37bc
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x37bc
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3835
movq 0xe8(%rsp), %rsi
jmp 0x3826
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x37f5
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x37f5
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r12, %rdi
je 0x3835
movq 0x108(%rsp), %rsi
jmp 0x3826
jmp 0x3810
jmp 0x3832
movq %rax, %rbx
leaq 0x28(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3835
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x3835
jmp 0x3832
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x385a
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x23b0