// File: /workspace/github_c_makefile_star2_O0/Matthias-Wandel[P]imgcomp/src/util.c
// Function: GetSortedDir
DirEntry_t * GetSortedDir(char * Directory, int * NumFiles)
{
    DirEntry_t * FileNames;
    int NumFileNames;
    int NumAllocated;
    DIR * dirp;

    NumAllocated = 10;
    FileNames = malloc(sizeof (DirEntry_t) * NumAllocated);

    NumFileNames = 0;
  
    dirp = opendir(Directory);
    if (dirp == NULL){
        fprintf(Log, "could not open dir\n");
        return NULL;
    }

    for (;;){
        struct dirent * dp;
        struct stat buf;
        int l;
        dp = readdir(dirp);
        if (dp == NULL) break;
        //printf("name: %s %d %d\n",dp->d_name, (int)dp->d_off, (int)dp->d_reclen);

        // Check that it's a regular file.
        stat(CatPath(Directory, dp->d_name), &buf);
        if (!S_ISREG(buf.st_mode)) continue; // not a file.

        if (NumFileNames >= NumAllocated){
            NumAllocated *= 2;
            FileNames = realloc(FileNames, sizeof (DirEntry_t) * NumAllocated);
        }
        l = strlen(dp->d_name);
        if (l >= 40){
            printf("Filename too long %s",dp->d_name);
            continue;
        }
        strncpy(FileNames[NumFileNames].FileName,dp->d_name,40);
        FileNames[NumFileNames].MTime = buf.st_mtime;
        FileNames[NumFileNames].ATime = buf.st_atime;
        FileNames[NumFileNames].FileSize = buf.st_size;
        NumFileNames += 1;
    }
    closedir(dirp);

    // Now sort the names (could be in random order)
    qsort(FileNames, NumFileNames, sizeof(DirEntry_t), fncmpfunc);

    *NumFiles = NumFileNames;
    return FileNames;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0xa, -0x28(%rbp)
movslq -0x28(%rbp), %rax
imulq $0x50, %rax, %rdi
callq 0x3330
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3120
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0xbe5b
leaq 0x91db(%rip), %rax      # 0x15018
movq (%rax), %rdi
leaq 0x5498(%rip), %rsi      # 0x112df
movb $0x0, %al
callq 0x3290
movq $0x0, -0x8(%rbp)
jmp 0xbfb4
jmp 0xbe5d
movq -0x30(%rbp), %rdi
callq 0x3310
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0xbe76
jmp 0xbf81
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x13, %rsi
callq 0xbaa0
movq %rax, %rdi
leaq -0xc8(%rbp), %rsi
callq 0x32b0
movl -0xb0(%rbp), %eax
andl $0xf000, %eax           # imm = 0xF000
cmpl $0x8000, %eax           # imm = 0x8000
je 0xbeaa
jmp 0xbe5d
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
jl 0xbecf
movl -0x28(%rbp), %eax
shll %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movslq -0x28(%rbp), %rax
imulq $0x50, %rax, %rsi
callq 0x3390
movq %rax, -0x20(%rbp)
movq -0x38(%rbp), %rdi
addq $0x13, %rdi
callq 0x3130
movl %eax, -0xcc(%rbp)
cmpl $0x28, -0xcc(%rbp)
jl 0xbf06
movq -0x38(%rbp), %rsi
addq $0x13, %rsi
leaq 0x53f9(%rip), %rdi      # 0x112f3
movb $0x0, %al
callq 0x3170
jmp 0xbe5d
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rax
imulq $0x50, %rax, %rax
addq %rax, %rdi
addq $0x18, %rdi
movq -0x38(%rbp), %rsi
addq $0x13, %rsi
movl $0x28, %edx
callq 0x3090
movq -0x70(%rbp), %rcx
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0x80(%rbp), %rcx
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movq -0x98(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rdx
imulq $0x50, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xbe5d
movq -0x30(%rbp), %rdi
callq 0x31f0
movq -0x20(%rbp), %rdi
movslq -0x24(%rbp), %rsi
movl $0x50, %edx
leaq 0x32(%rip), %rcx        # 0xbfd0
callq 0x30d0
movl -0x24(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)