// File: /workspace/github_cpp_makefile_star2_O1/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 0x5f3a
cmpb $0x3a, %al
jne 0x6036
movq 0x70d6(%rip), %rbx      # 0xcfd0
leaq 0x3751(%rip), %rsi      # 0x9652
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 0x628c
cmpb $0x3a, %al
jne 0x6104
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 0x5f84
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 0x639c
testb %al, %al
je 0x61b9
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 0x6290
movq 0x6fed(%rip), %rdi      # 0xcfd0
leaq 0x36c3(%rip), %rsi      # 0x96ad
movl $0x1a, %edx
callq 0x2240
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x6fce(%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 0x62ad
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 0x6078
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 0x61c0
movq 0x6f29(%rip), %rdi      # 0xcfd0
leaq 0x35e1(%rip), %rsi      # 0x968f
movl $0x1d, %edx
callq 0x2240
movq (%r15), %rsi
movq 0x8(%r15), %rdx
movq 0x6f0a(%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 0x628c
leaq 0x30(%rsp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x48f6
cmpl $-0x1, %eax
je 0x619f
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
movl %eax, %esi
xorl %ecx, %ecx
callq 0x35de
cmpl $-0x1, %eax
je 0x619f
movq %r14, %rdi
movl %eax, %esi
callq 0x4a8a
testb %al, %al
je 0x6205
movq 0x6e70(%rip), %rbx      # 0xcfd0
leaq 0x3561(%rip), %rsi      # 0x96c8
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 0x6e3e(%rip), %rdi      # 0xcfd0
callq 0x2030
movq %rax, %rdi
callq 0x2120
xorl %ebp, %ebp
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x62f5
movq 0x30(%rsp), %rsi
jmp 0x62ed
xorl %ebp, %ebp
jmp 0x62df
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 0x500a
testb %al, %al
je 0x625c
leaq 0x20(%rsp), %rdi
callq 0x2060
movq %rsp, %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x5aa4
movl %eax, %ebx
jmp 0x6268
leaq 0x10(%rsp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
movb $0x0, (%r13)
movq %rsp, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x639c
movl %eax, %ebp
testb %al, %al
je 0x623d
movq %rsp, %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x5aa4
movq (%rsp), %rdi
cmpq %r13, %rdi
je 0x61a1
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x61a1
leaq 0x20(%rsp), %rdi
callq 0x2060
xorl %ebx, %ebx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x627e
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x20(%rsp), %rdi
callq 0x2070
testb %bl, %bl
jne 0x62fa
xorl %eax, %eax
jmp 0x62fc
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
leaq 0x20(%rsp), %rdi
callq 0x2240
leaq 0x20(%rsp), %rdi
callq 0x22c0
movq 0x6d14(%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 0x62f5
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
testb %bpl, %bpl
je 0x628c
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 (%rsp), %rdi
cmpq %r13, %rdi
je 0x6350
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x6350
jmp 0x6348
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x6389
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x6389
jmp 0x634d
movq %rax, %rbx
jmp 0x636e
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r12, %rdi
je 0x6393
movq 0x30(%rsp), %rsi
jmp 0x637c
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x22e0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x6393
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x6393
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x2350
nop