// File: /workspace/github_c_makefile_star2_O2/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 $0x2018, %rsp           # imm = 0x2018
movq %rdx, %r14
movq %rdi, %r15
andq $0x0, (%rdx)
movq %rsi, -0x40(%rbp)
movq %rsi, %rdi
callq 0xc6b0
testq %rax, %rax
je 0x5d4ea
movq %rax, %r12
xorl %ecx, %ecx
xorl %r13d, %r13d
movl %ecx, -0x2c(%rbp)
movq %r12, %rdi
callq 0xc6c0
testq %rax, %rax
je 0x5d4dd
movq %rax, %rbx
cmpb $0x2e, 0x13(%rax)
jne 0x5d3e7
cmpb $0x0, 0x14(%rbx)
je 0x5d3bb
cmpb $0x2e, 0x14(%rbx)
jne 0x5d3e7
cmpb $0x0, 0x15(%rbx)
je 0x5d3bb
addq $0x13, %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x5bd11
testl %eax, %eax
jne 0x5d3bb
movl $0x2000, %esi           # imm = 0x2000
leaq -0x2040(%rbp), %rdi
leaq 0xb9a8(%rip), %rdx      # 0x68db5
movq -0x40(%rbp), %rcx
pushq $0x2f
popq %r8
movq %rbx, %r9
xorl %eax, %eax
callq 0x5bc9e
movq %r13, %rax
movl -0x2c(%rbp), %ecx
cmpl %eax, %ecx
jl 0x5d480
movq (%r14), %rdi
leal 0x64(%rax), %ecx
movq %rax, %r13
movl %ecx, -0x38(%rbp)
movslq %ecx, %rax
imulq $0xa0, %rax, %rsi
callq 0xc130
movq %r14, %rcx
testq %rax, %rax
je 0x5d477
movq %rax, %r14
movslq %r13d, %rax
imulq $0xa0, %rax, %rdi
addq %r14, %rdi
movl $0x3e80, %edx           # imm = 0x3E80
xorl %esi, %esi
movq %rcx, %r13
callq 0xc370
movq %r14, (%r13)
movl -0x38(%rbp), %eax
movq %r13, %r14
jmp 0x5d47d
movq %rcx, %r14
movq %r13, %rax
movl -0x2c(%rbp), %ecx
movq %rax, %r13
cmpl %eax, %ecx
jge 0x5d3bb
movq (%r14), %rax
movl -0x2c(%rbp), %ecx
movq %r14, -0x38(%rbp)
imulq $0xa0, %rcx, %r14
movq %r15, (%rax,%r14)
movq %rbx, %rdi
callq 0xc040
movq -0x38(%rbp), %rcx
movq (%rcx), %rcx
movq %rax, 0x8(%rcx,%r14)
movq -0x38(%rbp), %rax
movq (%rax), %rax
leaq (%rax,%r14), %rsi
addq $0x10, %rsi
movq -0x38(%rbp), %r14
leaq -0x2040(%rbp), %rdi
callq 0xcba0
movl -0x2c(%rbp), %ecx
incl %ecx
jmp 0x5d3b8
movq %r12, %rdi
callq 0xc680
movl -0x2c(%rbp), %eax
jmp 0x5d4ec
xorl %eax, %eax
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq