// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_parse_http
int mg_parse_http(const char *s, int n, struct http_message *hm, int is_req) {
  const char *end, *qs;
  int len = mg_http_get_request_len(s, n);

  if (len <= 0) return len;

  memset(hm, 0, sizeof(*hm));
  hm->message.p = s;
  hm->body.p = s + len;
  hm->message.len = hm->body.len = (size_t) ~0;
  end = s + len;

  /* Request is fully buffered. Skip leading whitespaces. */
  while (s < end && isspace(*(unsigned char *) s)) s++;

  if (is_req) {
    /* Parse request line: method, URI, proto */
    s = mg_skip(s, end, " ", &hm->method);
    s = mg_skip(s, end, " ", &hm->uri);
    s = mg_skip(s, end, "\r\n", &hm->proto);
    if (hm->uri.p <= hm->method.p || hm->proto.p <= hm->uri.p) return -1;

    /* If URI contains '?' character, initialize query_string */
    if ((qs = (char *) memchr(hm->uri.p, '?', hm->uri.len)) != NULL) {
      hm->query_string.p = qs + 1;
      hm->query_string.len = &hm->uri.p[hm->uri.len] - (qs + 1);
      hm->uri.len = qs - hm->uri.p;
    }
  } else {
    s = mg_skip(s, end, " ", &hm->proto);
    if (end - s < 4 || s[3] != ' ') return -1;
    hm->resp_code = atoi(s);
    if (hm->resp_code < 100 || hm->resp_code >= 600) return -1;
    s += 4;
    s = mg_skip(s, end, "\r\n", &hm->resp_status_msg);
  }

  s = mg_http_parse_headers(s, end, len, hm);

  /*
   * mg_parse_http() is used to parse both HTTP requests and HTTP
   * responses. If HTTP response does not have Content-Length set, then
   * body is read until socket is closed, i.e. body.len is infinite (~0).
   *
   * For HTTP requests though, according to
   * http://tools.ietf.org/html/rfc7231#section-8.1.3,
   * only POST and PUT methods have defined body semantics.
   * Therefore, if Content-Length is not specified and methods are
   * not one of PUT or POST, set body length to 0.
   *
   * So,
   * if it is HTTP request, and Content-Length is not set,
   * and method is not (PUT or POST) then reset body length to zero.
   */
  if (hm->body.len == (size_t) ~0 && is_req &&
      mg_vcasecmp(&hm->method, "PUT") != 0 &&
      mg_vcasecmp(&hm->method, "POST") != 0) {
    hm->body.len = 0;
    hm->message.len = len;
  }

  return len;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x10460
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jg 0x10186
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x10456
movq -0x20(%rbp), %rdi
xorl %esi, %esi
movl $0x578, %edx            # imm = 0x578
callq 0x3260
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rcx
movslq -0x3c(%rbp), %rax
addq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq $-0x1, 0x18(%rax)
movq -0x20(%rbp), %rax
movq $-0x1, 0x8(%rax)
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpq -0x30(%rbp), %rcx
movb %al, -0x3d(%rbp)
jae 0x1020e
callq 0x36a0
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movzbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
setne %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0x10217
jmp 0x10225
movq -0x10(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10(%rbp)
jmp 0x101db
cmpl $0x0, -0x24(%rbp)
je 0x10332
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rcx
addq $0x20, %rcx
leaq 0x113ae(%rip), %rdx     # 0x215f4
callq 0x105b0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rcx
addq $0x30, %rcx
leaq 0x1138e(%rip), %rdx     # 0x215f4
callq 0x105b0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rcx
addq $0x40, %rcx
leaq 0x10523(%rip), %rdx     # 0x207a9
callq 0x105b0
movq %rax, -0x10(%rbp)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jbe 0x102b3
movq -0x20(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x30(%rcx), %rax
ja 0x102bf
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10456
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdx
movl $0x3f, %esi
callq 0x32e0
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x1032d
movq -0x38(%rbp), %rcx
addq $0x1, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x20(%rbp), %rax
addq 0x38(%rax), %rcx
movq -0x38(%rbp), %rax
addq $0x1, %rax
subq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x38(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rax
subq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x38(%rax)
jmp 0x103dd
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rcx
addq $0x40, %rcx
leaq 0x112ab(%rip), %rdx     # 0x215f4
callq 0x105b0
movq %rax, -0x10(%rbp)
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
subq %rcx, %rax
cmpq $0x4, %rax
jl 0x10370
movq -0x10(%rbp), %rax
movsbl 0x3(%rax), %eax
cmpl $0x20, %eax
je 0x1037c
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10456
movq -0x10(%rbp), %rdi
callq 0x35c0
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x50(%rax)
movq -0x20(%rbp), %rax
cmpl $0x64, 0x50(%rax)
jl 0x103a5
movq -0x20(%rbp), %rax
cmpl $0x258, 0x50(%rax)      # imm = 0x258
jl 0x103b1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x10456
movq -0x10(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rcx
addq $0x58, %rcx
leaq 0x103d5(%rip), %rdx     # 0x207a9
callq 0x105b0
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0x3c(%rbp), %edx
movq -0x20(%rbp), %rcx
callq 0x10680
movq %rax, -0x10(%rbp)
movq -0x20(%rbp), %rax
cmpq $-0x1, 0x18(%rax)
jne 0x10450
cmpl $0x0, -0x24(%rbp)
je 0x10450
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
leaq 0xf57c(%rip), %rsi      # 0x1f991
callq 0x8b60
cmpl $0x0, %eax
je 0x10450
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
leaq 0xf567(%rip), %rsi      # 0x1f995
callq 0x8b60
cmpl $0x0, %eax
je 0x10450
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
movslq -0x3c(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop