// File: nilnilnil[P]autocomplete/deps/mongoose/mongoose.c
// Function: open_auth_file
static FILE *open_auth_file(struct mg_connection *conn, const char *path) {
  struct mg_context *ctx = conn->ctx;
  char name[PATH_MAX];
  const char *p, *e;
  struct mgstat st;
  FILE *fp;

  if (ctx->config[GLOBAL_PASSWORDS_FILE] != NULL) {
    // Use global passwords file
    fp =  mg_fopen(ctx->config[GLOBAL_PASSWORDS_FILE], "r");
    if (fp == NULL)
      cry(fc(ctx), "fopen(%s): %s",
          ctx->config[GLOBAL_PASSWORDS_FILE], strerror(ERRNO));
  } else if (!mg_stat(path, &st) && st.is_directory) {
    (void) mg_snprintf(conn, name, sizeof(name), "%s%c%s",
        path, DIRSEP, PASSWORDS_FILE_NAME);
    fp = mg_fopen(name, "r");
  } else {
     // Try to find .htpasswd in requested directory.
    for (p = path, e = p + strlen(p) - 1; e > p; e--)
      if (IS_DIRSEP_CHAR(*e))
        break;
    (void) mg_snprintf(conn, name, sizeof(name), "%.*s%c%s",
        (int) (e - p), p, DIRSEP, PASSWORDS_FILE_NAME);
    fp = mg_fopen(name, "r");
  }

  return fp;
}

// Assembly:
subq $0x1078, %rsp           # imm = 0x1078
movq %rdi, 0x1070(%rsp)
movq %rsi, 0x1068(%rsp)
movq 0x1070(%rsp), %rax
movq 0x458(%rax), %rax
movq %rax, 0x1060(%rsp)
movq 0x1060(%rsp), %rax
cmpq $0x0, 0x68(%rax)
je 0x1f121
movq 0x1060(%rsp), %rax
movq 0x68(%rax), %rdi
leaq 0x48ce(%rip), %rsi      # 0x2398e
callq 0x56b0
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x1f11c
movq 0x1060(%rsp), %rdi
callq 0x18750
movq %rax, 0x20(%rsp)
movq 0x1060(%rsp), %rax
movq 0x68(%rax), %rax
movq %rax, 0x28(%rsp)
callq 0x5060
movl (%rax), %edi
callq 0x5190
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rdx
movq %rax, %rcx
leaq 0x47e1(%rip), %rsi      # 0x238f6
movb $0x0, %al
callq 0x184e0
jmp 0x1f255
movq 0x1068(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x1a8a0
cmpl $0x0, %eax
jne 0x1f193
cmpl $0x0, 0x38(%rsp)
je 0x1f193
movq 0x1070(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq 0x1068(%rsp), %r8
movl $0x1000, %edx           # imm = 0x1000
leaq 0x4038(%rip), %rcx      # 0x23198
movl $0x2f, %r9d
leaq 0x3f40(%rip), %rax      # 0x230ad
movq %rax, (%rsp)
movb $0x0, %al
callq 0x1cc90
leaq 0x60(%rsp), %rdi
leaq 0x480a(%rip), %rsi      # 0x2398e
callq 0x56b0
movq %rax, 0x30(%rsp)
jmp 0x1f253
movq 0x1068(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rdi
callq 0x5230
movq %rax, %rcx
movq 0x18(%rsp), %rax
addq %rcx, %rax
addq $-0x1, %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq 0x58(%rsp), %rax
jbe 0x1f1f5
movq 0x50(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0x1f1e3
jmp 0x1f1f5
jmp 0x1f1e5
movq 0x50(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x1f1c8
movq 0x1070(%rsp), %rdi
leaq 0x60(%rsp), %rsi
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
subq %rcx, %rax
movl %eax, %r8d
movq 0x58(%rsp), %r9
movl $0x1000, %edx           # imm = 0x1000
leaq 0x3f7c(%rip), %rcx      # 0x2319f
leaq 0x3e83(%rip), %rax      # 0x230ad
movl $0x2f, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x1cc90
leaq 0x60(%rsp), %rdi
leaq 0x4745(%rip), %rsi      # 0x2398e
callq 0x56b0
movq %rax, 0x30(%rsp)
jmp 0x1f255
movq 0x30(%rsp), %rax
addq $0x1078, %rsp           # imm = 0x1078
retq
nopw %cs:(%rax,%rax)