// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movq 0x350(%rsp), %r13
movq %r8, 0x50(%rsp)
movq %r9, 0x58(%rsp)
leaq 0x1b0(%rsp), %rdi
movl $0x80, %esi
movq %r13, %rdx
callq 0x32e0
testq %rax, %rax
je 0xe095
movq %r12, 0x60(%rsp)
movq %r15, 0x68(%rsp)
movq %r14, 0x70(%rsp)
movq %rbx, 0x78(%rsp)
leaq 0x7df2(%rip), %rbx      # 0x15e12
leaq 0x1b0(%rsp), %r14
leaq 0x230(%rsp), %r15
leaq 0xb0(%rsp), %r12
leaq 0x130(%rsp), %rbp
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x3420
cmpl $0x3, %eax
jne 0xe080
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x6b4a
testl %eax, %eax
jne 0xe080
leaq 0x340(%rsp), %rdi
movq %r12, %rsi
callq 0x6b4a
testl %eax, %eax
je 0xe0a9
movq %r14, %rdi
movl $0x80, %esi
movq %r13, %rdx
callq 0x32e0
testq %rax, %rax
jne 0xe040
xorl %eax, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x130(%rsp), %rbx
movq %rbx, %rdi
callq 0x3180
leaq 0x330(%rsp), %rcx
movups (%rcx), %xmm0
leaq 0x320(%rsp), %rcx
movups (%rcx), %xmm1
leaq 0x2f0(%rsp), %rcx
movups (%rcx), %xmm2
leaq 0x310(%rsp), %rcx
movups (%rcx), %xmm3
leaq 0x80(%rsp), %r15
movq %r15, 0x40(%rsp)
movups %xmm3, 0x30(%rsp)
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0x60(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
movq %rbx, %r8
movq %rax, %r9
callq 0xdbe9
leaq 0x7cf6(%rip), %rsi      # 0x15e21
leaq 0x749c(%rip), %rdx      # 0x155ce
movl $0x3, %edi
callq 0x4447
leaq 0x300(%rsp), %rcx
movq (%rcx), %rbx
testl %eax, %eax
je 0xe17a
movl 0x58(%rsp), %esi
movq 0x50(%rsp), %rdx
movq 0x8(%rcx), %r14
movq %r15, (%rsp)
leaq 0x7cd3(%rip), %rdi      # 0x15e36
leaq 0xb0(%rsp), %rcx
movl %r14d, %r8d
movq %rbx, %r9
xorl %eax, %eax
callq 0x4539
jmp 0xe17e
movq 0x8(%rcx), %r14
leaq 0x80(%rsp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x6bc6
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
sete %al
jmp 0xe097