// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_check_digest_auth
int mg_check_digest_auth(struct mg_str method, struct mg_str uri,
                         struct mg_str username, struct mg_str cnonce,
                         struct mg_str response, struct mg_str qop,
                         struct mg_str nc, struct mg_str nonce,
                         struct mg_str auth_domain, FILE *fp) {
  char buf[128], f_user[sizeof(buf)], f_ha1[sizeof(buf)], f_domain[sizeof(buf)];
  char expected_response[33];

  /*
   * Read passwords file line by line. If should have htdigest format,
   * i.e. each line should be a colon-separated sequence:
   * USER_NAME:DOMAIN_NAME:HA1_HASH_OF_USER_DOMAIN_AND_PASSWORD
   */
  while (fgets(buf, sizeof(buf), fp) != NULL) {
    if (sscanf(buf, "%[^:]:%[^:]:%s", f_user, f_domain, f_ha1) == 3 &&
        mg_vcmp(&username, f_user) == 0 &&
        mg_vcmp(&auth_domain, f_domain) == 0) {
      /* Username and domain matched, check the password */
      mg_mkmd5resp(method.p, method.len, uri.p, uri.len, f_ha1, strlen(f_ha1),
                   nonce.p, nonce.len, nc.p, nc.len, cnonce.p, cnonce.len,
                   qop.p, qop.len, expected_response);
      LOG(LL_DEBUG,
          ("%.*s %s %.*s %s", (int) username.len, username.p, f_domain,
           (int) response.len, response.p, expected_response));
      return mg_ncasecmp(response.p, expected_response, response.len) == 0;
    }
  }

  /* None of the entries in the passwords file matched - return failure */
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movq 0x70(%rbp), %rax
leaq 0x60(%rbp), %rax
movq %rax, -0x2c0(%rbp)
leaq 0x50(%rbp), %rax
movq %rax, -0x2b8(%rbp)
leaq 0x40(%rbp), %rax
movq %rax, -0x2b0(%rbp)
leaq 0x30(%rbp), %rax
movq %rax, -0x2a8(%rbp)
leaq 0x20(%rbp), %rax
movq %rax, -0x2a0(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x298(%rbp)
movq %rdi, -0x40(%rbp)
movq %rsi, -0x38(%rbp)
movq %rdx, -0x50(%rbp)
movq %rcx, -0x48(%rbp)
movq %r8, -0x60(%rbp)
movq %r9, -0x58(%rbp)
leaq -0xe0(%rbp), %rdi
movq 0x70(%rbp), %rdx
movl $0x80, %esi
callq 0x3310
cmpq $0x0, %rax
je 0x13d5a
leaq -0xe0(%rbp), %rdi
leaq -0x160(%rbp), %rdx
leaq -0x260(%rbp), %rcx
leaq -0x1e0(%rbp), %r8
leaq 0xc1fd(%rip), %rsi      # 0x1fd91
movb $0x0, %al
callq 0x3460
cmpl $0x3, %eax
jne 0x13d55
leaq -0x160(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x8ad0
cmpl $0x0, %eax
jne 0x13d55
movq -0x2c0(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x8ad0
cmpl $0x0, %eax
jne 0x13d55
movq -0x2b8(%rbp), %rbx
movq -0x40(%rbp), %rax
movq %rax, -0x2f8(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x2f0(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x2e8(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x2e0(%rbp)
leaq -0x1e0(%rbp), %rax
movq %rax, -0x2d8(%rbp)
leaq -0x1e0(%rbp), %rdi
callq 0x3180
movq -0x2b0(%rbp), %r11
movq -0x298(%rbp), %r10
movq -0x2f8(%rbp), %rdi
movq -0x2f0(%rbp), %rsi
movq -0x2e8(%rbp), %rdx
movq -0x2e0(%rbp), %rcx
movq -0x2d8(%rbp), %r8
movq %rax, %r9
movq -0x2a8(%rbp), %rax
movq (%rbx), %r14
movq %r14, -0x2d0(%rbp)
movq 0x8(%rbx), %r13
movq (%r11), %r12
movq 0x8(%r11), %r15
movq (%r10), %r14
movq 0x8(%r10), %rbx
movq (%rax), %r11
movq 0x8(%rax), %r10
leaq -0x290(%rbp), %rax
movq %rax, -0x2c8(%rbp)
movq -0x2d0(%rbp), %rax
movq %rax, (%rsp)
movq -0x2c8(%rbp), %rax
movq %r13, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq %rbx, 0x28(%rsp)
movq %r11, 0x30(%rsp)
movq %r10, 0x38(%rsp)
movq %rax, 0x40(%rsp)
callq 0x13560
movl $0x3, %edi
leaq 0xc0c3(%rip), %rsi      # 0x1fda0
leaq 0xb866(%rip), %rdx      # 0x1f54a
callq 0x4650
cmpl $0x0, %eax
je 0x13d29
movq -0x2a0(%rbp), %rax
movq -0x58(%rbp), %rcx
movl %ecx, %esi
movq -0x60(%rbp), %rdx
leaq -0x260(%rbp), %rcx
movq 0x8(%rax), %rdi
movl %edi, %r8d
movq (%rax), %r9
leaq -0x290(%rbp), %rax
leaq 0xc097(%rip), %rdi      # 0x1fdb5
movq %rax, (%rsp)
movb $0x0, %al
callq 0x47a0
jmp 0x13d2b
movq -0x2a0(%rbp), %rax
movq (%rax), %rdi
leaq -0x290(%rbp), %rsi
movq 0x8(%rax), %rdx
callq 0x8bf0
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x2c(%rbp)
jmp 0x13d61
jmp 0x13b52
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopw %cs:(%rax,%rax)