// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_get_http_var
int mg_get_http_var(const struct mg_str *buf, const char *name, char *dst,
                    size_t dst_len) {
  const char *p, *e, *s;
  size_t name_len;
  int len;

  /*
   * According to the documentation function returns negative
   * value in case of error. For debug purposes it returns:
   * -1 - src is wrong (NUUL)
   * -2 - dst is wrong (NULL)
   * -3 - failed to decode url or dst is to small
   * -4 - name does not exist
   */
  if (dst == NULL || dst_len == 0) {
    len = -2;
  } else if (buf->p == NULL || name == NULL || buf->len == 0) {
    len = -1;
    dst[0] = '\0';
  } else {
    name_len = strlen(name);
    e = buf->p + buf->len;
    len = -4;
    dst[0] = '\0';

    for (p = buf->p; p + name_len < e; p++) {
      if ((p == buf->p || p[-1] == '&') && p[name_len] == '=' &&
          !mg_ncasecmp(name, p, name_len)) {
        p += name_len + 1;
        s = (const char *) memchr(p, '&', (size_t)(e - p));
        if (s == NULL) {
          s = e;
        }
        len = mg_url_decode(p, (size_t)(s - p), dst, dst_len, 1);
        /* -1 means: failed to decode or dst is too small */
        if (len == -1) {
          len = -3;
        }
        break;
      }
    }
  }

  return len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x12706
cmpq $0x0, -0x20(%rbp)
jne 0x12712
movl $0xfffffffe, -0x44(%rbp) # imm = 0xFFFFFFFE
jmp 0x12860
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x1272e
cmpq $0x0, -0x10(%rbp)
je 0x1272e
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x12741
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
jmp 0x1285e
movq -0x10(%rbp), %rdi
callq 0x3180
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
addq 0x8(%rcx), %rax
movq %rax, -0x30(%rbp)
movl $0xfffffffc, -0x44(%rbp) # imm = 0xFFFFFFFC
movq -0x18(%rbp), %rax
movb $0x0, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
addq -0x40(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0x1285c
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq (%rcx), %rax
je 0x127aa
movq -0x28(%rbp), %rax
movsbl -0x1(%rax), %eax
cmpl $0x26, %eax
jne 0x12849
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3d, %eax
jne 0x12849
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movq -0x40(%rbp), %rdx
callq 0x8bf0
cmpl $0x0, %eax
jne 0x12849
movq -0x40(%rbp), %rax
addq $0x1, %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rdx
movq -0x28(%rbp), %rax
subq %rax, %rdx
movl $0x26, %esi
callq 0x32e0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x12811
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rax
movq -0x28(%rbp), %rcx
subq %rcx, %rax
movl %eax, %esi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rax
movl %eax, %ecx
movl $0x1, %r8d
callq 0x124c0
movl %eax, -0x44(%rbp)
cmpl $-0x1, -0x44(%rbp)
jne 0x12847
movl $0xfffffffd, -0x44(%rbp) # imm = 0xFFFFFFFD
jmp 0x1285c
jmp 0x1284b
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x1277a
jmp 0x1285e
jmp 0x12860
movl -0x44(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)