// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_parse_header
int mg_http_parse_header(struct mg_str *hdr, const char *var_name, char *buf,
                         size_t buf_size) {
  int ch = ' ', ch1 = ',', len = 0, n = strlen(var_name);
  const char *p, *end = hdr ? hdr->p + hdr->len : NULL, *s = NULL;

  if (buf != NULL && buf_size > 0) buf[0] = '\0';
  if (hdr == NULL) return 0;

  /* Find where variable starts */
  for (s = hdr->p; s != NULL && s + n < end; s++) {
    if ((s == hdr->p || s[-1] == ch || s[-1] == ch1 || s[-1] == ';') &&
        s[n] == '=' && !strncmp(s, var_name, n))
      break;
  }

  if (s != NULL && &s[n + 1] < end) {
    s += n + 1;
    if (*s == '"' || *s == '\'') {
      ch = ch1 = *s++;
    }
    p = s;
    while (p < end && p[0] != ch && p[0] != ch1 && len < (int) buf_size) {
      if (ch != ' ' && p[0] == '\\' && p[1] == ch) p++;
      buf[len++] = *p++;
    }
    if (len >= (int) buf_size || (ch != ' ' && *p != ch)) {
      len = 0;
    } else {
      if (len > 0 && s[len - 1] == ',') len--;
      if (len > 0 && s[len - 1] == ';') len--;
      buf[len] = '\0';
    }
  }

  return len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r13
movq %rsi, %rdi
callq 0x3180
testq %r13, %r13
je 0xc97e
movq (%r13), %rbp
addq 0x8(%r13), %rbp
jmp 0xc980
xorl %ebp, %ebp
testq %rbx, %rbx
sete %dl
testq %r14, %r14
sete %cl
orb %dl, %cl
jne 0xc993
movb $0x0, (%rbx)
testq %r13, %r13
je 0xca48
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movq %rax, %rcx
movq (%r13), %r14
shlq $0x20, %rax
movq %rax, 0x10(%rsp)
movslq %ecx, %r13
leaq (%r14,%r13), %r15
xorl %ebx, %ebx
movq %r14, %rdi
addq %rbx, %rdi
je 0xca09
leaq (%r15,%rbx), %rax
cmpq %rbp, %rax
jae 0xca09
testq %rbx, %rbx
je 0xc9f0
movzbl -0x1(%r14,%rbx), %ecx
cmpq $0x3b, %rcx
ja 0xca04
movabsq $0x800100100000000, %rdx # imm = 0x800100100000000
btq %rcx, %rdx
jae 0xca04
cmpb $0x3d, (%rax)
jne 0xca04
movq %r12, %rsi
movq %r13, %rdx
callq 0x30c0
testl %eax, %eax
je 0xca0e
incq %rbx
jmp 0xc9be
testq %rdi, %rdi
je 0xca48
movabsq $0x100000000, %rax      # imm = 0x100000000
movq 0x10(%rsp), %rcx
addq %rax, %rcx
sarq $0x20, %rcx
addq %rcx, %r14
leaq (%r14,%rbx), %rcx
cmpq %rbp, %rcx
jae 0xca48
movzbl (%rcx), %eax
cmpl $0x22, %eax
je 0xca3d
cmpl $0x27, %eax
jne 0xca59
leaq (%rbx,%r14), %rcx
incq %rcx
movl %eax, %edx
jmp 0xca5f
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x20
popq %rdx
pushq $0x2c
popq %rax
movq 0x8(%rsp), %rbx
movq (%rsp), %r14
movslq %r14d, %r8
xorl %esi, %esi
pushq $0x5c
popq %r9
movq %rcx, %rdi
cmpq %rbp, %rdi
jae 0xcaba
movb (%rdi), %r10b
movsbl %r10b, %r11d
cmpl %r11d, %edx
je 0xcaba
cmpl %r11d, %eax
je 0xcaba
cmpq %r8, %rsi
jge 0xcaba
cmpl $0x20, %edx
je 0xcaae
cmpb $0x5c, %r10b
jne 0xcaae
leaq 0x1(%rdi), %r11
movsbl 0x1(%rdi), %r10d
cmpl %r10d, %edx
cmovnel %r9d, %r10d
cmoveq %r11, %rdi
incq %rdi
movb %r10b, (%rbx,%rsi)
incq %rsi
jmp 0xca74
xorl %eax, %eax
cmpl %r14d, %esi
jge 0xca4a
cmpl $0x20, %edx
je 0xcad1
movsbl (%rdi), %edi
cmpl %edi, %edx
jne 0xca4a
testq %rsi, %rsi
je 0xcaf2
leal -0x1(%rsi), %edx
cmpb $0x2c, (%rcx,%rdx)
movl %esi, %eax
cmovel %edx, %eax
testl %eax, %eax
jle 0xcaf4
leal -0x1(%rax), %edx
cmpb $0x3b, (%rcx,%rdx)
cmovel %edx, %eax
jmp 0xcaf4
xorl %eax, %eax
movslq %eax, %rcx
movb $0x0, (%rbx,%rcx)
jmp 0xca4a