// File: /workspace/github_cpp_makefile_star2_O1/aman-agrawal[P]Terminal-based-file-explorer/list.cpp
// Function: list[abi:cxx11](char*, char)
vector<pair<string, char>> list(char* str,char d) {            //function definition begin
    clear();        //clear terminal
    vector<pair<string, char>> filename;
    DIR *mydir;
    struct dirent **myfile;
    struct stat mystat;
    char buf[512];
    struct passwd *pw;
    struct group  *gr;

    int total_files = scandir(str, &myfile, NULL, alphasort);

    for(int i=0; i<total_files; i++) {


        string name = myfile[i]->d_name;
        stat(name.c_str(), &mystat);

        string strTemp(str);    //concatenate path to string
        strTemp = strTemp+"/"+name;

        cout << name<<"  ";     //filename

        cout<< mystat.st_size<<"    ";       //file size

        pw = getpwuid(mystat.st_uid);
        gr = getgrgid(mystat.st_gid);

        cout << pw->pw_name << " " << gr->gr_name << " ";   //ownername nd groupname

        char d= (S_ISDIR(mystat.st_mode)) ? 'd' : '-';
        filename.push_back(make_pair(strTemp, d));

        char ur= (mystat.st_mode & S_IRUSR) ? 'r' : '-';
        char  uw= (mystat.st_mode & S_IWUSR) ? 'w' : '-';
        char ue = (mystat.st_mode & S_IXUSR) ? 'x' : '-';

        char gr= (mystat.st_mode & S_IRGRP) ? 'r' : '-';
        char gw= (mystat.st_mode & S_IWGRP) ? 'w' : '-';
        char ge = (mystat.st_mode & S_IXGRP) ? 'x' : '-';

        char oread = (mystat.st_mode & S_IROTH) ? 'r' : '-';
        char ow = (mystat.st_mode & S_IWOTH) ? 'w' : '-';
        char oe = (mystat.st_mode & S_IXOTH) ? 'x' : '-';
        
        cout << d;                          //print whether it is directory or file
        cout << ur << uw << ue;
        cout << gr << gw << ge;
        cout << oread << ow << oe<<"   ";

        cout << ctime(&mystat.st_mtime);    //print time
    }
    return filename;   
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x494a(%rip), %rdi      # 0x8004
xorl %eax, %eax
callq 0x3040
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq %rbx, 0x30(%rsp)
movq $0x0, 0x10(%rbx)
movq 0x78ed(%rip), %rcx      # 0xafc8
leaq 0xc0(%rsp), %rsi
movq %r14, 0xb0(%rsp)
movq %r14, %rdi
xorl %edx, %edx
callq 0x3060
testl %eax, %eax
jle 0x3c19
leaq 0x48(%rsp), %r15
leaq 0x98(%rsp), %r12
leaq 0x18(%rsp), %r13
movl %eax, %eax
movq %rax, 0xa8(%rsp)
xorl %ecx, %ecx
movq 0xc0(%rsp), %rax
movq %rcx, 0xb8(%rsp)
movq (%rax,%rcx,8), %r14
leaq 0x13(%r14), %rbx
movq %r15, 0x38(%rsp)
movq %rbx, %rdi
callq 0x3100
leaq (%r14,%rax), %rdx
addq $0x13, %rdx
leaq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x3df8
movq 0x38(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x31e0
leaq 0x68(%rsp), %rdi
movq 0xb0(%rsp), %rsi
leaq 0x8(%rsp), %r14
movq %r14, %rdx
callq 0x3cce
leaq 0x88(%rsp), %rbx
movq %r12, 0x88(%rsp)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x3d68
movq %rbx, %rdi
leaq 0x49a5(%rip), %rsi      # 0x8155
callq 0x33f0
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq %rbx, %rdi
callq 0x30b0
movq %r13, 0x8(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x37ea
movq %rdx, 0x8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x18(%rsp)
jmp 0x37f2
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, 0x10(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x3290
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x382e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3220
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x384b
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x3220
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x7774(%rip), %rdi      # 0xafd0
callq 0x3270
movl $0x2, %edx
movq %rax, %rdi
leaq 0x4965(%rip), %rsi      # 0x81d5
callq 0x3270
movq 0xf8(%rsp), %rsi
movq 0x774c(%rip), %rdi      # 0xafd0
callq 0x31f0
movl $0x4, %edx
movq %rax, %rdi
leaq 0x493b(%rip), %rsi      # 0x81d3
callq 0x3270
movl 0xe4(%rsp), %edi
callq 0x3280
movq %rax, %rbx
movl 0xe8(%rsp), %edi
callq 0x3380
movq %rax, %rbp
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x38df
movq %rbx, %rdi
callq 0x3100
movq 0x76fe(%rip), %rdi      # 0xafd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3270
jmp 0x38fd
movq 0x76ea(%rip), %rcx      # 0xafd0
movq (%rcx), %rax
movq -0x18(%rax), %rax
leaq (%rcx,%rax), %rdi
movl 0x20(%rcx,%rax), %esi
orl $0x1, %esi
callq 0x3390
movl $0x1, %edx
movq 0x76c7(%rip), %rdi      # 0xafd0
leaq 0x48c6(%rip), %rsi      # 0x81d6
callq 0x3270
movq (%rbp), %rbx
testq %rbx, %rbx
je 0x393a
movq %rbx, %rdi
callq 0x3100
movq 0x76a3(%rip), %rdi      # 0xafd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3270
jmp 0x3958
movq 0x768f(%rip), %rcx      # 0xafd0
movq (%rcx), %rax
movq -0x18(%rax), %rax
leaq (%rcx,%rax), %rdi
movl 0x20(%rcx,%rax), %esi
orl $0x1, %esi
callq 0x3390
movl $0x1, %edx
movq 0x766c(%rip), %rdi      # 0xafd0
leaq 0x486b(%rip), %rsi      # 0x81d6
callq 0x3270
movl 0xe0(%rsp), %eax
movl $0xf000, %ecx           # imm = 0xF000
andl %ecx, %eax
cmpl $0x4000, %eax           # imm = 0x4000
movl $0x2d, %ebp
movl $0x64, %eax
cmovel %eax, %ebp
movq %r13, 0x8(%rsp)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq %rsi, %rdx
movq %r14, %rdi
callq 0x3d68
movb %bpl, 0x28(%rsp)
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x3e88
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x39d3
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3220
movl 0xe0(%rsp), %r13d
testb %r13b, %r13b
movl $0x77, %r14d
movl $0x2d, %eax
cmovnsl %eax, %r14d
testb $0x40, %r13b
movl $0x78, %ebx
cmovel %eax, %ebx
testb $0x20, %r13b
movl $0x72, %r12d
cmovel %eax, %r12d
testb $0x10, %r13b
movl $0x77, %r15d
cmovel %eax, %r15d
testb $0x8, %r13b
movl $0x78, %ecx
cmovel %eax, %ecx
movl %ecx, 0x64(%rsp)
testb $0x4, %r13b
movl $0x72, %ecx
cmovel %eax, %ecx
movl %ecx, 0x60(%rsp)
testb $0x2, %r13b
movl $0x77, %ecx
cmovel %eax, %ecx
movl %ecx, 0x5c(%rsp)
testb $0x1, %r13b
movl $0x78, %ecx
cmovel %eax, %ecx
movl %ecx, 0x58(%rsp)
movb %bpl, 0x8(%rsp)
movl $0x1, %edx
movq 0x756a(%rip), %rdi      # 0xafd0
leaq 0x8(%rsp), %rbp
movq %rbp, %rsi
callq 0x3270
btl $0x8, %r13d
movl $0x72, %eax
movl $0x2d, %ecx
cmovael %ecx, %eax
movb %al, 0x8(%rsp)
movl $0x1, %edx
movq 0x753b(%rip), %rdi      # 0xafd0
movq %rbp, %rsi
callq 0x3270
movb %r14b, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3270
movb %bl, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3270
movb %r12b, 0x8(%rsp)
movl $0x1, %edx
movq 0x74f9(%rip), %rdi      # 0xafd0
movq %rbp, %rsi
callq 0x3270
movb %r15b, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3270
movl 0x64(%rsp), %ecx
movb %cl, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3270
movl 0x60(%rsp), %eax
movb %al, 0x8(%rsp)
movl $0x1, %edx
movq 0x74b0(%rip), %rdi      # 0xafd0
movq %rbp, %rsi
callq 0x3270
movl 0x5c(%rsp), %ecx
movb %cl, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3270
movl 0x58(%rsp), %ecx
movb %cl, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x3270
movl $0x3, %edx
movq %rax, %rdi
leaq 0x466d(%rip), %rsi      # 0x81d4
callq 0x3270
leaq 0x120(%rsp), %rdi
callq 0x30e0
testq %rax, %rax
je 0x3b9d
movq %rax, %rbx
movq %rax, %rdi
callq 0x3100
movq 0x7440(%rip), %rdi      # 0xafd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x3270
jmp 0x3bbb
movq 0x742c(%rip), %rcx      # 0xafd0
movq (%rcx), %rax
movq -0x18(%rax), %rax
leaq (%rcx,%rax), %rdi
movl 0x20(%rcx,%rax), %esi
orl $0x1, %esi
callq 0x3390
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x3bd7
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3220
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %r15
cmpq %r15, %rdi
leaq 0x98(%rsp), %r12
leaq 0x18(%rsp), %r13
je 0x3c00
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3220
movq 0xb8(%rsp), %rcx
incq %rcx
cmpq %rcx, 0xa8(%rsp)
jne 0x371b
movq 0x30(%rsp), %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3c32
movq %rax, %rbx
jmp 0x3cbb
movq %rax, %rbx
jmp 0x3ca4
jmp 0x3c80
jmp 0x3c43
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x3c83
movq 0x98(%rsp), %rsi
jmp 0x3c71
jmp 0x3c80
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x3c83
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x3220
jmp 0x3c83
movq %rax, %rbx
jmp 0x3c88
movq %rax, %rbx
leaq 0x48(%rsp), %r15
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x3ca4
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x3220
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x3cbb
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x3220
movq 0x30(%rsp), %rdi
callq 0x3d0c
movq %rbx, %rdi
callq 0x33b0
nop