// File: /workspace/github_cpp_makefile_star2_O3/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 $0x108, %rsp            # imm = 0x108
movq %rsi, %r12
movq %rdi, %r13
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 -0x130(%rbp), %rbx
movq %rbx, %rsi
callq 0x3d48
movsbl 0x2a(%rbx), %eax
movsbl 0x2b(%rbx), %ecx
shll $0x8, %ecx
leaq 0x8(%r13), %rdi
leal (%rcx,%rax), %edx
addl $0x6, %edx
movq %r15, %rsi
callq 0x26e0
leaq 0x458b(%rip), %rsi      # 0x960d
movq %r12, -0xb0(%rbp)
movq %r12, %rdi
callq 0x2090
testl %eax, %eax
jne 0x5113
movq 0x7f34(%rip), %rbx      # 0xcfd0
leaq 0x456d(%rip), %rsi      # 0x9610
movl $0xa, %edx
movq %rbx, %rdi
callq 0x2240
leaq 0x4564(%rip), %rsi      # 0x961b
movl $0x7, %edx
movq %rbx, %rdi
callq 0x2240
leaq 0x4558(%rip), %rsi      # 0x9623
movl $0x12, %edx
movq %rbx, %rdi
callq 0x2240
leaq 0x4557(%rip), %rsi      # 0x9636
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
movq %r13, -0x38(%rbp)
cmpl $0xd, (%r13)
jl 0x54f2
movq %r14, -0xa8(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0xc, %r13d
leaq -0x60(%rbp), %r14
movq %r15, -0x40(%rbp)
movq %r14, %r12
leal -0x4(%r13), %r14d
leal -0x2(%r13), %ebx
movq %r15, %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x2a36
testl %eax, %eax
je 0x5233
leal -0xc(%r13), %edx
movq %r12, %rdi
movq %r15, %rsi
movl %r14d, %ecx
callq 0x2ab4
movq -0xb0(%rbp), %r14
movq %r14, %rdi
leaq 0x44c8(%rip), %rsi      # 0x9649
callq 0x2090
testl %eax, %eax
je 0x51d2
movq %r14, %rdi
leaq 0x4479(%rip), %rsi      # 0x960d
callq 0x2090
testl %eax, %eax
je 0x51d2
movq %r12, %r15
movq %r12, %rdi
leaq 0x43b1(%rip), %rsi      # 0x955b
callq 0x2090
testl %eax, %eax
je 0x547d
movq %r15, %rdi
leaq 0x4399(%rip), %rsi      # 0x955a
callq 0x2090
testl %eax, %eax
movq -0x40(%rbp), %r15
je 0x548a
movq %r14, %rdi
leaq 0x4431(%rip), %rsi      # 0x960d
callq 0x2090
testl %eax, %eax
je 0x523f
movq %r15, %rdi
movl %ebx, %esi
movl %r13d, %edx
callq 0x2a36
movq -0x38(%rbp), %rbx
movq %r12, %r14
movq %rbx, %rdi
leaq -0xf0(%rbp), %rsi
movl %eax, %edx
callq 0x3d48
movsbl -0xf0(%rbp), %eax
movsbl -0xef(%rbp), %ecx
shll $0x8, %ecx
addl %eax, %ecx
cmpl $0x1, %ecx
jne 0x5411
movq %r14, %rdi
callq 0x2dc6
jmp 0x5435
movq -0x38(%rbp), %rbx
movq %r12, %r14
jmp 0x54aa
movq %r15, %rdi
movl %ebx, %esi
movl %r13d, %edx
callq 0x2a36
movq -0x38(%rbp), %rbx
movq %r12, %r14
leaq -0xf0(%rbp), %r12
leal 0xf(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %edx
sarl $0x4, %edx
incl %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3d48
leaq -0xa0(%rbp), %rdi
movq %r12, %rsi
movl $0xa, %edx
movl $0x1a, %ecx
callq 0x2ab4
leaq -0x80(%rbp), %rdi
movq %r12, %rsi
movl $0x1a, %edx
movl $0x2a, %ecx
callq 0x2ab4
movq 0x7d28(%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 -0x60(%rbp), %rsi
movq -0x58(%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)
movsbl -0xf0(%rbp), %eax
movsbl -0xef(%rbp), %ecx
shll $0x8, %ecx
addl %eax, %ecx
leaq 0x433b(%rip), %rsi      # 0x964c
leaq 0x4305(%rip), %rax      # 0x961d
cmoveq %rax, %rsi
movl $0x5, %edx
movq 0x7ca8(%rip), %rdi      # 0xcfd0
callq 0x2240
movl $0x2, %edx
movq 0x7c97(%rip), %rdi      # 0xcfd0
leaq 0x42e0(%rip), %rsi      # 0x9620
callq 0x2240
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq 0x7c76(%rip), %rdi      # 0xcfd0
callq 0x2240
movl $0x4, %edx
movq %rax, %rdi
leaq 0x42b0(%rip), %rsi      # 0x961e
callq 0x2240
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq 0x7c4e(%rip), %rdi      # 0xcfd0
callq 0x2240
movl $0x4, %edx
movq %rax, %rdi
leaq 0x4288(%rip), %rsi      # 0x961e
callq 0x2240
movq 0x7c2e(%rip), %rcx      # 0xcfd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq 0x7c10(%rip), %rdi      # 0xcfd0
callq 0x2030
movq %rax, %rdi
callq 0x2120
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x53e6
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x5491
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2200
jmp 0x5491
movq 0x7bb8(%rip), %rdi      # 0xcfd0
movq (%rdi), %rax
movq -0x18(%rax), %rax
movq $0xa, 0x10(%rdi,%rax)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq 0x2240
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, -0x2c(%rbp)
cmpl $0x4, %eax
jne 0x5491
movq 0x7b87(%rip), %rcx      # 0xcfd0
movq (%rcx), %rax
movq -0x18(%rax), %rdi
addq %rcx, %rdi
movl $0xa, %esi
callq 0x21e0
movsbl %al, %esi
movq 0x7b69(%rip), %rdi      # 0xcfd0
callq 0x2030
movl $0x0, -0x2c(%rbp)
movq %rax, %rdi
callq 0x2120
jmp 0x5491
movq -0x38(%rbp), %rbx
movq %r15, %r14
movq -0x40(%rbp), %r15
jmp 0x5491
movq -0x38(%rbp), %rbx
movq %r12, %r14
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x54aa
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2200
addl $0xc, %r13d
cmpl (%rbx), %r13d
jl 0x513e
cmpl $0x0, -0x2c(%rbp)
movq -0xa8(%rbp), %r14
je 0x54f2
movq 0x7b05(%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 0x552e
jmp 0x550d
jmp 0x550d
movq %rax, %rbx
jmp 0x5550
movq %rax, %rbx
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x552e
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x5550
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2200
movq -0x60(%rbp), %rdi
leaq -0x50(%rbp), %rax
cmpq %rax, %rdi
je 0x5569
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2350
nop