// File: /workspace/github_c_makefile_star2_O2/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, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdi, 0x50(%rsp)
movq 0x350(%rsp), %r13
leaq 0x70(%rsp), %rax
movq %r8, (%rax)
movq %r9, 0x8(%rax)
leaq 0x230(%rsp), %r15
leaq 0x7afb(%rip), %r12      # 0x14df5
leaq 0x1b0(%rsp), %rbx
leaq 0xb0(%rsp), %rbp
leaq 0x130(%rsp), %r14
movq %r15, %rdi
movl $0x80, %esi
movq %r13, %rdx
callq 0x32e0
testq %rax, %rax
je 0xd43a
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x3420
cmpl $0x3, %eax
jne 0xd312
leaq 0x70(%rsp), %rdi
movq %rbx, %rsi
callq 0x6899
testl %eax, %eax
jne 0xd312
leaq 0x340(%rsp), %rdi
movq %rbp, %rsi
callq 0x6899
testl %eax, %eax
jne 0xd312
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 0x50(%rsp), %rdi
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq %rbx, %r8
movq %rax, %r9
callq 0xcf05
leaq 0x7a17(%rip), %rsi      # 0x14e04
leaq 0x71ba(%rip), %rdx      # 0x145ae
pushq $0x3
popq %rdi
callq 0x4227
leaq 0x300(%rsp), %rcx
movq (%rcx), %rbx
testl %eax, %eax
je 0xd450
movl 0x78(%rsp), %esi
movq 0x70(%rsp), %rdx
movq 0x8(%rcx), %r14
movq %r15, (%rsp)
leaq 0x79f6(%rip), %rdi      # 0x14e19
leaq 0xb0(%rsp), %rcx
movl %r14d, %r8d
movq %rbx, %r9
xorl %eax, %eax
callq 0x430a
jmp 0xd454
xorl %ecx, %ecx
movl %ecx, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rcx), %r14
leaq 0x80(%rsp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x6915
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
jmp 0xd43c