// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %r14d
movq %rdx, %rbx
movq %rdi, %r13
callq 0xb664
movl %eax, %ebp
testl %eax, %eax
jle 0xb64f
leaq 0x20(%rbx), %r15
movl $0x558, %edx            # imm = 0x558
movq %r15, %rdi
xorl %esi, %esi
callq 0x3240
movq %r13, (%rbx)
movl %ebp, %eax
movq %rax, 0x10(%rsp)
leaq (%rax,%r13), %r12
movq %r12, 0x10(%rbx)
movq $-0x1, %rax
movq %rax, 0x18(%rbx)
movq %rax, 0x8(%rbx)
callq 0x3660
movq (%rax), %rax
movzbl (%r13), %ecx
testb $0x20, 0x1(%rax,%rcx,2)
je 0xb4da
incq %r13
cmpq %r12, %r13
jb 0xb4c6
movl %r14d, 0x4(%rsp)
testl %r14d, %r14d
je 0xb58c
leaq 0xc13b(%rip), %r14      # 0x1762a
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %r15, 0x8(%rsp)
movq %r15, %rcx
callq 0xb701
leaq 0x30(%rbx), %rcx
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0xb701
leaq 0x40(%rbx), %r15
leaq 0xb2c9(%rip), %rdx      # 0x167eb
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rcx
callq 0xb701
movq 0x30(%rbx), %r14
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpq 0x20(%rbx), %r14
jbe 0xb652
cmpq %r14, (%r15)
jbe 0xb652
movq %rax, %r15
movq 0x38(%rbx), %r13
movq %r14, %rdi
movl $0x3f, %esi
movq %r13, %rdx
callq 0x32c0
testq %rax, %rax
je 0xb582
leaq 0x1(%rax), %rcx
movq %rcx, 0x68(%rbx)
addq %r14, %r13
subq %rcx, %r13
movq %r13, 0x70(%rbx)
subq %r14, %rax
movq %rax, 0x38(%rbx)
movq 0x8(%rsp), %r14
movq %r15, %rdi
jmp 0xb5fd
leaq 0x40(%rbx), %rcx
leaq 0xc093(%rip), %rdx      # 0x1762a
movq %r13, %rdi
movq %r12, %rsi
callq 0xb701
movq %rax, %r14
movq %r12, %rax
subq %r14, %rax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpq $0x4, %rax
jl 0xb652
cmpb $0x20, 0x3(%r14)
jne 0xb652
movq %r14, %rdi
callq 0x3580
movl %eax, 0x50(%rbx)
addl $0xfffffda8, %eax       # imm = 0xFFFFFDA8
cmpl $0xfffffe0c, %eax       # imm = 0xFFFFFE0C
jb 0xb652
addq $0x4, %r14
leaq 0x58(%rbx), %rcx
leaq 0xb1ff(%rip), %rdx      # 0x167eb
movq %r14, %rdi
movq %r12, %rsi
callq 0xb701
movq %rax, %rdi
movq %r15, %r14
movq %r12, %rsi
movl %ebp, %edx
movq %rbx, %rcx
callq 0xb780
cmpl $0x0, 0x4(%rsp)
je 0xb64f
cmpq $-0x1, 0x18(%rbx)
jne 0xb64f
leaq 0xa3f3(%rip), %rsi      # 0x15a12
movq %r14, %rdi
callq 0x6b88
testl %eax, %eax
je 0xb64f
leaq 0xa3e4(%rip), %rsi      # 0x15a16
movq %r14, %rdi
callq 0x6b88
testl %eax, %eax
je 0xb64f
movq $0x0, 0x18(%rbx)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbx)
movl %ebp, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq