// File: /workspace/github_c_makefile_star2_O1/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 $0x4698, %rsp           # imm = 0x4698
testq %rdi, %rdi
sete %al
testq %rsi, %rsi
sete %cl
xorl %r15d, %r15d
orb %al, %cl
jne 0x6ac07
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xbd29(%rip), %rsi      # 0x7690b
callq 0x69863
testq %rax, %rax
je 0x6ac07
movq %rax, %r13
leaq 0xf797(%rip), %rsi      # 0x7a38d
movl $0x7, %edx
movq %rax, %rdi
callq 0x6ae41
testl %eax, %eax
je 0x6ac1c
movl %r15d, %eax
addq $0x4698, %rsp           # imm = 0x4698
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0xc460
leaq 0x8bdb(%rip), %rdx      # 0x73806
leaq -0x2c0(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x6af98
testl %eax, %eax
je 0x6ac07
movq %r13, %rdi
callq 0xc460
leaq 0xf73f(%rip), %rdx      # 0x7a395
leaq -0x1e0(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x6af98
testl %eax, %eax
je 0x6ac07
movq %r13, %rdi
callq 0xc460
leaq 0xf71b(%rip), %rdx      # 0x7a39c
leaq -0x170(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x6af98
testl %eax, %eax
je 0x6ac07
movq %r13, %rdi
callq 0xc460
leaq 0xf6f5(%rip), %rdx      # 0x7a3a5
leaq -0x46c0(%rbp), %rcx
movl $0x4000, %r8d           # imm = 0x4000
movq %r13, %rdi
movq %rax, %rsi
callq 0x6af98
testl %eax, %eax
je 0x6ac07
movq %r13, %rdi
callq 0xc460
leaq 0xf6ca(%rip), %rdx      # 0x7a3a9
leaq -0x100(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x6af98
testl %eax, %eax
je 0x6ac07
movq %r13, %rdi
callq 0xc460
leaq 0xf69f(%rip), %rdx      # 0x7a3ad
leaq -0x90(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x6af98
testl %eax, %eax
je 0x6ac07
movq %r13, %rdi
callq 0xc460
leaq 0xf659(%rip), %rdx      # 0x7a396
leaq -0x250(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x6af98
testl %eax, %eax
je 0x6ac07
leaq -0x5c0(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0xc750
testq %rax, %rax
je 0x6ac07
leaq -0x5c0(%rbp), %r12
leaq -0x6c0(%rbp), %r13
xorl %r15d, %r15d
movq %r12, %rdi
leaq 0xf61b(%rip), %rsi      # 0x7a3b0
movq %r13, %rdx
leaq -0x3c0(%rbp), %rcx
leaq -0x4c0(%rbp), %r8
xorl %eax, %eax
callq 0xc100
cmpl $0x3, %eax
jne 0x6ade0
leaq -0x2c0(%rbp), %rdi
movq %r13, %rsi
callq 0xc950
testl %eax, %eax
jne 0x6ade0
movq 0x2a0(%rbx), %rax
movq 0x48(%rax), %rdi
leaq -0x3c0(%rbp), %rsi
callq 0xc950
testl %eax, %eax
je 0x6adfa
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0xc750
testq %rax, %rax
jne 0x6ad8b
jmp 0x6ac07
movq (%rbx), %rdi
leaq -0x4c0(%rbp), %rsi
leaq -0x46c0(%rbp), %rdx
leaq -0x250(%rbp), %rcx
leaq -0x90(%rbp), %r8
leaq -0x1e0(%rbp), %r9
leaq -0x170(%rbp), %rax
pushq %rax
leaq -0x100(%rbp), %rax
pushq %rax
callq 0x6aedd
addq $0x10, %rsp
movl %eax, %r15d
jmp 0x6ac07