// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x230, %rsp            # imm = 0x230
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq (%rsi), %rax
cmpb $0x3a, (%rax)
movq (%rdx), %rax
movb (%rax), %al
jne 0x4c27
cmpb $0x3a, %al
jne 0x4cd3
movq 0x63c2(%rip), %rdi      # 0xafd0
leaq 0x2a3d(%rip), %rsi      # 0x7652
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
jmp 0x4eeb
cmpb $0x3a, %al
jne 0x4d4d
leaq 0x28(%rsp), %r12
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2200
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2240
movq %r12, %rdi
callq 0x20e0
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4f5c
testb %al, %al
je 0x4dc3
leaq 0x28(%rsp), %rdi
pushq $0x10
popq %rdx
movq %rbx, %rsi
callq 0x2360
movq 0x28(%rsp), %rax
movq -0x18(%rax), %rax
movl 0x48(%rsp,%rax), %ebp
testb $0x5, %bpl
je 0x4ea0
movq 0x6321(%rip), %rdi      # 0xafd0
leaq 0x29f7(%rip), %rsi      # 0x76ad
callq 0x21d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
jmp 0x4eb9
leaq 0x28(%rsp), %r12
pushq $0x1
popq %rdx
pushq $-0x1
popq %rcx
movq %r12, %rdi
movq %r15, %rsi
callq 0x2200
movq %r15, %rdi
movq %r12, %rsi
callq 0x2240
movq %r12, %rdi
callq 0x20e0
leaq 0x28(%rsp), %r12
pushq $0x8
popq %rdx
movq %r12, %rdi
movq %r15, %rsi
callq 0x2310
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x48(%rsp,%rax)
je 0x4dcd
movq 0x62a7(%rip), %rdi      # 0xafd0
leaq 0x295f(%rip), %rsi      # 0x768f
callq 0x21d0
movq %rax, %rdi
movq %r15, %rsi
callq 0x21b0
movq %rax, %rdi
callq 0x20f0
jmp 0x4e94
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x28(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x3c86
cmpl $-0x1, %eax
je 0x4ee1
leaq 0x28(%rsp), %rdx
movq %r14, %rdi
movl %eax, %esi
xorl %ecx, %ecx
callq 0x2ff2
cmpl $-0x1, %eax
je 0x4ee1
movq %r14, %rdi
movl %eax, %esi
callq 0x3d98
testb %al, %al
je 0x4e35
movq 0x6226(%rip), %rdi      # 0xafd0
leaq 0x2917(%rip), %rsi      # 0x76c8
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
jmp 0x4ee1
leaq 0x8(%rsp), %rdi
jmp 0x4ee6
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x28(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x4168
testb %al, %al
je 0x4e80
leaq 0x28(%rsp), %rdi
callq 0x2060
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x48cc
movl %eax, %ebx
leaq 0x8(%rsp), %rdi
callq 0x20e0
leaq 0x28(%rsp), %rdi
callq 0x2070
testb %bl, %bl
jne 0x4ed3
jmp 0x4eeb
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x4f5c
testb %al, %al
je 0x4ed7
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x48cc
leaq 0x8(%rsp), %rdi
callq 0x20e0
leaq 0x28(%rsp), %rdi
callq 0x20e0
jmp 0x4ed3
leaq 0x28(%rsp), %rdi
callq 0x2060
leaq 0x8(%rsp), %rdi
callq 0x20e0
leaq 0x28(%rsp), %rdi
callq 0x2070
jmp 0x4eeb
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x21b0
leaq 0x28(%rsp), %rdi
callq 0x22c0
leaq 0x28(%rsp), %rdi
callq 0x22e0
leaq 0x8(%rsp), %rdi
callq 0x20e0
testb $0x5, %bpl
jne 0x4eeb
movb $0x1, %al
jmp 0x4eed
leaq 0x8(%rsp), %rdi
callq 0x20e0
leaq 0x28(%rsp), %rdi
callq 0x20e0
xorl %eax, %eax
addq $0x230, %rsp            # imm = 0x230
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x20e0
jmp 0x4f3b
jmp 0x4f1f
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x20e0
jmp 0x4f4a
jmp 0x4f38
movq %rax, %rbx
jmp 0x4f31
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x22e0
leaq 0x8(%rsp), %rdi
jmp 0x4f40
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x20e0
jmp 0x4f54
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x2340