// File: /workspace/github_cpp_makefile_star2_O2/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
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 0x6d1f(%rip), %rdi      # 0xafd0
testb %bpl, %bpl
je 0x42ec
movq 0x10(%rsp), %rax
cmpq 0x18(%rsp), %rax
je 0x42f8
leaq 0x2de5(%rip), %rsi      # 0x70ae
movq %rax, %rdi
callq 0x54ac
testb %al, %al
je 0x4304
movl 0x30(%r14), %eax
movl %eax, 0xc(%rsp)
leaq 0x10(%rsp), %rdi
movq (%rdi), %rsi
callq 0x54ba
jmp 0x430c
leaq 0x31d9(%rip), %rsi      # 0x74cc
jmp 0x439e
leaq 0x31e3(%rip), %rsi      # 0x74e2
jmp 0x439e
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 0x4359
addq %r12, %rdx
movq %r14, %rdi
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x338e
incq %rbp
addq $0x20, %r12
jmp 0x4320
addq %rax, %rdx
addq $-0x20, %rdx
leaq 0xc(%rsp), %rsi
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x338e
movb $0x1, %bpl
testb %al, %al
jne 0x43ad
movq 0x6c53(%rip), %rdi      # 0xafd0
leaq 0x3257(%rip), %rsi      # 0x75db
callq 0x21d0
movq %rax, %rdi
movq %rbx, %rsi
callq 0x21b0
movq %rax, %rdi
leaq 0x3247(%rip), %rsi      # 0x75e5
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 0x43e5
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x20e0
jmp 0x43e8
jmp 0x43e5
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x20e0
leaq 0x10(%rsp), %rdi
callq 0x5480
movq %rbx, %rdi
callq 0x2340