// File: /workspace/github_c_makefile_star2_O3/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 %rsi, %r13
movq %rdi, %r12
movq $0x0, (%rdx)
movq %rsi, %rdi
callq 0xc690
testq %rax, %rax
je 0x6c96b
movq %rax, %rbx
movq %rax, %rdi
callq 0xc6a0
testq %rax, %rax
je 0x6c96f
movq %rax, %r15
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
cmpb $0x2e, 0x13(%r15)
jne 0x6c84f
cmpb $0x0, 0x14(%r15)
je 0x6c86e
cmpb $0x2e, 0x14(%r15)
jne 0x6c84f
cmpb $0x0, 0x15(%r15)
je 0x6c86e
addq $0x13, %r15
movq 0x2a8(%r12), %rax
movq 0x98(%rax), %rdi
movq %r15, %rsi
callq 0x6ae0b
testl %eax, %eax
je 0x6c883
movq %rbx, %rdi
callq 0xc6a0
movq %rax, %r15
testq %rax, %rax
jne 0x6c833
jmp 0x6c976
movl $0x2000, %esi           # imm = 0x2000
leaq -0x2040(%rbp), %rdi
leaq 0xc53f(%rip), %rdx      # 0x78dd5
movq %r13, %rcx
movl $0x2f, %r8d
movq %r15, %r9
xorl %eax, %eax
callq 0x6ad62
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %eax
cmpl %eax, %ecx
jl 0x6c90c
movq (%r14), %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 0x6c906
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 -0x38(%rbp), %rax
movq %rax, (%r14)
movl -0x2c(%rbp), %ecx
movl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
cmpl %eax, %ecx
jge 0x6c86e
movq (%r14), %rax
movl %ecx, -0x2c(%rbp)
movslq %ecx, %rcx
shlq $0x5, %rcx
movq %r13, -0x38(%rbp)
movq %r14, %r13
leaq (%rcx,%rcx,4), %r14
movq %r12, (%rax,%r14)
movq %r15, %rdi
callq 0xc040
movq (%r13), %rcx
movq %rax, 0x8(%rcx,%r14)
movq (%r13), %rax
leaq (%rax,%r14), %rsi
addq $0x10, %rsi
movq %r13, %r14
movq -0x38(%rbp), %r13
leaq -0x2040(%rbp), %rdi
callq 0xcb70
incl -0x2c(%rbp)
jmp 0x6c86e
xorl %eax, %eax
jmp 0x6c981
movl $0x0, -0x2c(%rbp)
movq %rbx, %rdi
callq 0xc660
movl -0x2c(%rbp), %eax
addq $0x2018, %rsp           # imm = 0x2018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq