// File: attractivechaos[P]udb2/stb/./stb.h
// Function: readdir_raw
static char **readdir_raw(char *dir, int return_subdirs, char *mask)
{
   char **results = NULL;
   char buffer[4096], with_slash[4096];
   size_t n;

   #ifdef _MSC_VER
      stb__wchar *ws;
      struct _wfinddata_t data;
   #ifdef _WIN64
      const intptr_t none = -1;
      intptr_t z;
   #else
      const long none = -1;
      long z;
   #endif
   #else // !_MSC_VER
      const DIR *none = NULL;
      DIR *z;
   #endif

   n = stb_strscpy(buffer,dir,sizeof(buffer));
   if (!n || n >= sizeof(buffer))
      return NULL;
   stb_fixpath(buffer);
   n--;

   if (n > 0 && (buffer[n-1] != '/')) {
      buffer[n++] = '/';
   }
   buffer[n] = 0;
   if (!stb_strscpy(with_slash,buffer,sizeof(with_slash)))
      return NULL;

   #ifdef _MSC_VER
      if (!stb_strscpy(buffer+n,"*.*",sizeof(buffer)-n))
         return NULL;
      ws = stb__from_utf8(buffer);
      z = _wfindfirst((const wchar_t *)ws, &data);
   #else
      z = opendir(dir);
   #endif

   if (z != none) {
      int nonempty = STB_TRUE;
      #ifndef _MSC_VER
      struct dirent *data = readdir(z);
      nonempty = (data != NULL);
      #endif

      if (nonempty) {

         do {
            int is_subdir;
            #ifdef _MSC_VER
            char *name = stb__to_utf8((stb__wchar *)data.name);
            if (name == NULL) {
               fprintf(stderr, "%s to convert '%S' to %s!\n", "Unable", data.name, "utf8");
               continue;
            }
            is_subdir = !!(data.attrib & _A_SUBDIR);
            #else
            char *name = data->d_name;
            if (!stb_strscpy(buffer+n,name,sizeof(buffer)-n))
               break;
            // Could follow DT_LNK, but would need to check for recursive links.
            is_subdir = !!(data->d_type & DT_DIR);
            #endif

            if (is_subdir == return_subdirs) {
               if (!is_subdir || !isdotdirname(name)) {
                  if (!mask || stb_wildmatchi(mask, name)) {
                     char buffer[4096],*p=buffer;
                     if ( stb_snprintf(buffer, sizeof(buffer), "%s%s", with_slash, name) < 0 )
                        break;
                     if (buffer[0] == '.' && buffer[1] == '/')
                        p = buffer+2;
                     stb_arr_push(results, strdup(p));
                  }
               }
            }
         }
         #ifdef _MSC_VER
         while (0 == _wfindnext(z, &data));
         #else
         while ((data = readdir(z)) != NULL);
         #endif
      }
      #ifdef _MSC_VER
         _findclose(z);
      #else
         closedir(z);
      #endif
   }
   return results;
}

