// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, -0x40(%rbp)
movl (%rdi), %eax
movq %rsp, %r15
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movl 0x34(%rdi), %edx
leaq -0x120(%rbp), %r12
movq %r12, %rsi
callq 0x3176
leaq 0x8(%r14), %r13
pushq $0x2a
popq %rsi
pushq $0x2c
popq %rdx
movq %r12, %rdi
callq 0x2917
leal 0x6(%rax), %edx
movq %r13, %rdi
movq %r15, %rsi
callq 0x2648
leaq 0x374e(%rip), %rsi      # 0x757c
movq %rbx, -0x38(%rbp)
movq %rbx, %rdi
callq 0x54ac
testb %al, %al
je 0x3e89
movq 0x718b(%rip), %r12      # 0xafd0
leaq 0x3733(%rip), %rsi      # 0x757f
movq %r12, %rdi
callq 0x21d0
leaq 0x372f(%rip), %rsi      # 0x758a
movq %r12, %rdi
callq 0x21d0
leaq 0x3728(%rip), %rsi      # 0x7592
movq %r12, %rdi
callq 0x21d0
leaq 0x372c(%rip), %rsi      # 0x75a5
movq %r12, %rdi
callq 0x21d0
movq %r12, %rdi
callq 0x20f0
xorl %ebx, %ebx
movl $0x0, -0x2c(%rbp)
addl $-0xc, %ebx
movl %ebx, %r13d
movq -0x38(%rbp), %r12
leal 0x18(%r13), %eax
cmpl (%r14), %eax
jge 0x410c
leal 0x14(%r13), %esi
leal 0x16(%r13), %edx
movq %r15, %rdi
callq 0x2917
addl $0xc, %r13d
testl %eax, %eax
je 0x3e9c
leal 0x8(%r13), %ecx
leaq -0x60(%rbp), %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x2967
movq %r12, %rdi
leaq 0x36da(%rip), %rsi      # 0x75b8
callq 0x54bf
leal 0xc(%r13), %ebx
testb %al, %al
je 0x3f34
movq %r12, %rdi
leaq 0x3687(%rip), %rsi      # 0x757c
callq 0x54bf
testb %al, %al
je 0x3f34
leaq -0x60(%rbp), %r12
movq %r12, %rdi
leaq 0x35be(%rip), %rsi      # 0x74ca
callq 0x54ac
testb %al, %al
jne 0x40fe
movq %r12, %rdi
leaq 0x35a6(%rip), %rsi      # 0x74c9
callq 0x54ac
testb %al, %al
movq -0x38(%rbp), %r12
jne 0x40fe
addl $0xa, %r13d
movq %r12, %rdi
leaq 0x363a(%rip), %rsi      # 0x757c
callq 0x54ac
testb %al, %al
je 0x4098
movq %r15, %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0x2917
leaq -0xe0(%rbp), %r13
cltd
pushq $0x10
popq %rcx
idivl %ecx
leal 0x1(%rax), %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3176
leaq -0xa0(%rbp), %rdi
movq %r13, %rsi
pushq $0xa
popq %rdx
pushq $0x1a
popq %r12
movl %r12d, %ecx
callq 0x2967
leaq -0x80(%rbp), %rdi
movq %r13, %rsi
movl %r12d, %edx
pushq $0x2a
popq %rcx
callq 0x2967
movq 0x7027(%rip), %rdi      # 0xafd0
movq (%rdi), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rdi,%rcx), %edx
movl $0xffffff4f, %esi       # imm = 0xFFFFFF4F
andl %esi, %edx
orl $0x20, %edx
movl %edx, 0x18(%rdi,%rcx)
movq -0x18(%rax), %rax
movq $0xa, 0x10(%rdi,%rax)
leaq -0x60(%rbp), %rsi
callq 0x21b0
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
movl $0xffffff4f, %esi       # imm = 0xFFFFFF4F
andl %esi, %edx
orl $0x80, %edx
movl %edx, 0x18(%rax,%rcx)
leaq -0xe0(%rbp), %rdi
xorl %esi, %esi
pushq $0x2
popq %rdx
callq 0x2917
testl %eax, %eax
leaq 0x35ad(%rip), %rsi      # 0x75bb
leaq 0x3577(%rip), %rax      # 0x758c
cmoveq %rax, %rsi
movq 0x6fb0(%rip), %rdi      # 0xafd0
callq 0x21d0
movq %rax, %rdi
leaq 0x3560(%rip), %rsi      # 0x758f
callq 0x21d0
movq 0x6f95(%rip), %rdi      # 0xafd0
leaq -0xa0(%rbp), %rsi
callq 0x21b0
movq %rax, %rdi
leaq 0x353c(%rip), %rsi      # 0x758d
callq 0x21d0
movq 0x6f73(%rip), %rdi      # 0xafd0
leaq -0x80(%rbp), %rsi
callq 0x21b0
movq %rax, %rdi
leaq 0x351d(%rip), %rsi      # 0x758d
callq 0x21d0
movq 0x6f54(%rip), %rdi      # 0xafd0
callq 0x20f0
leaq -0x80(%rbp), %rdi
callq 0x20e0
leaq -0xa0(%rbp), %rdi
callq 0x20e0
jmp 0x40fe
movq %r15, %rdi
movl %r13d, %esi
movl %ebx, %edx
callq 0x2917
movq %r14, %rdi
movl %eax, %esi
callq 0x3d98
testb %al, %al
je 0x40be
leaq -0x60(%rbp), %rdi
callq 0x2bbe
jmp 0x40de
movq 0x6f0b(%rip), %rdi      # 0xafd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0xa, 0x10(%rdi,%rax)
leaq -0x60(%rbp), %rsi
callq 0x21b0
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
cmpl $0x4, %eax
jne 0x40fe
movl $0x0, -0x2c(%rbp)
movq 0x6ed7(%rip), %rdi      # 0xafd0
callq 0x20f0
leaq -0x60(%rbp), %rdi
callq 0x20e0
jmp 0x3e92
cmpl $0x0, -0x2c(%rbp)
je 0x411e
movq 0x6eb7(%rip), %rdi      # 0xafd0
callq 0x20f0
movq -0x40(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x414b
jmp 0x413a
jmp 0x413a
movq %rax, %rbx
jmp 0x4157
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x20e0
leaq -0xa0(%rbp), %rdi
callq 0x20e0
leaq -0x60(%rbp), %rdi
callq 0x20e0
movq %rbx, %rdi
callq 0x2340