// File: /workspace/github_c_makefile_star2_O3/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 0x68ffa
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xb93e(%rip), %rsi      # 0x74913
callq 0x67c6a
testq %rax, %rax
je 0x68ffa
movq %rax, %r13
leaq 0xf3a4(%rip), %rsi      # 0x7838d
movl $0x7, %edx
movq %rax, %rdi
callq 0x69234
testl %eax, %eax
je 0x6900f
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 0x87e8(%rip), %rdx      # 0x71806
leaq -0x2c0(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x693a2
testl %eax, %eax
je 0x68ffa
movq %r13, %rdi
callq 0xc460
leaq 0xf34c(%rip), %rdx      # 0x78395
leaq -0x1e0(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x693a2
testl %eax, %eax
je 0x68ffa
movq %r13, %rdi
callq 0xc460
leaq 0xf328(%rip), %rdx      # 0x7839c
leaq -0x170(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x693a2
testl %eax, %eax
je 0x68ffa
movq %r13, %rdi
callq 0xc460
leaq 0xf302(%rip), %rdx      # 0x783a5
leaq -0x46c0(%rbp), %rcx
movl $0x4000, %r8d           # imm = 0x4000
movq %r13, %rdi
movq %rax, %rsi
callq 0x693a2
testl %eax, %eax
je 0x68ffa
movq %r13, %rdi
callq 0xc460
leaq 0xf2d7(%rip), %rdx      # 0x783a9
leaq -0x100(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x693a2
testl %eax, %eax
je 0x68ffa
movq %r13, %rdi
callq 0xc460
leaq 0xf2ac(%rip), %rdx      # 0x783ad
leaq -0x90(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x693a2
testl %eax, %eax
je 0x68ffa
movq %r13, %rdi
callq 0xc460
leaq 0xf266(%rip), %rdx      # 0x78396
leaq -0x250(%rbp), %rcx
movl $0x64, %r8d
movq %r13, %rdi
movq %rax, %rsi
callq 0x693a2
testl %eax, %eax
je 0x68ffa
leaq -0x5c0(%rbp), %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0xc750
testq %rax, %rax
je 0x68ffa
leaq -0x5c0(%rbp), %r12
leaq -0x6c0(%rbp), %r13
xorl %r15d, %r15d
movq %r12, %rdi
leaq 0xf228(%rip), %rsi      # 0x783b0
movq %r13, %rdx
leaq -0x3c0(%rbp), %rcx
leaq -0x4c0(%rbp), %r8
xorl %eax, %eax
callq 0xc100
cmpl $0x3, %eax
jne 0x691d3
leaq -0x2c0(%rbp), %rdi
movq %r13, %rsi
callq 0xc950
testl %eax, %eax
jne 0x691d3
movq 0x2a0(%rbx), %rax
movq 0x48(%rax), %rdi
leaq -0x3c0(%rbp), %rsi
callq 0xc950
testl %eax, %eax
je 0x691ed
movq %r12, %rdi
movl $0x100, %esi            # imm = 0x100
movq %r14, %rdx
callq 0xc750
testq %rax, %rax
jne 0x6917e
jmp 0x68ffa
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 0x692e7
addq $0x10, %rsp
movl %eax, %r15d
jmp 0x68ffa