// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2028, %rsp           # imm = 0x2028
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq $0x0, (%rdx)
movq %rsi, %rdi
callq 0xc690
testq %rax, %rax
je 0x6e50e
movq %rax, %rbx
movq %rax, %rdi
callq 0xc6a0
testq %rax, %rax
je 0x6e512
movq %rax, %r13
movq %r15, -0x48(%rbp)
movq %r14, -0x40(%rbp)
leaq 0x5914(%rip), %r15      # 0x73cd7
leaq 0x590c(%rip), %r14      # 0x73cd6
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
addq $0x13, %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0xc950
testl %eax, %eax
je 0x6e409
movq %r13, %rdi
movq %r14, %rsi
callq 0xc950
testl %eax, %eax
je 0x6e409
movq %r12, %rdi
movq %r13, %rsi
callq 0x6c6d9
testl %eax, %eax
je 0x6e41e
movq %rbx, %rdi
callq 0xc6a0
movq %rax, %r13
testq %rax, %rax
jne 0x6e3d8
jmp 0x6e519
movl $0x2000, %esi           # imm = 0x2000
leaq -0x2050(%rbp), %rdi
leaq 0xc9a4(%rip), %rdx      # 0x7add5
movq -0x48(%rbp), %rcx
movl $0x2f, %r8d
movq %r13, %r9
xorl %eax, %eax
callq 0x6c630
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %eax
cmpl %eax, %ecx
jl 0x6e4b0
movq -0x40(%rbp), %rcx
movq (%rcx), %rdi
movslq %eax, %rcx
movl %eax, -0x30(%rbp)
movq %rcx, %rax
movq %rcx, -0x38(%rbp)
shlq $0x5, %rax
leaq (%rax,%rax,4), %rsi
addq $0x3e80, %rsi           # imm = 0x3E80
callq 0xc120
testq %rax, %rax
je 0x6e4aa
addl $0x64, -0x30(%rbp)
movq -0x38(%rbp), %rcx
leaq (%rcx,%rcx,4), %rdi
shlq $0x5, %rdi
addq %rax, %rdi
movl $0x3e80, %edx           # imm = 0x3E80
xorl %esi, %esi
movq %rax, -0x38(%rbp)
callq 0xc360
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, (%rax)
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
cmpl %eax, %ecx
jge 0x6e409
movq -0x40(%rbp), %rax
movq (%rax), %rax
movl %ecx, -0x2c(%rbp)
movslq %ecx, %rcx
shlq $0x5, %rcx
leaq (%rcx,%rcx,4), %rcx
movq %rcx, -0x38(%rbp)
movq %r12, (%rax,%rcx)
movq %r13, %rdi
callq 0xc040
movq -0x40(%rbp), %rdx
movq (%rdx), %rcx
movq -0x38(%rbp), %rsi
movq %rax, 0x8(%rcx,%rsi)
movq (%rdx), %rax
addq %rax, %rsi
addq $0x10, %rsi
leaq -0x2050(%rbp), %rdi
callq 0xcb70
incl -0x2c(%rbp)
jmp 0x6e409
xorl %eax, %eax
jmp 0x6e524
movl $0x0, -0x2c(%rbp)
movq %rbx, %rdi
callq 0xc660
movl -0x2c(%rbp), %eax
addq $0x2028, %rsp           # imm = 0x2028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq