// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: scan_directory
static int scan_directory(struct connection *conn, const char *dir,
                          struct dir_entry **arr) {
  char path[MAX_PATH_SIZE];
  struct dir_entry *p;
  struct dirent *dp;
  int arr_size = 0, arr_ind = 0, inc = 100;
  DIR *dirp;

  *arr = NULL;
  if ((dirp = (opendir(dir))) == NULL) return 0;

  while ((dp = readdir(dirp)) != NULL) {
    // Do not show current dir and hidden files
    if (!strcmp(dp->d_name, ".") ||
        !strcmp(dp->d_name, "..") ||
        must_hide_file(conn, dp->d_name)) {
      continue;
    }
    mg_snprintf(path, sizeof(path), "%s%c%s", dir, '/', dp->d_name);

    // Resize the array if necessary
    if (arr_ind >= arr_size) {
      if ((p = (struct dir_entry *)
           NS_REALLOC(*arr, (inc + arr_size) * sizeof(**arr))) != NULL) {
        // Memset new chunk to zero, otherwise st_mtime will have garbage which
        // can make strftime() segfault, see
        // http://code.google.com/p/mongoose/issues/detail?id=79
        memset(p + arr_size, 0, sizeof(**arr) * inc);

        *arr = p;
        arr_size += inc;
      }
    }

    if (arr_ind < arr_size) {
      (*arr)[arr_ind].conn = conn;
      (*arr)[arr_ind].file_name = strdup(dp->d_name);
      stat(path, &(*arr)[arr_ind].st);
      arr_ind++;
    }
  }
  closedir(dirp);

  return arr_ind;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2050, %rsp           # imm = 0x2050
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x2034(%rbp)
movl $0x0, -0x2038(%rbp)
movl $0x64, -0x203c(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rdi
callq 0xd7c0
movq %rax, -0x2048(%rbp)
cmpq $0x0, %rax
jne 0xb73d2
movl $0x0, -0x4(%rbp)
jmp 0xb75af
jmp 0xb73d4
movq -0x2048(%rbp), %rdi
callq 0xd7d0
movq %rax, -0x2030(%rbp)
cmpq $0x0, %rax
je 0xb759a
movq -0x2030(%rbp), %rdi
addq $0x13, %rdi
leaq 0x8896(%rip), %rsi      # 0xbfc99
callq 0xdab0
cmpl $0x0, %eax
je 0xb7442
movq -0x2030(%rbp), %rdi
addq $0x13, %rdi
leaq 0x8879(%rip), %rsi      # 0xbfc98
callq 0xdab0
cmpl $0x0, %eax
je 0xb7442
movq -0x10(%rbp), %rdi
movq -0x2030(%rbp), %rsi
addq $0x13, %rsi
callq 0xb3d00
cmpl $0x0, %eax
je 0xb7444
jmp 0xb73d4
leaq -0x2020(%rbp), %rdi
movq -0x18(%rbp), %rcx
movq -0x2030(%rbp), %r9
addq $0x13, %r9
movl $0x2000, %esi           # imm = 0x2000
leaq 0x10256(%rip), %rdx     # 0xc76bc
movl $0x2f, %r8d
movb $0x0, %al
callq 0xb3c50
movl -0x2038(%rbp), %eax
cmpl -0x2034(%rbp), %eax
jl 0xb74fe
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movl -0x203c(%rbp), %eax
addl -0x2034(%rbp), %eax
cltq
imulq $0xa0, %rax, %rsi
callq 0xd160
movq %rax, -0x2028(%rbp)
cmpq $0x0, %rax
je 0xb74fc
movq -0x2028(%rbp), %rdi
movslq -0x2034(%rbp), %rax
imulq $0xa0, %rax, %rax
addq %rax, %rdi
movslq -0x203c(%rbp), %rax
imulq $0xa0, %rax, %rdx
xorl %esi, %esi
callq 0xd430
movq -0x2028(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movl -0x203c(%rbp), %eax
addl -0x2034(%rbp), %eax
movl %eax, -0x2034(%rbp)
jmp 0xb74fe
movl -0x2038(%rbp), %eax
cmpl -0x2034(%rbp), %eax
jge 0xb7595
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movslq -0x2038(%rbp), %rdx
imulq $0xa0, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x2030(%rbp), %rdi
addq $0x13, %rdi
callq 0xd040
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movslq -0x2038(%rbp), %rdx
imulq $0xa0, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
leaq -0x2020(%rbp), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
movslq -0x2038(%rbp), %rax
imulq $0xa0, %rax, %rax
addq %rax, %rsi
addq $0x10, %rsi
callq 0xdd10
movl -0x2038(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2038(%rbp)
jmp 0xb73d4
movq -0x2048(%rbp), %rdi
callq 0xd780
movl -0x2038(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x2050, %rsp           # imm = 0x2050
popq %rbp
retq
nopl (%rax,%rax)