// File: /workspace/github_c_makefile_star2_O0/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: find_index_file
static int find_index_file(struct connection *conn, char *path,
                           size_t path_len, file_stat_t *stp) {
  const char *list = conn->server->config_options[INDEX_FILES];
  file_stat_t st;
  struct vec filename_vec;
  size_t n = strlen(path);
  int found = 0;

  // The 'path' given to us points to the directory. Remove all trailing
  // directory separator characters from the end of the path, and
  // then append single directory separator character.
  while (n > 0 && path[n - 1] == '/') {
    n--;
  }
  path[n] = '/';

  // Traverse index files list. For each entry, append it to the given
  // path and see if the file exists. If it exists, break the loop
  while ((list = next_option(list, &filename_vec, NULL)) != NULL) {

    if (path_len <= n + 2) {
      continue;
    }

    // Ignore too long entries that may overflow path buffer
    if (filename_vec.len > (path_len - (n + 2)))
      continue;

    // Prepare full path to the index file
    strncpy(path + n + 1, filename_vec.ptr, filename_vec.len);
    path[n + 1 + filename_vec.len] = '\0';

    //DBG(("[%s]", path));

    // Does it exist?
    if (!stat(path, &st)) {
      // Yes it does, break the loop
      *stp = st;
      found = 1;
      break;
    }
  }

  // If no index file exists, restore directory path
  if (!found) {
    path[n] = '/';
    path[n + 1] = '\0';
  }

  return found;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x2a8(%rax), %rax
movq 0xa8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0xd550
movq %rax, -0xd0(%rbp)
movl $0x0, -0xd4(%rbp)
xorl %eax, %eax
cmpq $0x0, -0xd0(%rbp)
movb %al, -0xd5(%rbp)
jbe 0xb416c
movq -0x10(%rbp), %rax
movq -0xd0(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
sete %al
movb %al, -0xd5(%rbp)
movb -0xd5(%rbp), %al
testb $0x1, %al
jne 0xb4178
jmp 0xb418c
movq -0xd0(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0xd0(%rbp)
jmp 0xb413b
movq -0x10(%rbp), %rax
movq -0xd0(%rbp), %rcx
movb $0x2f, (%rax,%rcx)
movq -0x28(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xb5ad0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
je 0xb426a
movq -0x18(%rbp), %rax
movq -0xd0(%rbp), %rcx
addq $0x2, %rcx
cmpq %rcx, %rax
ja 0xb41d3
jmp 0xb419b
movq -0xc0(%rbp), %rax
movq -0x18(%rbp), %rcx
movq -0xd0(%rbp), %rdx
addq $0x2, %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jbe 0xb41f3
jmp 0xb419b
movq -0x10(%rbp), %rdi
addq -0xd0(%rbp), %rdi
addq $0x1, %rdi
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
callq 0xd240
movq -0x10(%rbp), %rax
movq -0xd0(%rbp), %rcx
addq $0x1, %rcx
addq -0xc0(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x10(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0xdd10
cmpl $0x0, %eax
jne 0xb4265
movq -0x20(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
movl $0x90, %edx
callq 0xd100
movl $0x1, -0xd4(%rbp)
jmp 0xb426a
jmp 0xb419b
cmpl $0x0, -0xd4(%rbp)
jne 0xb4292
movq -0x10(%rbp), %rax
movq -0xd0(%rbp), %rcx
movb $0x2f, (%rax,%rcx)
movq -0x10(%rbp), %rax
movq -0xd0(%rbp), %rcx
movb $0x0, 0x1(%rax,%rcx)
movl -0xd4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)