// File: 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
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 0x5c2f
leaq -0x78(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x4280
movb %al, -0xb1(%rbp)
jmp 0x5c44
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 0x5c67
jmp 0x5cdc
movq 0xf362(%rip), %rdi      # 0x14fd0
leaq 0x9872(%rip), %rsi      # 0xf4e7
callq 0x3250
movq %rax, -0xc0(%rbp)
jmp 0x5c83
movq -0xc0(%rbp), %rdi
movq 0xf32f(%rip), %rsi      # 0x14fc0
callq 0x32a0
jmp 0x5c98
movb $0x0, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x5f0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x5f2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3160
jmp 0x5f2a
leaq -0x30(%rbp), %rdi
callq 0x92e0
testb $0x1, %al
jne 0x5ceb
jmp 0x5d2f
movq 0xf2de(%rip), %rdi      # 0x14fd0
leaq 0x9804(%rip), %rsi      # 0xf4fd
callq 0x3250
movq %rax, -0xc8(%rbp)
jmp 0x5d07
movq -0xc8(%rbp), %rdi
movq 0xf2ab(%rip), %rsi      # 0x14fc0
callq 0x32a0
jmp 0x5d1c
movb $0x0, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x5f0a
xorl %eax, %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x9350
movq %rax, %rdi
leaq 0x9368(%rip), %rsi      # 0xf0ae
callq 0x9320
movb %al, -0xc9(%rbp)
jmp 0x5d53
movb -0xc9(%rbp), %al
testb $0x1, %al
jne 0x5d5f
jmp 0x5dc2
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 0x5db2
movq -0xd8(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x5dcf
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 0x5e38
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 0x5e25
jmp 0x5e27
movl -0xa4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa4(%rbp)
jmp 0x5dd9
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
movl $0x1, %ecx
callq 0x5440
movb %al, -0xe5(%rbp)
jmp 0x5e7a
movb -0xe5(%rbp), %al
testb $0x1, %al
jne 0x5efc
jmp 0x5e86
movq 0xf143(%rip), %rdi      # 0x14fd0
leaq 0x967d(%rip), %rsi      # 0xf511
callq 0x3250
movq %rax, -0xf8(%rbp)
jmp 0x5ea2
movq -0xf8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3230
movq %rax, -0x100(%rbp)
jmp 0x5ebb
movq -0x100(%rbp), %rdi
leaq 0x9738(%rip), %rsi      # 0xf601
callq 0x3250
movq %rax, -0x108(%rbp)
jmp 0x5ed7
movq -0x108(%rbp), %rdi
movq 0xf0db(%rip), %rsi      # 0x14fc0
callq 0x32a0
jmp 0x5eec
movb $0x0, -0x1(%rbp)
movl $0x1, -0x88(%rbp)
jmp 0x5f0a
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)