// File: /workspace/github_c_makefile_star2_O2/coyove[P]chann/./lib/mongoose/mongoose.c
// Function: mg_authorize_digest
int mg_authorize_digest(struct mg_connection *c, FILE *fp) {
  struct connection *conn = MG_CONN_2_CONN(c);
  const char *hdr;
  char line[256], f_user[256], ha1[256], f_domain[256], user[100], nonce[100],
       uri[MAX_REQUEST_SIZE], cnonce[100], resp[100], qop[100], nc[100];

  if (c == NULL || fp == NULL) return 0;
  if ((hdr = mg_get_header(c, "Authorization")) == NULL ||
      mg_strncasecmp(hdr, "Digest ", 7) != 0) return 0;
  if (!mg_parse_header(hdr, "username", user, sizeof(user))) return 0;
  if (!mg_parse_header(hdr, "cnonce", cnonce, sizeof(cnonce))) return 0;
  if (!mg_parse_header(hdr, "response", resp, sizeof(resp))) return 0;
  if (!mg_parse_header(hdr, "uri", uri, sizeof(uri))) return 0;
  if (!mg_parse_header(hdr, "qop", qop, sizeof(qop))) return 0;
  if (!mg_parse_header(hdr, "nc", nc, sizeof(nc))) return 0;
  if (!mg_parse_header(hdr, "nonce", nonce, sizeof(nonce))) return 0;

  while (fgets(line, sizeof(line), fp) != NULL) {
    if (sscanf(line, "%[^:]:%[^:]:%s", f_user, f_domain, ha1) == 3 &&
        !strcmp(user, f_user) &&
        // NOTE(lsm): due to a bug in MSIE, we do not compare URIs
        !strcmp(conn->server->config_options[AUTH_DOMAIN], f_domain))
      return check_password(c->request_method, ha1, uri,
                            nonce, nc, cnonce, qop, resp);
  }
  return MG_FALSE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x46f8, %rsp           # imm = 0x46F8
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
xorl %ebx, %ebx
orb %al, %cl
jne 0x5a09a
movq %rsi, %r15
movq %rdi, %r14
leaq 0xa87c(%rip), %rsi      # 0x648f3
callq 0x58dc0
testq %rax, %rax
je 0x5a09a
movq %rax, %r13
leaq 0xe2e2(%rip), %rsi      # 0x6836d
pushq $0x7
popq %rdx
movq %rax, %rdi
callq 0x5a293
testl %eax, %eax
je 0x5a0ae
movl %ebx, %eax
addq $0x46f8, %rsp           # imm = 0x46F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7721(%rip), %rsi      # 0x617d6
leaq -0x320(%rbp), %rdx
pushq $0x64
popq %rcx
movq %r13, %rdi
callq 0x5a2ed
testl %eax, %eax
je 0x5a09a
leaq 0xe2a3(%rip), %rsi      # 0x68375
leaq -0x240(%rbp), %rdx
pushq $0x64
popq %rcx
movq %r13, %rdi
callq 0x5a2ed
testl %eax, %eax
je 0x5a09a
leaq 0xe28d(%rip), %rsi      # 0x6837c
leaq -0x1d0(%rbp), %rdx
pushq $0x64
popq %rcx
movq %r13, %rdi
callq 0x5a2ed
testl %eax, %eax
je 0x5a09a
leaq 0xe279(%rip), %rsi      # 0x68385
leaq -0x4720(%rbp), %rdx
movl $0x4000, %ecx           # imm = 0x4000
movq %r13, %rdi
callq 0x5a2ed
testl %eax, %eax
je 0x5a09a
leaq 0xe25a(%rip), %rsi      # 0x68389
leaq -0x160(%rbp), %rdx
pushq $0x64
popq %rcx
movq %r13, %rdi
callq 0x5a2ed
testl %eax, %eax
je 0x5a09a
leaq 0xe23d(%rip), %rsi      # 0x6838d
leaq -0xf0(%rbp), %rdx
pushq $0x64
popq %rcx
movq %r13, %rdi
callq 0x5a2ed
testl %eax, %eax
je 0x5a09a
leaq 0xe205(%rip), %rsi      # 0x68376
leaq -0x2b0(%rbp), %rdx
pushq $0x64
popq %rcx
movq %r13, %rdi
callq 0x5a2ed
testl %eax, %eax
je 0x5a09a
leaq -0x720(%rbp), %r13
xorl %ebx, %ebx
leaq -0x620(%rbp), %r12
movq %r13, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r15, %rdx
callq 0xc770
testq %rax, %rax
je 0x5a09a
movq %r13, %rdi
leaq 0xe1d2(%rip), %rsi      # 0x68390
movq %r12, %rdx
leaq -0x420(%rbp), %rcx
leaq -0x520(%rbp), %r8
xorl %eax, %eax
callq 0xc110
cmpl $0x3, %eax
jne 0x5a19b
leaq -0x320(%rbp), %rdi
movq %r12, %rsi
callq 0xc970
testl %eax, %eax
jne 0x5a19b
movq 0x2a0(%r14), %rax
movq 0x48(%rax), %rdi
leaq -0x420(%rbp), %rsi
callq 0xc970
testl %eax, %eax
jne 0x5a19b
movq (%r14), %rsi
leaq 0x7a59(%rip), %rbx      # 0x61c6c
leaq -0x80(%rbp), %r14
leaq -0x4720(%rbp), %rcx
movq %r14, %rdi
movq %rbx, %rdx
xorl %r8d, %r8d
xorl %eax, %eax
callq 0x59db6
subq $0x8, %rsp
leaq -0x50(%rbp), %r15
leaq -0x520(%rbp), %rsi
leaq -0x2b0(%rbp), %rcx
leaq -0xf0(%rbp), %r9
movq %r15, %rdi
movq %rbx, %rdx
movq %rbx, %r8
xorl %eax, %eax
pushq $0x0
pushq %r14
pushq %rbx
leaq -0x160(%rbp), %r10
pushq %r10
pushq %rbx
leaq -0x240(%rbp), %r10
pushq %r10
pushq %rbx
callq 0x59db6
addq $0x40, %rsp
leaq -0x1d0(%rbp), %rdi
movq %r15, %rsi
callq 0x58e28
xorl %ebx, %ebx
testl %eax, %eax
sete %bl
jmp 0x5a09a