// File: /workspace/github_cpp_makefile_star2_O2/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
andq $0x0, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x28(%rsp), %rdi
callq 0x22b0
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x29e2
movl %eax, %ebp
leaq 0x28(%rsp), %rdi
callq 0x20e0
movq 0x7845(%rip), %rdi      # 0xafd0
testb %bpl, %bpl
je 0x37c6
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
je 0x37d2
leaq 0x390b(%rip), %rsi      # 0x70ae
movq %rax, %rdi
callq 0x54ac
testb %al, %al
je 0x37de
movl 0x30(%r14), %eax
movl %eax, 0xc(%rsp)
leaq 0x10(%rsp), %rdi
movq (%rdi), %rsi
callq 0x54ba
jmp 0x37e6
leaq 0x3cff(%rip), %rsi      # 0x74cc
jmp 0x3879
leaq 0x3d09(%rip), %rsi      # 0x74e2
jmp 0x3879
movl 0x34(%r14), %eax
movl %eax, 0xc(%rsp)
xorl %r12d, %r12d
movabsq $-0x100000000, %r13     # imm = 0xFFFFFFFF00000000
leaq 0xc(%rsp), %r15
xorl %ebp, %ebp
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rax
subq %rdx, %rax
movq %rax, %rcx
shlq $0x1b, %rcx
addq %r13, %rcx
sarq $0x20, %rcx
cmpq %rcx, %rbp
jge 0x3833
addq %r12, %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x338e
incq %rbp
addq $0x20, %r12
jmp 0x37fa
addq %rax, %rdx
addq $-0x20, %rdx
leaq 0xc(%rsp), %rsi
pushq $0x1
popq %rcx
movq %r14, %rdi
callq 0x338e
movb $0x1, %bpl
testb %al, %al
jne 0x3888
movq 0x7778(%rip), %rdi      # 0xafd0
leaq 0x3c97(%rip), %rsi      # 0x74f6
callq 0x21d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21b0
movq %rax, %rdi
leaq 0x3d6d(%rip), %rsi      # 0x75e6
callq 0x21d0
movq %rax, %rdi
callq 0x20f0
xorl %ebp, %ebp
leaq 0x48(%rsp), %rdi
callq 0x20e0
leaq 0x10(%rsp), %rdi
callq 0x5480
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x38c0
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x20e0
jmp 0x38c3
jmp 0x38c0
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x20e0
leaq 0x10(%rsp), %rdi
callq 0x5480
movq %rbx, %rdi
callq 0x2340
nop