// File: /workspace/github_cpp_makefile_star2_O3/hyp1231[P]FMSS/filesystem.cpp
// Function: FileSystem::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 FileSystem::CopyFile(string& S_filepath, string& D_filepath) {
    if(isOutside_path(S_filepath)) {        // souce is outside path
        if(isOutside_path(D_filepath)) {    // both outside path
            cout << "[Error] Cannot move an outside file to another outside place" << endl;
            return false;
        } else {    // move from outside to inside
            /*
                step 1: test if can open the outside file, and change file to string (attention length)
            */

            S_filepath = S_filepath.substr(1);

            ifstream ifile(S_filepath);
            if(!ifile) {    // cannot open
                cout << "[Error] Illegal outside path:" << S_filepath << endl;
                return false;
            }

            // store the data in outside file
            string file_data;

            if(!Outside_file2str(ifile, file_data)) {
                ifile.close();
                return false;
            }

            ifile.close();

            if(!str2Inside_file(file_data, D_filepath)) {
                return false;
            }
        }
    } else {        // souce is inside path
        if(isOutside_path(D_filepath)) {    // move from inside to outside
            D_filepath = D_filepath.substr(1);

            // convert inside file to string
            string file_data;
            if(!Inside_file2str(S_filepath, file_data)) {
                return false;
            }

            ofstream ofile(D_filepath);
            if(!ofile) {
                cout << "[Error] Cannot open file: " << D_filepath << endl;
                return false;
            }

            ofile << file_data;
            ofile.close();
        } else {    // both inside
            string filename;
            int dir_inodeNum = Analysis_path(S_filepath, filename);
            if(dir_inodeNum == -1) {
                return false;
            }
            int file_inodeNum = Get_file_inodeNum_from_dir(dir_inodeNum, filename);
            if(file_inodeNum == -1) {
                return false;
            }
            if(isDir(file_inodeNum)) {
                cout << "[Error] Source cannot be a directory" << endl;
                return false;
            }

            // convert inside file to string
            string file_data;
            if(!Inside_file2str(S_filepath, file_data)) {
                return false;
            }

            str2Inside_file(file_data, D_filepath);
        }
    }

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq (%rsi), %rax
cmpb $0x3a, (%rax)
movq (%rdx), %rax
movb (%rax), %al
jne 0x64c0
cmpb $0x3a, %al
jne 0x65bc
movq 0x6b50(%rip), %rbx      # 0xcfd0
leaq 0x325c(%rip), %rsi      # 0x96e3
movl $0x3c, %edx
movq %rbx, %rdi
callq 0x2240
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
jmp 0x6812
cmpb $0x3a, %al
jne 0x668a
leaq 0x20(%rsp), %r12
movl $0x1, %edx
movq %r12, %rdi
movq %rbx, %rsi
movq $-0x1, %rcx
callq 0x2220
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2260
movq (%r12), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x650a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
movq %rsp, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x6910
testb %al, %al
je 0x673a
leaq 0x20(%rsp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2390
movq 0x20(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x40(%rsp,%rax)
sete %bpl
je 0x6816
movq 0x6a67(%rip), %rdi      # 0xcfd0
leaq 0x31ce(%rip), %rsi      # 0x973e
movl $0x1a, %edx
callq 0x2240
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x6a48(%rip), %rdi      # 0xcfd0
callq 0x2240
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
jmp 0x6833
leaq 0x20(%rsp), %r12
movl $0x1, %edx
movq %r12, %rdi
movq %r15, %rsi
movq $-0x1, %rcx
callq 0x2220
movq %r15, %rdi
movq %r12, %rsi
callq 0x2260
movq (%r12), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x65fe
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x20(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movl $0x8, %edx
callq 0x2310
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x40(%rsp,%rax)
je 0x6741
movq 0x69a3(%rip), %rdi      # 0xcfd0
leaq 0x30ec(%rip), %rsi      # 0x9720
movl $0x1d, %edx
callq 0x2240
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq 0x6984(%rip), %rdi      # 0xcfd0
callq 0x2240
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
leaq 0x20(%rsp), %rdi
callq 0x2070
jmp 0x6812
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
movq %rsp, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4e5e
cmpl $-0x1, %eax
je 0x673a
movq %rsp, %rdx
movq %r14, %rdi
movl %eax, %esi
xorl %ecx, %ecx
callq 0x35dc
cmpl $-0x1, %eax
je 0x673a
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
movl %eax, %edx
callq 0x3d48
movsbl 0x20(%rsp), %eax
movsbl 0x21(%rsp), %ecx
shll $0x8, %ecx
addl %eax, %ecx
cmpl $0x1, %ecx
jne 0x6786
movq 0x68d5(%rip), %rbx      # 0xcfd0
leaq 0x3057(%rip), %rsi      # 0x9759
movl $0x24, %edx
movq %rbx, %rdi
callq 0x2240
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq 0x68a3(%rip), %rdi      # 0xcfd0
callq 0x2030
movq %rax, %rdi
callq 0x2120
xorl %ebp, %ebp
jmp 0x6865
leaq 0x10(%rsp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
leaq 0x20(%rsp), %rsi
movq %rsp, %rdx
movq %r14, %rdi
callq 0x5572
testb %al, %al
je 0x67e2
leaq 0x20(%rsp), %rdi
callq 0x2060
movq %rsp, %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x6000
movl %eax, %ebx
jmp 0x67ee
leaq 0x30(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x6910
movl %eax, %ebp
testb %al, %al
je 0x67c2
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x6000
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x6865
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x6865
leaq 0x20(%rsp), %rdi
callq 0x2060
xorl %ebx, %ebx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x6804
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x20(%rsp), %rdi
callq 0x2070
testb %bl, %bl
jne 0x6880
xorl %eax, %eax
jmp 0x6882
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0x20(%rsp), %rdi
callq 0x2240
leaq 0x20(%rsp), %rdi
callq 0x22c0
movq 0x678e(%rip), %rax      # 0xcfc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x28(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x20(%rsp,%rcx)
callq 0x21a0
leaq 0x118(%rsp), %rdi
callq 0x20b0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x687b
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
testb %bpl, %bpl
je 0x6812
movb $0x1, %al
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x68e3
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x68e3
jmp 0x68d1
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x68fe
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x68fe
jmp 0x68d1
jmp 0x68d1
movq %rax, %rbx
jmp 0x68e3
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x22e0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x6908
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x6908
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x2350