// Assembly:
subq $0x3098, %rsp           # imm = 0x3098
movq %rdi, 0x3088(%rsp)
movl %esi, 0x3084(%rsp)
movq %rdx, 0x3078(%rsp)
movq $0x0, 0x3070(%rsp)
movq $0x0, 0x1060(%rsp)
leaq 0x2070(%rsp), %rdi
movq 0x3088(%rsp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x4f40
movq %rax, 0x1068(%rsp)
cmpq $0x0, 0x1068(%rsp)
je 0xf6d1
cmpq $0x1000, 0x1068(%rsp) # imm = 0x1000
jb 0xf6e2
movq $0x0, 0x3090(%rsp)
jmp 0xfa46
leaq 0x2070(%rsp), %rdi
callq 0x66f0
movq 0x1068(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x1068(%rsp)
cmpq $0x0, 0x1068(%rsp)
jbe 0xf746
movq 0x1068(%rsp), %rax
subq $0x1, %rax
movsbl 0x2070(%rsp,%rax), %eax
cmpl $0x2f, %eax
je 0xf746
movq 0x1068(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x1068(%rsp)
movb $0x2f, 0x2070(%rsp,%rax)
movq 0x1068(%rsp), %rax
movb $0x0, 0x2070(%rsp,%rax)
leaq 0x1070(%rsp), %rdi
leaq 0x2070(%rsp), %rsi
movl $0x1000, %edx           # imm = 0x1000
callq 0x4f40
cmpq $0x0, %rax
jne 0xf787
movq $0x0, 0x3090(%rsp)
jmp 0xfa46
movq 0x3088(%rsp), %rdi
callq 0x20e0
movq %rax, 0x1058(%rsp)
movq 0x1058(%rsp), %rax
cmpq 0x1060(%rsp), %rax
je 0xfa36
movl $0x1, 0x1054(%rsp)
movq 0x1058(%rsp), %rdi
callq 0x2240
movq %rax, 0x1048(%rsp)
cmpq $0x0, 0x1048(%rsp)
setne %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x1054(%rsp)
cmpl $0x0, 0x1054(%rsp)
je 0xfa29
jmp 0xf7fa
movq 0x1048(%rsp), %rax
addq $0x13, %rax
movq %rax, 0x1038(%rsp)
leaq 0x2070(%rsp), %rdi
addq 0x1068(%rsp), %rdi
movq 0x1038(%rsp), %rsi
movl $0x1000, %edx           # imm = 0x1000
subq 0x1068(%rsp), %rdx
callq 0x4f40
cmpq $0x0, %rax
jne 0xf843
jmp 0xfa27
movq 0x1048(%rsp), %rax
movzbl 0x12(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0x1044(%rsp)
movl 0x1044(%rsp), %eax
cmpl 0x3084(%rsp), %eax
jne 0xfa06
cmpl $0x0, 0x1044(%rsp)
je 0xf89c
movq 0x1038(%rsp), %rdi
callq 0x1d660
cmpl $0x0, %eax
jne 0xfa04
cmpq $0x0, 0x3078(%rsp)
je 0xf8c5
movq 0x3078(%rsp), %rdi
movq 0x1038(%rsp), %rsi
callq 0x16f80
cmpl $0x0, %eax
je 0xfa02
leaq 0x30(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x1070(%rsp), %rcx
movq 0x1038(%rsp), %r8
movl $0x1000, %esi           # imm = 0x1000
leaq 0x106aa(%rip), %rdx     # 0x1ff9a
movb $0x0, %al
callq 0x2a20
cmpl $0x0, %eax
jge 0xf901
jmp 0xfa27
movsbl 0x30(%rsp), %eax
cmpl $0x2e, %eax
jne 0xf923
movsbl 0x31(%rsp), %eax
cmpl $0x2f, %eax
jne 0xf923
leaq 0x30(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rdi
callq 0x2390
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x3070(%rsp)
je 0xf94e
movq 0x3070(%rsp), %rax
movl -0x10(%rax), %eax
movl %eax, 0x1c(%rsp)
jmp 0xf956
xorl %eax, %eax
movl %eax, 0x1c(%rsp)
jmp 0xf956
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
cmpq $0x0, 0x3070(%rsp)
je 0xf97d
movq 0x3070(%rsp), %rax
movl -0xc(%rax), %eax
movl %eax, 0x14(%rsp)
jmp 0xf985
xorl %eax, %eax
movl %eax, 0x14(%rsp)
jmp 0xf985
movl 0x18(%rsp), %eax
movl 0x14(%rsp), %ecx
cmpl %ecx, %eax
jle 0xf9aa
leaq 0x3070(%rsp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x8030
jmp 0xf9bb
movq 0x3070(%rsp), %rax
movl -0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, -0x10(%rax)
movq 0x3070(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x3070(%rsp)
je 0xf9e4
movq 0x3070(%rsp), %rax
movl -0x10(%rax), %eax
movl %eax, 0x4(%rsp)
jmp 0xf9ec
xorl %eax, %eax
movl %eax, 0x4(%rsp)
jmp 0xf9ec
movq 0x8(%rsp), %rax
movq 0x20(%rsp), %rdx
movl 0x4(%rsp), %ecx
movslq %ecx, %rcx
movq %rdx, -0x8(%rax,%rcx,8)
jmp 0xfa04
jmp 0xfa06
jmp 0xfa08
movq 0x1058(%rsp), %rdi
callq 0x2240
movq %rax, 0x1048(%rsp)
cmpq $0x0, %rax
jne 0xf7fa
jmp 0xfa29
movq 0x1058(%rsp), %rdi
callq 0x21a0
movq 0x3070(%rsp), %rax
movq %rax, 0x3090(%rsp)
movq 0x3090(%rsp), %rax
addq $0x3098, %rsp           # imm = 0x3098
retq
nopw %cs:(%rax,%rax)