// File: /workspace/github_cpp_makefile_star2_O1/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 0x6c9e
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2b4a
movl %eax, %ebp
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x40e8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2200
testb %bpl, %bpl
je 0x411a
movq 0x10(%rsp), %rdi
cmpq 0x18(%rsp), %rdi
je 0x4128
leaq 0x4fae(%rip), %rsi      # 0x90ae
callq 0x2090
testl %eax, %eax
je 0x419e
movl 0x34(%r14), %eax
movl %eax, 0xc(%rsp)
jmp 0x41b3
movl $0x15, %edx
leaq 0x53a6(%rip), %rsi      # 0x94cc
jmp 0x4134
movl $0x13, %edx
leaq 0x53ae(%rip), %rsi      # 0x94e2
movq 0x8e95(%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 0x4183
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x10(%rsp), %rdi
callq 0x6abe
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 0x71b8
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rax
subq %rdx, %rax
movq %rax, %rcx
shrq $0x5, %rcx
cmpl $0x2, %ecx
jl 0x4218
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 0x3a66
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 0x41e1
addq %rax, %rdx
addq $-0x20, %rdx
leaq 0xc(%rsp), %rsi
movq %r14, %rdi
movl $0x1, %ecx
leaq 0x58(%rsp), %r12
callq 0x3a66
movb $0x1, %bpl
testb %al, %al
jne 0x416c
movq 0x8d88(%rip), %rdi      # 0xcfd0
leaq 0x52a7(%rip), %rsi      # 0x94f6
movl $0x8, %edx
callq 0x2240
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x8d69(%rip), %rdi      # 0xcfd0
callq 0x2240
movq %rax, %rbx
leaq 0x5370(%rip), %rsi      # 0x95e6
movl $0x10, %edx
movq %rax, %rdi
callq 0x2240
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
jmp 0x4157
jmp 0x42bc
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x42bf
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x42bf
jmp 0x42bc
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x42db
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x10(%rsp), %rdi
callq 0x6abe
movq %rbx, %rdi
callq 0x2350
nop