// File: /workspace/github_cpp_makefile_star2_O1/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 0x6c9e
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2b4a
movl %eax, %ebp
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x5228
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2200
testb %bpl, %bpl
je 0x525a
movq 0x10(%rsp), %rdi
cmpq 0x18(%rsp), %rdi
je 0x5268
leaq 0x3e6e(%rip), %rsi      # 0x90ae
callq 0x2090
testl %eax, %eax
je 0x52de
movl 0x34(%r14), %eax
movl %eax, 0xc(%rsp)
jmp 0x52f3
movl $0x15, %edx
leaq 0x4266(%rip), %rsi      # 0x94cc
jmp 0x5274
movl $0x13, %edx
leaq 0x426e(%rip), %rsi      # 0x94e2
movq 0x7d55(%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 0x52c3
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 0x5358
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 0x5321
addq %rax, %rdx
addq $-0x20, %rdx
leaq 0xc(%rsp), %rsi
movq %r14, %rdi
xorl %ecx, %ecx
leaq 0x58(%rsp), %r12
callq 0x3a66
movb $0x1, %bpl
testb %al, %al
jne 0x52ac
movq 0x7c4b(%rip), %rdi      # 0xcfd0
leaq 0x424f(%rip), %rsi      # 0x95db
movl $0x9, %edx
callq 0x2240
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x7c2c(%rip), %rdi      # 0xcfd0
callq 0x2240
movq %rax, %rbx
leaq 0x4232(%rip), %rsi      # 0x95e5
movl $0x11, %edx
movq %rax, %rdi
callq 0x2240
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x21e0
jmp 0x5297
jmp 0x53f9
movq %rax, %rbx
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x53fc
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x53fc
jmp 0x53f9
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x5418
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x10(%rsp), %rdi
callq 0x6abe
movq %rbx, %rdi
callq 0x2350