// File: 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
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x3c8(%rbp)
movb %dl, %al
movq %rdi, %rcx
movq %rcx, -0x3d0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %al, -0x11(%rbp)
leaq 0x7724(%rip), %rdi      # 0xb004
xorl %eax, %eax
movl %eax, -0x3bc(%rbp)
callq 0x3030
movq -0x3c8(%rbp), %rdi
movb $0x0, -0x12(%rbp)
callq 0x3f10
movl -0x3bc(%rbp), %eax
movq -0x10(%rbp), %rdi
movq 0xc6ba(%rip), %rcx      # 0xffc8
movl %eax, %edx
leaq -0x28(%rbp), %rsi
callq 0x3050
movl %eax, -0x3b8(%rbp)
jmp 0x3921
movl -0x3b8(%rbp), %eax
movl %eax, -0x2d4(%rbp)
movl $0x0, -0x2e8(%rbp)
movl -0x2e8(%rbp), %eax
cmpl -0x2d4(%rbp), %eax
jge 0x3ecf
movq -0x28(%rbp), %rax
movslq -0x2e8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq $0x13, %rax
movq %rax, -0x3e0(%rbp)
leaq -0x309(%rbp), %rdi
movq %rdi, -0x3d8(%rbp)
callq 0x3520
movq -0x3e0(%rbp), %rsi
movq -0x3d8(%rbp), %rdx
leaq -0x308(%rbp), %rdi
callq 0x3f30
jmp 0x3992
leaq -0x309(%rbp), %rdi
callq 0x3340
leaq -0x308(%rbp), %rdi
callq 0x3110
movq %rax, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x32b0
movq -0x10(%rbp), %rax
movq %rax, -0x3f0(%rbp)
leaq -0x331(%rbp), %rdi
movq %rdi, -0x3e8(%rbp)
callq 0x3520
movq -0x3f0(%rbp), %rsi
movq -0x3e8(%rbp), %rdx
leaq -0x330(%rbp), %rdi
callq 0x3f30
jmp 0x39f3
leaq -0x331(%rbp), %rdi
callq 0x3340
leaq 0x76fb(%rip), %rdx      # 0xb101
leaq -0x378(%rbp), %rdi
leaq -0x330(%rbp), %rsi
callq 0x4030
jmp 0x3a1b
leaq -0x358(%rbp), %rdi
leaq -0x378(%rbp), %rsi
leaq -0x308(%rbp), %rdx
callq 0x3fe0
jmp 0x3a37
leaq -0x330(%rbp), %rdi
leaq -0x358(%rbp), %rsi
movq %rsi, -0x400(%rbp)
callq 0x33b0
movq -0x400(%rbp), %rdi
callq 0x35b8
leaq -0x378(%rbp), %rdi
callq 0x35b8
movq 0xc560(%rip), %rdi      # 0xffd0
leaq -0x308(%rbp), %rsi
callq 0x32a0
movq %rax, -0x3f8(%rbp)
jmp 0x3a85
movq -0x3f8(%rbp), %rdi
leaq 0x76ee(%rip), %rsi      # 0xb181
callq 0x32d0
jmp 0x3a9a
movq -0x88(%rbp), %rsi
movq 0xc528(%rip), %rdi      # 0xffd0
callq 0x3550
movq %rax, -0x408(%rbp)
jmp 0x3ab6
movq -0x408(%rbp), %rdi
leaq 0x76bb(%rip), %rsi      # 0xb17f
callq 0x32d0
jmp 0x3acb
movl -0x9c(%rbp), %edi
callq 0x33a0
movq %rax, -0x410(%rbp)
jmp 0x3adf
movq -0x410(%rbp), %rax
movq %rax, -0x2c8(%rbp)
movl -0x98(%rbp), %edi
callq 0x34d0
movq %rax, -0x418(%rbp)
jmp 0x3b01
movq -0x418(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0x2c8(%rbp), %rax
movq (%rax), %rsi
movq 0xc4b0(%rip), %rdi      # 0xffd0
callq 0x32d0
movq %rax, -0x420(%rbp)
jmp 0x3b2e
movq -0x420(%rbp), %rdi
leaq 0x7646(%rip), %rsi      # 0xb182
callq 0x32d0
movq %rax, -0x428(%rbp)
jmp 0x3b4a
movq -0x428(%rbp), %rdi
movq -0x2d0(%rbp), %rax
movq (%rax), %rsi
callq 0x32d0
movq %rax, -0x430(%rbp)
jmp 0x3b69
movq -0x430(%rbp), %rdi
leaq 0x760b(%rip), %rsi      # 0xb182
callq 0x32d0
jmp 0x3b7e
movl -0xa0(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
subl $0x4000, %eax           # imm = 0x4000
movl $0x64, %ecx
movl $0x2d, %eax
cmovel %ecx, %eax
movb %al, -0x379(%rbp)
leaq -0x3a8(%rbp), %rdi
leaq -0x330(%rbp), %rsi
leaq -0x379(%rbp), %rdx
callq 0x40e0
jmp 0x3bbd
movq -0x3c8(%rbp), %rdi
leaq -0x3a8(%rbp), %rsi
callq 0x40b0
jmp 0x3bd2
leaq -0x3a8(%rbp), %rdi
callq 0x4120
movl -0xa0(%rbp), %eax
testl $0x100, %eax            # imm = 0x100
movl $0x72, %edi
movl $0x2d, %eax
movl %eax, -0x434(%rbp)
movl %eax, %ecx
cmovnel %edi, %ecx
movb %cl, -0x3a9(%rbp)
movb -0xa0(%rbp), %cl
testb %cl, %cl
movl $0x77, %esi
movl %eax, %ecx
cmovsl %esi, %ecx
movb %cl, -0x3aa(%rbp)
movl -0xa0(%rbp), %ecx
testb $0x40, %cl
movl $0x78, %ecx
movl %eax, %edx
cmovnel %ecx, %edx
movb %dl, -0x3ab(%rbp)
movl -0xa0(%rbp), %edx
testb $0x20, %dl
movl %eax, %edx
cmovnel %edi, %edx
movb %dl, -0x3ac(%rbp)
movl -0xa0(%rbp), %edx
testb $0x10, %dl
movl %eax, %edx
cmovnel %esi, %edx
movb %dl, -0x3ad(%rbp)
movl -0xa0(%rbp), %edx
testb $0x8, %dl
movl %eax, %edx
cmovnel %ecx, %edx
movb %dl, -0x3ae(%rbp)
movl -0xa0(%rbp), %edx
testb $0x4, %dl
movl %eax, %edx
cmovnel %edi, %edx
movb %dl, -0x3af(%rbp)
movl -0xa0(%rbp), %edx
testb $0x2, %dl
movl %eax, %edx
cmovnel %esi, %edx
movb %dl, -0x3b0(%rbp)
movb -0xa0(%rbp), %dl
testb $0x1, %dl
cmovnel %ecx, %eax
movb %al, -0x3b1(%rbp)
movsbl -0x379(%rbp), %esi
movq 0xc317(%rip), %rdi      # 0xffd0
callq 0x3390
jmp 0x3cc0
movsbl -0x3a9(%rbp), %esi
movq 0xc302(%rip), %rdi      # 0xffd0
callq 0x3390
movq %rax, -0x440(%rbp)
jmp 0x3cdc
movq -0x440(%rbp), %rdi
movsbl -0x3aa(%rbp), %esi
callq 0x3390
movq %rax, -0x448(%rbp)
jmp 0x3cf8
movq -0x448(%rbp), %rdi
movsbl -0x3ab(%rbp), %esi
callq 0x3390
jmp 0x3d0d
movsbl -0x3ac(%rbp), %esi
movq 0xc2b5(%rip), %rdi      # 0xffd0
callq 0x3390
movq %rax, -0x450(%rbp)
jmp 0x3d29
movq -0x450(%rbp), %rdi
movsbl -0x3ad(%rbp), %esi
callq 0x3390
movq %rax, -0x458(%rbp)
jmp 0x3d45
movq -0x458(%rbp), %rdi
movsbl -0x3ae(%rbp), %esi
callq 0x3390
jmp 0x3d5a
movsbl -0x3af(%rbp), %esi
movq 0xc268(%rip), %rdi      # 0xffd0
callq 0x3390
movq %rax, -0x460(%rbp)
jmp 0x3d76
movq -0x460(%rbp), %rdi
movsbl -0x3b0(%rbp), %esi
callq 0x3390
movq %rax, -0x468(%rbp)
jmp 0x3d92
movq -0x468(%rbp), %rdi
movsbl -0x3b1(%rbp), %esi
callq 0x3390
movq %rax, -0x470(%rbp)
jmp 0x3dae
movq -0x470(%rbp), %rdi
leaq 0x73c4(%rip), %rsi      # 0xb180
callq 0x32d0
jmp 0x3dc3
leaq -0x60(%rbp), %rdi
callq 0x30f0
movq %rax, %rsi
movq 0xc1fa(%rip), %rdi      # 0xffd0
callq 0x32d0
jmp 0x3ddd
leaq -0x330(%rbp), %rdi
callq 0x35b8
leaq -0x308(%rbp), %rdi
callq 0x35b8
movl -0x2e8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2e8(%rbp)
jmp 0x3937
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e0(%rbp)
movl %eax, -0x2e4(%rbp)
jmp 0x3ef5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e0(%rbp)
movl %eax, -0x2e4(%rbp)
leaq -0x309(%rbp), %rdi
callq 0x3340
jmp 0x3ef5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e0(%rbp)
movl %eax, -0x2e4(%rbp)
leaq -0x331(%rbp), %rdi
callq 0x3340
jmp 0x3ec1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e0(%rbp)
movl %eax, -0x2e4(%rbp)
jmp 0x3eb5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e0(%rbp)
movl %eax, -0x2e4(%rbp)
leaq -0x378(%rbp), %rdi
callq 0x35b8
jmp 0x3eb5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x2e0(%rbp)
movl %eax, -0x2e4(%rbp)
leaq -0x3a8(%rbp), %rdi
callq 0x4120
leaq -0x330(%rbp), %rdi
callq 0x35b8
leaq -0x308(%rbp), %rdi
callq 0x35b8
jmp 0x3ef5
movb $0x1, -0x12(%rbp)
testb $0x1, -0x12(%rbp)
jne 0x3ee5
movq -0x3c8(%rbp), %rdi
callq 0x4140
movq -0x3d0(%rbp), %rax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq
movq -0x3c8(%rbp), %rdi
callq 0x4140
movq -0x2e0(%rbp), %rdi
callq 0x3510
nopl (%rax)