// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movq %rdx, %rbp
movq %rdi, %r14
movq %rsi, 0x20(%rsp)
movq %rsi, %rdi
callq 0x3180
movq %rax, %rdx
testq %r14, %r14
je 0xd73c
movq (%r14), %r11
addq 0x8(%r14), %r11
jmp 0xd73f
xorl %r11d, %r11d
testq %rbp, %rbp
sete %al
testq %rbx, %rbx
sete %cl
orb %al, %cl
jne 0xd753
movb $0x0, (%rbp)
xorl %eax, %eax
testq %r14, %r14
je 0xd8ea
movq %rbx, 0x10(%rsp)
movq (%r14), %r15
testq %r15, %r15
setne %bl
je 0xd804
movq %rdx, (%rsp)
movslq %edx, %rax
movq %rax, 0x18(%rsp)
leaq (%r15,%rax), %r13
cmpq %r11, %r13
jae 0xd7f9
movq %rbp, 0x8(%rsp)
xorl %ebp, %ebp
testq %rbp, %rbp
je 0xd7af
movzbl -0x1(%r15,%rbp), %eax
cmpq $0x3b, %rax
ja 0xd7d7
movabsq $0x800100100000000, %rcx # imm = 0x800100100000000
btq %rax, %rcx
jae 0xd7d7
cmpb $0x3d, (%r13,%rbp)
jne 0xd7d7
leaq (%r15,%rbp), %r12
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
movq %r11, %r14
callq 0x30c0
movq %r14, %r11
testl %eax, %eax
je 0xd7f2
leaq 0x1(,%rbp), %rax
addq %r13, %rax
incq %rbp
movb $0x1, %bl
cmpq %r11, %rax
jb 0xd78e
addq %rbp, %r15
movq %r15, %r12
movq 0x8(%rsp), %rbp
jmp 0xd7fc
movq %r15, %r12
xorl %eax, %eax
movq (%rsp), %rdx
jmp 0xd807
movq %r15, %r12
testb $0x1, %bl
je 0xd8ea
shlq $0x20, %rdx
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rdx, %rcx
sarq $0x20, %rcx
addq %rcx, %r12
cmpq %r11, %r12
jae 0xd8ea
movzbl (%r12), %eax
cmpl $0x27, %eax
je 0xd840
cmpl $0x22, %eax
jne 0xd84a
movsbl %al, %esi
incq %r12
movl %esi, %ecx
jmp 0xd854
movl $0x20, %ecx
movl $0x2c, %esi
movq 0x10(%rsp), %r10
xorl %eax, %eax
movl $0x0, %ebx
movq %r12, %rdx
cmpq %r11, %r12
jae 0xd8b1
movslq %r10d, %rdi
xorl %ebx, %ebx
movq %r12, %rdx
movb (%rdx), %r8b
movsbl %r8b, %r9d
cmpl %r9d, %ecx
je 0xd8b1
cmpl %r9d, %esi
je 0xd8b1
cmpq %rdi, %rbx
jge 0xd8b1
cmpl $0x20, %ecx
je 0xd89e
cmpb $0x5c, %r8b
jne 0xd89e
movsbl 0x1(%rdx), %r8d
cmpl %r8d, %ecx
jne 0xd89e
incq %rdx
movb (%rdx), %r8b
incq %rdx
movb %r8b, (%rbp,%rbx)
incq %rbx
cmpq %r11, %rdx
jb 0xd870
cmpl %r10d, %ebx
jge 0xd8ea
cmpl $0x20, %ecx
je 0xd8c2
movsbl (%rdx), %edx
cmpl %edx, %ecx
jne 0xd8ea
testl %ebx, %ebx
je 0xd8d1
leal -0x1(%rbx), %ecx
cmpb $0x2c, (%r12,%rcx)
cmovel %ecx, %ebx
testl %ebx, %ebx
jle 0xd8e0
leal -0x1(%rbx), %ecx
cmpb $0x3b, (%r12,%rcx)
cmovel %ecx, %ebx
movslq %ebx, %rcx
movb $0x0, (%rbp,%rcx)
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq