// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movq %rsi, %r12
movq %rsp, %r14
movl (%rdi), %eax
movq %rsp, %r15
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movl 0x34(%rdi), %edx
leaq -0x100(%rbp), %rsi
movq %rdi, -0x38(%rbp)
callq 0x37c4
xorl %ecx, %ecx
leaq -0xd6(%rbp), %rax
xorl %edx, %edx
movsbl (%rax), %esi
shll %cl, %esi
addl %esi, %edx
incq %rax
addq $0x8, %rcx
cmpq $0x10, %rcx
jne 0x4b0b
movq -0x38(%rbp), %r13
leaq 0x8(%r13), %rdi
addl $0x6, %edx
movq %r15, %rsi
callq 0x26d0
leaq 0x4a43(%rip), %rsi      # 0x957c
movq %r12, %rdi
callq 0x2090
testl %eax, %eax
jne 0x4bc3
movq 0x8484(%rip), %rbx      # 0xcfd0
leaq 0x4a2c(%rip), %rsi      # 0x957f
movl $0xa, %edx
movq %rbx, %rdi
callq 0x2240
leaq 0x4a23(%rip), %rsi      # 0x958a
movl $0x7, %edx
movq %rbx, %rdi
callq 0x2240
leaq 0x4a17(%rip), %rsi      # 0x9592
movl $0x12, %edx
movq %rbx, %rdi
callq 0x2240
leaq 0x4a16(%rip), %rsi      # 0x95a5
movl $0x12, %edx
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
cmpl $0xd, (%r13)
jl 0x4f87
movq %r15, -0x48(%rbp)
movq %r12, -0xb8(%rbp)
movq %r14, -0xb0(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0xc, %eax
leaq -0x68(%rbp), %r15
xorl %r13d, %r13d
movq %rax, -0x40(%rbp)
leal 0x8(%r13), %r12d
leal 0xa(%r13), %ebx
movq -0x48(%rbp), %r14
movq %r14, %rdi
movl %r12d, %esi
movl %ebx, %edx
callq 0x2a38
testl %eax, %eax
je 0x4ccf
movq %r15, %rdi
movq %r14, %rsi
movl %r13d, %edx
movl %r12d, %ecx
callq 0x2ab6
movq -0xb8(%rbp), %r12
movq %r12, %rdi
leaq 0x497e(%rip), %rsi      # 0x95b8
callq 0x2090
testl %eax, %eax
je 0x4c87
movq %r12, %rdi
leaq 0x492f(%rip), %rsi      # 0x957c
callq 0x2090
testl %eax, %eax
je 0x4c87
movq %r15, %r13
movq %r15, %rdi
leaq 0x4867(%rip), %rsi      # 0x94ca
callq 0x2090
testl %eax, %eax
je 0x4f16
movq %r13, %rdi
leaq 0x484f(%rip), %rsi      # 0x94c9
callq 0x2090
testl %eax, %eax
je 0x4f1f
movq %r12, %rdi
leaq 0x48eb(%rip), %rsi      # 0x957c
callq 0x2090
testl %eax, %eax
je 0x4cdc
movq -0x48(%rbp), %rdi
movl %ebx, %esi
movq -0x40(%rbp), %r13
movl %r13d, %edx
callq 0x2a38
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
movl %eax, %esi
callq 0x4a8a
testb %al, %al
je 0x4eaa
movq %r15, %rdi
callq 0x2dc8
jmp 0x4ece
movq -0x38(%rbp), %rbx
movq -0x40(%rbp), %r13
jmp 0x4f40
movq -0x48(%rbp), %rdi
movl %ebx, %esi
movq -0x40(%rbp), %r13
movl %r13d, %edx
callq 0x2a38
movq -0x38(%rbp), %rbx
leaq -0x140(%rbp), %r14
leal 0xf(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %edx
sarl $0x4, %edx
incl %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x37c4
leaq -0xa8(%rbp), %rdi
movq %r14, %rsi
movl $0xa, %edx
movl $0x1a, %ecx
callq 0x2ab6
leaq -0x88(%rbp), %rdi
movq %r14, %rsi
movl $0x1a, %edx
movl $0x2a, %ecx
callq 0x2ab6
movq 0x8286(%rip), %rdi      # 0xcfd0
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)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x2240
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)
xorl %ecx, %ecx
xorl %edx, %edx
movsbl (%r14), %esi
shll %cl, %esi
addl %esi, %edx
addq $0x8, %rcx
incq %r14
cmpq $0x10, %rcx
jne 0x4d9d
testl %edx, %edx
leaq 0x4800(%rip), %rsi      # 0x95bb
leaq 0x47ca(%rip), %rax      # 0x958c
cmoveq %rax, %rsi
movl $0x5, %edx
movq 0x81fe(%rip), %r14      # 0xcfd0
movq %r14, %rdi
callq 0x2240
movl $0x2, %edx
movq %r14, %rdi
leaq 0x47a6(%rip), %rsi      # 0x958f
callq 0x2240
movq -0xa8(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movq %r14, %rdi
callq 0x2240
movl $0x4, %edx
movq %rax, %rdi
leaq 0x477a(%rip), %rsi      # 0x958d
callq 0x2240
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
movq %r14, %rdi
callq 0x2240
movl $0x4, %edx
movq %rax, %rdi
leaq 0x4753(%rip), %rsi      # 0x958d
callq 0x2240
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x4e82
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x4f27
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x4f27
movq 0x811f(%rip), %rdi      # 0xcfd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0xa, 0x10(%rdi,%rax)
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
callq 0x2240
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
cmpl $0x4, %eax
jne 0x4f27
movq 0x80ee(%rip), %rcx      # 0xcfd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq 0x80d0(%rip), %rdi      # 0xcfd0
callq 0x2030
movl $0x0, -0x2c(%rbp)
movq %rax, %rdi
callq 0x2120
jmp 0x4f27
movq -0x38(%rbp), %rbx
movq %r13, %r15
jmp 0x4f23
movq -0x38(%rbp), %rbx
movq -0x40(%rbp), %r13
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x4f40
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
leal 0xc(%r13), %eax
cmpl (%rbx), %eax
jl 0x4bf3
cmpl $0x0, -0x2c(%rbp)
movq -0xb0(%rbp), %r14
je 0x4f87
movq 0x8070(%rip), %rbx      # 0xcfd0
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
movq %r14, %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x4fc6
jmp 0x4fa2
jmp 0x4fa2
movq %rax, %rbx
jmp 0x4fe8
movq %rax, %rbx
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x4fc6
movq -0x78(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0xa8(%rbp), %rdi
leaq -0x98(%rbp), %rax
cmpq %rax, %rdi
je 0x4fe8
movq -0x98(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x5001
movq -0x58(%rbp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2350
nop