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

    vector<string> path;
    string dirname;
    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], false)) {
        // dir 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 0x5790
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2200
testb %bpl, %bpl
je 0x57c2
movq 0x10(%rsp), %rdi
cmpq 0x18(%rsp), %rdi
je 0x57d0
leaq 0x3997(%rip), %rsi      # 0x913f
callq 0x2090
testl %eax, %eax
je 0x5846
movl 0x34(%r14), %eax
movl %eax, 0xc(%rsp)
jmp 0x585b
movl $0x15, %edx
leaq 0x3d8f(%rip), %rsi      # 0x955d
jmp 0x57dc
movl $0x13, %edx
leaq 0x3d97(%rip), %rsi      # 0x9573
movq 0x77ed(%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 0x582b
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 0x58c0
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 0x5889
addq %rax, %rdx
addq $-0x20, %rdx
leaq 0xc(%rsp), %rsi
movq %r14, %rdi
xorl %ecx, %ecx
leaq 0x58(%rsp), %r12
callq 0x3fa6
movb $0x1, %bpl
testb %al, %al
jne 0x5814
movq 0x76e3(%rip), %rdi      # 0xcfd0
leaq 0x3d78(%rip), %rsi      # 0x966c
movl $0x9, %edx
callq 0x2240
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x76c4(%rip), %rdi      # 0xcfd0
callq 0x2240
movq %rax, %rbx
leaq 0x3d5b(%rip), %rsi      # 0x9676
movl $0x11, %edx
movq %rax, %rdi
callq 0x2240
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
jmp 0x57ff
jmp 0x5961
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x5964
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x5964
jmp 0x5961
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x5980
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x10(%rsp), %rdi
callq 0x7068
movq %rbx, %rdi
callq 0x2350