// File: hyp1231[P]FMSS/filesystem.cpp
// Function: FileSystem::ListFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void FileSystem::ListFile(const string param) {
    /* 
        step 1: get current dir block
    */

    char inode_buf[64], dir_buf[BLKsize];
    Get_inode_from_inodeNum(inode_buf, cur_dir_inodeNum);
    // get dir data block
    D.Getblk(dir_buf, Get_actual_dataBLKnumber(byte2int(inode_buf, 42, 44)));

    /* 
        step 2: list all files in the dir
    */

    if (param == "-l") {
        cout << "Name      ";       // name
        cout << "       ";          // <DIR>
        cout << "     Create Time  "; // create_time
        cout << "Last Modified Time"; // modify_time
        cout << endl;
    }

    int cnt_per_line = 0;
    int max_per_line = 4;
    for (int i = 0; i + 12 < BLKsize; i += 12) {
        if (byte2int(dir_buf, i + 8, i + 10) != 0) {
            string name = byte2string(dir_buf, i, i + 8);
            // if not show hidden files and filename "." or ".."
            if((param != "-a" && param != "-l") && (name == "." || name == "..")) {
                continue;
            }
            else if (param == "-l") {
                char buf[64];
                int file_inodeNum = byte2int(dir_buf, i + 10, i + 12);
                Get_inode_from_inodeNum(buf, Get_actual_inodeBLKnumber(file_inodeNum));

                string create_time = byte2string(buf, 10, 26);
                string modify_time = byte2string(buf, 26, 42);
                cout << std::left << setw(10) << name << std::right;
                if (byte2int(buf, 0, 2) == 0)
                    cout << "     " << "  ";
                else
                    cout << "<DIR>" << "  ";
                cout << create_time << "    ";
                cout << modify_time << "    ";
                cout << endl;

                continue;
            }

            if(isDir(byte2int(dir_buf, i + 10, i + 12))) {
                PrintRed(name);
            } else {
                cout << setw(10) << name;
            }
            cnt_per_line++;
            if (cnt_per_line == max_per_line) {
                cnt_per_line = 0;
                cout << endl;
            }
        }
    }
    if(cnt_per_line != 0) {
        cout << endl;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rsi, -0x138(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x150(%rbp)
movl (%rdi), %eax
movq %rsp, %rcx
movq %rcx, -0x58(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x140(%rbp)
movq %rcx, %rsp
movq %rax, -0x60(%rbp)
leaq -0x50(%rbp), %rsi
movl 0x34(%rdi), %edx
callq 0x4ff0
movq -0x150(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x148(%rbp)
leaq -0x50(%rbp), %rdi
movl $0x2a, %esi
movl $0x2c, %edx
callq 0x40e0
movq -0x150(%rbp), %rdi
movl %eax, %esi
callq 0x9390
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rsi
movl %eax, %edx
callq 0x3900
movq -0x138(%rbp), %rdi
leaq 0x8ca8(%rip), %rsi      # 0xf597
callq 0x9320
testb $0x1, %al
jne 0x68fa
jmp 0x6959
movq 0xe6cf(%rip), %rdi      # 0x14fd0
leaq 0x8c92(%rip), %rsi      # 0xf59a
callq 0x3250
movq 0xe6bc(%rip), %rdi      # 0x14fd0
leaq 0x8c8a(%rip), %rsi      # 0xf5a5
callq 0x3250
movq 0xe6a9(%rip), %rdi      # 0x14fd0
leaq 0x8c7f(%rip), %rsi      # 0xf5ad
callq 0x3250
movq 0xe696(%rip), %rdi      # 0x14fd0
leaq 0x8c7f(%rip), %rsi      # 0xf5c0
callq 0x3250
movq 0xe683(%rip), %rdi      # 0x14fd0
movq 0xe66c(%rip), %rsi      # 0x14fc0
callq 0x32a0
movl $0x0, -0x64(%rbp)
movl $0x4, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movq -0x150(%rbp), %rcx
movl -0x6c(%rbp), %eax
addl $0xc, %eax
cmpl (%rcx), %eax
jge 0x6e6f
movq -0x140(%rbp), %rdi
movl -0x6c(%rbp), %esi
addl $0x8, %esi
movl -0x6c(%rbp), %edx
addl $0xa, %edx
callq 0x40e0
cmpl $0x0, %eax
je 0x6e5f
movq -0x140(%rbp), %rsi
movl -0x6c(%rbp), %edx
movl %edx, %ecx
addl $0x8, %ecx
leaq -0x90(%rbp), %rdi
callq 0x4180
movq -0x138(%rbp), %rdi
leaq 0x8c06(%rip), %rsi      # 0xf5d3
callq 0x94b0
movb %al, -0x151(%rbp)
jmp 0x69da
movb -0x151(%rbp), %al
testb $0x1, %al
jne 0x69e9
jmp 0x6a84
movq -0x138(%rbp), %rdi
leaq 0x8ba0(%rip), %rsi      # 0xf597
callq 0x94b0
movb %al, -0x152(%rbp)
jmp 0x6a04
movb -0x152(%rbp), %al
testb $0x1, %al
jne 0x6a10
jmp 0x6a84
leaq 0x8ace(%rip), %rsi      # 0xf4e5
leaq -0x90(%rbp), %rdi
callq 0x9320
movb %al, -0x153(%rbp)
jmp 0x6a2b
movb -0x153(%rbp), %al
testb $0x1, %al
jne 0x6a5e
jmp 0x6a37
leaq 0x8aa6(%rip), %rsi      # 0xf4e4
leaq -0x90(%rbp), %rdi
callq 0x9320
movb %al, -0x154(%rbp)
jmp 0x6a52
movb -0x154(%rbp), %al
testb $0x1, %al
jne 0x6a5e
jmp 0x6a84
movl $0x4, -0xa0(%rbp)
jmp 0x6e35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x6e51
movq -0x138(%rbp), %rdi
leaq 0x8b05(%rip), %rsi      # 0xf597
callq 0x9320
movb %al, -0x155(%rbp)
jmp 0x6a9f
movb -0x155(%rbp), %al
testb $0x1, %al
jne 0x6aae
jmp 0x6d55
movq -0x140(%rbp), %rdi
movl -0x6c(%rbp), %edx
movl %edx, %esi
addl $0xa, %esi
addl $0xc, %edx
callq 0x40e0
movl %eax, -0x15c(%rbp)
jmp 0x6acd
movq -0x150(%rbp), %rdi
movl -0x15c(%rbp), %eax
movl %eax, -0xe4(%rbp)
leaq -0xe0(%rbp), %rax
movq %rax, -0x168(%rbp)
movl -0xe4(%rbp), %esi
callq 0x93b0
movl %eax, -0x160(%rbp)
jmp 0x6b01
movl -0x160(%rbp), %edx
movq -0x168(%rbp), %rsi
movq -0x150(%rbp), %rdi
callq 0x4ff0
jmp 0x6b1c
leaq -0x108(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
movl $0xa, %edx
movl $0x1a, %ecx
callq 0x4180
jmp 0x6b3b
leaq -0x128(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
movl $0x1a, %edx
movl $0x2a, %ecx
callq 0x4180
jmp 0x6b5a
movq 0xe46f(%rip), %rdi      # 0x14fd0
leaq 0x2a48(%rip), %rsi      # 0x95b0
callq 0x30c0
movq %rax, -0x170(%rbp)
jmp 0x6b76
movl $0xa, %edi
callq 0x9240
movl %eax, -0x174(%rbp)
jmp 0x6b88
movq -0x170(%rbp), %rdi
movl -0x174(%rbp), %eax
movl %eax, -0x12c(%rbp)
movl -0x12c(%rbp), %esi
callq 0x3310
movq %rax, -0x180(%rbp)
jmp 0x6baf
movq -0x180(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3230
movq %rax, -0x188(%rbp)
jmp 0x6bcb
movq -0x188(%rbp), %rdi
leaq 0x2a07(%rip), %rsi      # 0x95e0
callq 0x30c0
jmp 0x6be0
leaq -0xe0(%rbp), %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x40e0
movl %eax, -0x18c(%rbp)
jmp 0x6bfb
movl -0x18c(%rbp), %eax
cmpl $0x0, %eax
jne 0x6c73
movq 0xe3c3(%rip), %rdi      # 0x14fd0
leaq 0x8993(%rip), %rsi      # 0xf5a7
callq 0x3250
movq %rax, -0x198(%rbp)
jmp 0x6c22
movq -0x198(%rbp), %rdi
leaq 0x897a(%rip), %rsi      # 0xf5aa
callq 0x3250
jmp 0x6c37
jmp 0x6ca6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
jmp 0x6d44
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x98(%rbp)
movl %eax, -0x9c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x3160
jmp 0x6d44
movq 0xe356(%rip), %rdi      # 0x14fd0
leaq 0x8955(%rip), %rsi      # 0xf5d6
callq 0x3250
movq %rax, -0x1a0(%rbp)
jmp 0x6c8f
movq -0x1a0(%rbp), %rdi
leaq 0x890d(%rip), %rsi      # 0xf5aa
callq 0x3250
jmp 0x6ca4
jmp 0x6ca6
movq 0xe323(%rip), %rdi      # 0x14fd0
leaq -0x108(%rbp), %rsi
callq 0x3230
movq %rax, -0x1a8(%rbp)
jmp 0x6cc2
movq -0x1a8(%rbp), %rdi
leaq 0x88d8(%rip), %rsi      # 0xf5a8
callq 0x3250
jmp 0x6cd7
movq 0xe2f2(%rip), %rdi      # 0x14fd0
leaq -0x128(%rbp), %rsi
callq 0x3230
movq %rax, -0x1b0(%rbp)
jmp 0x6cf3
movq -0x1b0(%rbp), %rdi
leaq 0x88a7(%rip), %rsi      # 0xf5a8
callq 0x3250
jmp 0x6d08
movq 0xe2c1(%rip), %rdi      # 0x14fd0
movq 0xe2aa(%rip), %rsi      # 0x14fc0
callq 0x32a0
jmp 0x6d1d
movl $0x4, -0xa0(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x3160
leaq -0x108(%rbp), %rdi
callq 0x3160
jmp 0x6e35
leaq -0x108(%rbp), %rdi
callq 0x3160
jmp 0x6e51
jmp 0x6d57
movq -0x140(%rbp), %rdi
movl -0x6c(%rbp), %edx
movl %edx, %esi
addl $0xa, %esi
addl $0xc, %edx
callq 0x40e0
movl %eax, -0x1b4(%rbp)
jmp 0x6d76
movl -0x1b4(%rbp), %esi
movq -0x150(%rbp), %rdi
callq 0x6800
movb %al, -0x1b5(%rbp)
jmp 0x6d90
movb -0x1b5(%rbp), %al
testb $0x1, %al
jne 0x6d9c
jmp 0x6dac
leaq -0x90(%rbp), %rdi
callq 0x4640
jmp 0x6daa
jmp 0x6dfc
movl $0xa, %edi
callq 0x9240
movl %eax, -0x1bc(%rbp)
jmp 0x6dbe
movl -0x1bc(%rbp), %eax
movl %eax, -0x130(%rbp)
movl -0x130(%rbp), %esi
movq 0xe1f9(%rip), %rdi      # 0x14fd0
callq 0x3310
movq %rax, -0x1c8(%rbp)
jmp 0x6de5
movq -0x1c8(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3230
jmp 0x6dfa
jmp 0x6dfc
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x68(%rbp), %eax
jne 0x6e2b
movl $0x0, -0x64(%rbp)
movq 0xe1b5(%rip), %rdi      # 0x14fd0
movq 0xe19e(%rip), %rsi      # 0x14fc0
callq 0x32a0
jmp 0x6e29
jmp 0x6e2b
movl $0x0, -0xa0(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x3160
movl -0xa0(%rbp), %eax
testl %eax, %eax
je 0x6e4f
jmp 0x6e4d
jmp 0x6e61
jmp 0x6e5f
leaq -0x90(%rbp), %rdi
callq 0x3160
jmp 0x6e94
jmp 0x6e61
movl -0x6c(%rbp), %eax
addl $0xc, %eax
movl %eax, -0x6c(%rbp)
jmp 0x696e
cmpl $0x0, -0x64(%rbp)
je 0x6e88
movq 0xe154(%rip), %rdi      # 0x14fd0
movq 0xe13d(%rip), %rsi      # 0x14fc0
callq 0x32a0
movq -0x58(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
movq -0x98(%rbp), %rdi
callq 0x3490