// File: 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
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x9260
leaq -0x50(%rbp), %rdi
callq 0x33e0
movq -0x18(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x30f0
jmp 0x703f
leaq -0x78(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4280
movb %al, -0xb1(%rbp)
jmp 0x7054
movb -0xb1(%rbp), %al
xorb $-0x1, %al
movb %al, -0xb2(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3160
movb -0xb2(%rbp), %al
testb $0x1, %al
jne 0x7077
jmp 0x70ec
movq 0xdf52(%rip), %rdi      # 0x14fd0
leaq 0x8462(%rip), %rsi      # 0xf4e7
callq 0x3250
movq %rax, -0xc0(%rbp)
jmp 0x7093
movq -0xc0(%rbp), %rdi
movq 0xdf1f(%rip), %rsi      # 0x14fc0
callq 0x32a0
jmp 0x70a8
movb $0x0, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x7317
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x7337
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3160
jmp 0x7337
leaq -0x30(%rbp), %rdi
callq 0x92e0
testb $0x1, %al
jne 0x70fb
jmp 0x713f
movq 0xdece(%rip), %rdi      # 0x14fd0
leaq 0x83f4(%rip), %rsi      # 0xf4fd
callq 0x3250
movq %rax, -0xc8(%rbp)
jmp 0x7117
movq -0xc8(%rbp), %rdi
movq 0xde9b(%rip), %rsi      # 0x14fc0
callq 0x32a0
jmp 0x712c
movb $0x0, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x7317
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x9350
movq %rax, %rdi
leaq 0x7f58(%rip), %rsi      # 0xf0ae
callq 0x9320
movb %al, -0xc9(%rbp)
jmp 0x7163
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0x716f
jmp 0x71d2
movq -0xb0(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x54(%rbp)
leaq -0x30(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x9440
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x9470
movq -0xe0(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x93d0
movq %rax, -0xd8(%rbp)
jmp 0x71c2
movq -0xd8(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x71df
movq -0xb0(%rbp), %rax
movl 0x34(%rax), %eax
movl %eax, -0x54(%rbp)
movl $0x0, -0xa4(%rbp)
movl -0xa4(%rbp), %eax
movl %eax, -0xe4(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x9370
movq %rax, %rcx
movl -0xe4(%rbp), %eax
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x7248
movslq -0xa4(%rbp), %rsi
leaq -0x30(%rbp), %rdi
callq 0x9350
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
leaq -0x54(%rbp), %rsi
xorl %ecx, %ecx
callq 0x5440
jmp 0x7235
jmp 0x7237
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x71e9
leaq -0x30(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x9370
movq -0xf0(%rbp), %rdi
movq %rax, %rsi
decq %rsi
callq 0x9350
movq -0xb0(%rbp), %rdi
movq %rax, %rdx
leaq -0x54(%rbp), %rsi
xorl %ecx, %ecx
callq 0x5440
movb %al, -0xe5(%rbp)
jmp 0x7287
movb -0xe5(%rbp), %al
testb $0x1, %al
jne 0x7309
jmp 0x7293
movq 0xdd36(%rip), %rdi      # 0x14fd0
leaq 0x8355(%rip), %rsi      # 0xf5f6
callq 0x3250
movq %rax, -0xf8(%rbp)
jmp 0x72af
movq -0xf8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3230
movq %rax, -0x100(%rbp)
jmp 0x72c8
movq -0x100(%rbp), %rdi
leaq 0x832a(%rip), %rsi      # 0xf600
callq 0x3250
movq %rax, -0x108(%rbp)
jmp 0x72e4
movq -0x108(%rbp), %rdi
movq 0xdcce(%rip), %rsi      # 0x14fc0
callq 0x32a0
jmp 0x72f9
movb $0x0, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x7317
movb $0x1, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x3160
leaq -0x30(%rbp), %rdi
callq 0x9280
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x3160
leaq -0x30(%rbp), %rdi
callq 0x9280
movq -0x80(%rbp), %rdi
callq 0x3490
nopw %cs:(%rax,%rax)