// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
movq %rcx, %r12
movq %rdx, %r14
movq %rdi, %r13
movq %rsi, 0x20(%rsp)
movq %rsi, %rdi
callq 0x3180
movq %rax, 0x18(%rsp)
testq %r13, %r13
je 0xd618
movq (%r13), %rbp
addq 0x8(%r13), %rbp
jmp 0xd61a
xorl %ebp, %ebp
testq %r14, %r14
sete %al
testq %r12, %r12
sete %cl
orb %al, %cl
jne 0xd62e
movb $0x0, (%r14)
xorl %eax, %eax
testq %r13, %r13
je 0xd7b2
movq (%r13), %rbx
testq %rbx, %rbx
je 0xd6b1
movslq 0x18(%rsp), %r13
leaq (%rbx,%r13), %r15
cmpq %rbp, %r15
jae 0xd6b1
movq %r12, 0x8(%rsp)
movq %r14, 0x10(%rsp)
xorl %r12d, %r12d
testq %r12, %r12
je 0xd67e
movzbl -0x1(%rbx,%r12), %eax
cmpq $0x3b, %rax
ja 0xd69d
movabsq $0x800100100000000, %rcx # imm = 0x800100100000000
btq %rax, %rcx
jae 0xd69d
cmpb $0x3d, (%r15,%r12)
jne 0xd69d
leaq (%rbx,%r12), %r14
movq %r14, %rdi
movq 0x20(%rsp), %rsi
movq %r13, %rdx
callq 0x30c0
testl %eax, %eax
je 0xd6bd
leaq (%r15,%r12), %rax
incq %rax
incq %r12
cmpq %rbp, %rax
jb 0xd65d
addq %r12, %rbx
jmp 0xd6c0
testq %rbx, %rbx
jne 0xd6ca
xorl %eax, %eax
jmp 0xd7b2
movq %r14, %rbx
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r12
movq 0x18(%rsp), %rax
shlq $0x20, %rax
movabsq $0x100000000, %r15      # imm = 0x100000000
addq %rax, %r15
sarq $0x20, %r15
addq %rbx, %r15
cmpq %rbp, %r15
movl $0x0, %eax
jae 0xd7b2
movzbl (%r15), %esi
cmpl $0x27, %esi
je 0xd703
cmpl $0x22, %esi
jne 0xd70a
incq %r15
movl %esi, %edx
jmp 0xd714
movl $0x20, %edx
movl $0x2c, %esi
xorl %eax, %eax
movl $0x0, %ecx
movq %r15, %rdi
cmpq %rbp, %r15
jae 0xd775
movslq %r12d, %r8
xorl %ecx, %ecx
movl $0x5c, %r9d
movq %r15, %rdi
movb (%rdi), %r10b
movsbl %r10b, %r11d
cmpl %r11d, %edx
je 0xd775
cmpl %r11d, %esi
je 0xd775
cmpq %r8, %rcx
jge 0xd775
cmpl $0x20, %edx
je 0xd766
cmpb $0x5c, %r10b
jne 0xd766
leaq 0x1(%rdi), %r11
movsbl 0x1(%rdi), %r10d
cmpl %r10d, %edx
cmovnel %r9d, %r10d
cmoveq %r11, %rdi
incq %rdi
movb %r10b, (%r14,%rcx)
incq %rcx
cmpq %rbp, %rdi
jb 0xd731
cmpl %r12d, %ecx
jge 0xd7b2
cmpl $0x20, %edx
je 0xd786
movsbl (%rdi), %esi
cmpl %esi, %edx
jne 0xd7b2
testl %ecx, %ecx
je 0xd7a6
leal -0x1(%rcx), %edx
cmpb $0x2c, (%r15,%rdx)
cmovel %edx, %ecx
testl %ecx, %ecx
jle 0xd7a8
leal -0x1(%rcx), %edx
cmpb $0x3b, (%r15,%rdx)
cmovel %edx, %ecx
jmp 0xd7a8
xorl %ecx, %ecx
movslq %ecx, %rax
movb $0x0, (%r14,%rax)
movl %ecx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq