// File: /workspace/github_cpp_makefile_star2_O3/hyp1231[P]FMSS/filesystem.cpp
// Function: FileSystem::CreateFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
bool FileSystem::CreateFile(const string &filepath) {
    /* 
        step 1: find the right directory
    */

    vector<string> path;
    string filename;
    int dir_inodeNum;
    if(!Decomposition_path(filepath, path)) {
        cout << "[Error] Illegal path!" << endl;
        return false;
    }

    if(path.empty()) {
        cout << "[Error] Empty path!" << endl;
        return false;
    }

    if (path[0] == "/") {
        dir_inodeNum = root_dir_inodeNum;
        path.erase(path.begin());   // erase the root dir "/"
    }
    else
        dir_inodeNum = cur_dir_inodeNum;

    // apart from the last file, all other directories need to be created
    for (int i = 0; i < (int)path.size() - 1; i++) {
        // get to the next directory (dir_inodeNum points to its inode)
        // if dir exists, nothing happens; otherwise, create a new dir and return false
        CreateInCurDir(dir_inodeNum, path[i], false);
    }
    if (!CreateInCurDir(dir_inodeNum, path[path.size() - 1], true)) {
        // file already exists
        cout << "[Error] " << filepath << " already exists!" << endl;
        return false;
    }
    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb $0x0, (%r12)
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rsi), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x7268
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2b48
movl %eax, %ebp
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x4678
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2200
testb %bpl, %bpl
je 0x46aa
movq 0x10(%rsp), %rdi
cmpq 0x18(%rsp), %rdi
je 0x46b8
leaq 0x4aaf(%rip), %rsi      # 0x913f
callq 0x2090
testl %eax, %eax
je 0x472e
movl 0x34(%r14), %eax
movl %eax, 0xc(%rsp)
jmp 0x4743
movl $0x15, %edx
leaq 0x4ea7(%rip), %rsi      # 0x955d
jmp 0x46c4
movl $0x13, %edx
leaq 0x4eaf(%rip), %rsi      # 0x9573
movq 0x8905(%rip), %rbx      # 0xcfd0
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
xorl %ebp, %ebp
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x4713
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x10(%rsp), %rdi
callq 0x7068
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x30(%r14), %eax
movl %eax, 0xc(%rsp)
leaq 0x10(%rsp), %rdi
movq (%rdi), %rsi
callq 0x775a
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rax
subq %rdx, %rax
movq %rax, %rcx
shrq $0x5, %rcx
cmpl $0x2, %ecx
jl 0x47a8
xorl %r13d, %r13d
leaq 0xc(%rsp), %r15
movabsq $-0x100000000, %rbp     # imm = 0xFFFFFFFF00000000
xorl %r12d, %r12d
addq %r13, %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x3fa6
incq %r12
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rax
subq %rdx, %rax
movq %rax, %rcx
shlq $0x1b, %rcx
addq %rbp, %rcx
sarq $0x20, %rcx
addq $0x20, %r13
cmpq %rcx, %r12
jl 0x4771
addq %rax, %rdx
addq $-0x20, %rdx
leaq 0xc(%rsp), %rsi
movq %r14, %rdi
movl $0x1, %ecx
leaq 0x58(%rsp), %r12
callq 0x3fa6
movb $0x1, %bpl
testb %al, %al
jne 0x46fc
movq 0x87f8(%rip), %rdi      # 0xcfd0
leaq 0x4da8(%rip), %rsi      # 0x9587
movl $0x8, %edx
callq 0x2240
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x87d9(%rip), %rdi      # 0xcfd0
callq 0x2240
movq %rax, %rbx
leaq 0x4e71(%rip), %rsi      # 0x9677
movl $0x10, %edx
movq %rax, %rdi
callq 0x2240
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
jmp 0x46e7
jmp 0x484c
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x484f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x484f
jmp 0x484c
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x486b
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x10(%rsp), %rdi
callq 0x7068
movq %rbx, %rdi
callq 0x2350
nop