LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_skip
const char *mg_skip(const char *s, const char *end, const char *delims,
                    struct mg_str *v) {
  v->p = s;
  while (s < end && strchr(delims, *(unsigned char *) s) == NULL) s++;
  v->len = s - v->p;
  while (s < end && strchr(delims, *(unsigned char *) s) != NULL) s++;
  return s;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r13
movq %rdi, (%rcx)
movq %rdi, %r14
cmpq %rsi, %rdi
jae 0xb740
movq %r13, %r14
movzbl (%r14), %esi
movq %rbx, %rdi
callq 0x31d0
testq %rax, %rax
jne 0xb740
incq %r14
cmpq %r15, %r14
jne 0xb724
movq %r15, %r14
movq %r14, %rax
subq %r13, %rax
movq %rax, 0x8(%r12)
cmpq %r15, %r14
jae 0xb773
subq %r14, %r15
leaq (%r14,%r15), %r12
movzbl (%r14), %esi
movq %rbx, %rdi
callq 0x31d0
testq %rax, %rax
je 0xb773
incq %r14
decq %r15
jne 0xb757
movq %r12, %r14
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_parse_headers
static const char *mg_http_parse_headers(const char *s, const char *end,
                                         int len, struct http_message *req) {
  int i = 0;
  while (i < (int) ARRAY_SIZE(req->header_names) - 1) {
    struct mg_str *k = &req->header_names[i], *v = &req->header_values[i];

    s = mg_skip(s, end, ": ", k);
    s = mg_skip(s, end, "\r\n", v);

    while (v->len > 0 && v->p[v->len - 1] == ' ') {
      v->len--; /* Trim trailing spaces in header value */
    }

    /*
     * If header value is empty - skip it and go to next (if any).
     * NOTE: Do not add it to headers_values because such addition changes API
     * behaviour
     */
    if (k->len != 0 && v->len == 0) {
      continue;
    }

    if (k->len == 0 || v->len == 0) {
      k->p = v->p = NULL;
      k->len = v->len = 0;
      break;
    }

    if (!mg_ncasecmp(k->p, "Content-Length", 14)) {
      req->body.len = (size_t) to64(v->p);
      req->message.len = len + req->body.len;
    }

    i++;
  }

  return s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, 0x20(%rsp)
movq %rdi, %rbp
leaq 0x78(%rcx), %rax
movq %rax, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
leaq 0x2f8(%rcx), %r12
movslq %edx, %rax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
movslq %r15d, %r14
shlq $0x4, %r14
movq 0x18(%rsp), %rax
leaq (%rax,%r14), %rbx
leaq (%r12,%r14), %r13
movq %rbp, %rdi
movq 0x20(%rsp), %rbp
movq %rbp, %rsi
leaq 0xac87(%rip), %rdx      # 0x16463
movq %rbx, %rcx
callq 0xb701
movq %rax, %rdi
movq %rbp, %rsi
leaq 0xaffa(%rip), %rdx      # 0x167eb
movq %r13, %rcx
callq 0xb701
movq %rax, %rbp
movq 0x8(%r12,%r14), %rax
testq %rax, %rax
je 0xb81d
movq (%r13), %rcx
decq %rax
cmpb $0x20, (%rcx,%rax)
jne 0xb826
movq %rax, 0x8(%r13)
addq $-0x1, %rax
jb 0xb80d
cmpq $0x0, 0x8(%rbx)
jne 0xb86a
jmp 0xb876
cmpq $0x0, 0x8(%rbx)
je 0xb876
movq (%rbx), %rdi
movl $0xe, %edx
leaq 0xac2a(%rip), %rsi      # 0x16466
callq 0x6bc6
testl %eax, %eax
jne 0xb867
movq (%r13), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3330
movq 0x10(%rsp), %rcx
movq %rax, 0x18(%rcx)
addq 0x8(%rsp), %rax
movq %rax, 0x8(%rcx)
incl %r15d
cmpl $0x27, %r15d
jl 0xb7b6
jmp 0xb887
xorl %eax, %eax
movq %rax, (%r13)
movq %rax, (%rbx)
movq %rax, 0x8(%r13)
movq %rax, 0x8(%rbx)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_get_http_header
struct mg_str *mg_get_http_header(struct http_message *hm, const char *name) {
  size_t i, len = strlen(name);

  for (i = 0; hm->header_names[i].len > 0; i++) {
    struct mg_str *h = &hm->header_names[i], *v = &hm->header_values[i];
    if (h->p != NULL && h->len == len && !mg_ncasecmp(h->p, name, len))
      return v;
  }

  return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x3180
movq %rax, %r15
movq 0x80(%rbx), %rax
testq %rax, %rax
je 0xb8f7
addq $0x2f8, %rbx            # imm = 0x2F8
movq -0x280(%rbx), %rdi
testq %rdi, %rdi
setne %cl
cmpq %r15, %rax
sete %al
andb %cl, %al
cmpb $0x1, %al
jne 0xb8e7
movq %r14, %rsi
movq %r15, %rdx
callq 0x6bc6
testl %eax, %eax
je 0xb8f9
movq -0x268(%rbx), %rax
addq $0x10, %rbx
testq %rax, %rax
jne 0xb8bf
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_get_endpoint_handler
struct mg_http_endpoint *mg_http_get_endpoint_handler(struct mg_connection *nc,
                                                      struct mg_str *uri_path) {
  struct mg_http_proto_data *pd;
  struct mg_http_endpoint *ret = NULL;
  int matched, matched_max = 0;
  struct mg_http_endpoint *ep;

  if (nc == NULL) {
    return NULL;
  }

  pd = mg_http_get_proto_data(nc);

  ep = pd->endpoints;
  while (ep != NULL) {
    if ((matched = mg_match_prefix_n(ep->uri_pattern, *uri_path)) != -1) {
      if (matched > matched_max) {
        /* Looking for the longest suitable handler */
        ret = ep;
        matched_max = matched;
      }
    }

    ep = ep->next;
  }

  return ret;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0xb988
movq %rsi, %rbx
movq %rdi, %r14
movq 0x88(%rdi), %rax
testq %rax, %rax
jne 0xb945
movl $0x1, %edi
movl $0x58, %esi
callq 0x3300
movq %rax, 0x88(%r14)
leaq 0x77c0(%rip), %rcx      # 0x130fe
movq %rcx, 0x90(%r14)
movq 0x38(%rax), %r15
xorl %r12d, %r12d
testq %r15, %r15
je 0xb988
xorl %r14d, %r14d
movq 0x8(%r15), %rdi
movq 0x10(%r15), %rsi
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
callq 0x77c3
cmpl $-0x1, %eax
setne %cl
cmpl %r12d, %eax
setg %dl
testb %dl, %cl
cmovneq %r15, %r14
cmovnel %eax, %r12d
movq (%r15), %r15
testq %r15, %r15
jne 0xb954
jmp 0xb98b
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: deliver_chunk
static void deliver_chunk(struct mg_connection *c, struct http_message *hm,
                          int req_len) {
  /* Incomplete message received. Send MG_EV_HTTP_CHUNK event */
  hm->body.len = c->recv_mbuf.len - req_len;
  c->flags &= ~MG_F_DELETE_CHUNK;
  mg_call(c, c->handler, c->user_data, MG_EV_HTTP_CHUNK, hm);
  /* Delete processed data if user set MG_F_DELETE_CHUNK flag */
  if (c->flags & MG_F_DELETE_CHUNK) c->recv_mbuf.len = req_len;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rcx
movq %rdi, %rbx
movq 0x48(%rdi), %rax
movl %edx, %r14d
subq %r14, %rax
movq %rax, 0x18(%rsi)
andb $-0x21, 0xc9(%rdi)
movq 0x98(%rdi), %rsi
movl $0x66, %edx
callq 0x7979
testb $0x20, 0xc9(%rbx)
je 0xc117
movq %r14, 0x48(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_call_endpoint_handler
static void mg_http_call_endpoint_handler(struct mg_connection *nc, int ev,
                                          struct http_message *hm) {
  struct mg_http_proto_data *pd = mg_http_get_proto_data(nc);
  void *user_data = nc->user_data;

  if (ev == MG_EV_HTTP_REQUEST
#if MG_ENABLE_HTTP_STREAMING_MULTIPART
      || ev == MG_EV_HTTP_MULTIPART_REQUEST
#endif
      ) {
    struct mg_http_endpoint *ep =
        mg_http_get_endpoint_handler(nc->listener, &hm->uri);
    if (ep != NULL) {
#if MG_ENABLE_FILESYSTEM && !MG_DISABLE_HTTP_DIGEST_AUTH
      if (!mg_http_is_authorized(hm, hm->uri, 0 /* is_directory */,
                                 ep->auth_domain, ep->auth_file,
                                 1 /* is_global_pass_file */)) {
        mg_http_send_digest_auth_request(nc, ep->auth_domain);
        return;
      }
#endif
      pd->endpoint_handler = ep->handler;
#if MG_ENABLE_CALLBACK_USERDATA
      user_data = ep->user_data;
#endif
    }
  }
  mg_call(nc, pd->endpoint_handler ? pd->endpoint_handler : nc->handler,
          user_data, ev, hm);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
movq 0x88(%rdi), %r15
testq %r15, %r15
jne 0xc166
movl $0x1, %edi
movl $0x58, %esi
callq 0x3300
movq %rax, %r15
movq %rax, 0x88(%rbx)
leaq 0x6f9f(%rip), %rax      # 0x130fe
movq %rax, 0x90(%rbx)
cmpl $0x64, %ebp
jne 0xc1ae
movq 0x10(%rbx), %rdi
leaq 0x30(%r14), %rsi
callq 0xb902
testq %rax, %rax
je 0xc1ae
movq %rax, %r12
movq 0x18(%rax), %r8
movq 0x20(%rax), %r9
movq 0x30(%r14), %rsi
movq 0x38(%r14), %rdx
movl $0x1, (%rsp)
movq %r14, %rdi
xorl %ecx, %ecx
callq 0x131da
testl %eax, %eax
je 0xc1d7
movq 0x28(%r12), %rax
movq %rax, 0x40(%r15)
movq 0x40(%r15), %rsi
testq %rsi, %rsi
jne 0xc1be
movq 0x98(%rbx), %rsi
movq %rbx, %rdi
movl %ebp, %edx
movq %r14, %rcx
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7979
movq 0x18(%r12), %r14
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd 0x9113(%rip), %xmm0     # 0x15308
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rax, %rcx
leaq 0xa578(%rip), %rsi      # 0x1677f
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x7ff5
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_ws_handshake
MG_INTERNAL void mg_ws_handshake(struct mg_connection *nc,
                                 const struct mg_str *key,
                                 struct http_message *hm) {
  static const char *magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
  const uint8_t *msgs[2] = {(const uint8_t *) key->p, (const uint8_t *) magic};
  const size_t msg_lens[2] = {key->len, 36};
  unsigned char sha[20];
  char b64_sha[30];
  struct mg_str *s;

  mg_hash_sha1_v(2, msgs, msg_lens, sha);
  mg_base64_encode(sha, sizeof(sha), b64_sha);
  mg_printf(nc, "%s",
            "HTTP/1.1 101 Switching Protocols\r\n"
            "Upgrade: websocket\r\n"
            "Connection: Upgrade\r\n");

  s = mg_get_http_header(hm, "Sec-WebSocket-Protocol");
  if (s != NULL) {
    mg_printf(nc, "Sec-WebSocket-Protocol: %.*s\r\n", (int) s->len, s->p);
  }
  mg_printf(nc, "Sec-WebSocket-Accept: %s%s", b64_sha, "\r\n\r\n");

  DBG(("%p %.*s %s", nc, (int) key->len, key->p, b64_sha));
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rax
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
leaq 0xae2f(%rip), %rax      # 0x17558
movq %rax, 0x8(%rsi)
movq 0x8(%r14), %rax
leaq 0x20(%rsp), %rdx
movq %rax, (%rdx)
movq $0x24, 0x8(%rdx)
leaq 0x40(%rsp), %r12
movl $0x2, %edi
movq %r12, %rcx
callq 0x10724
movq %rsp, %rdx
movq %r12, %rdi
movl $0x14, %esi
callq 0x4746
leaq 0x98a9(%rip), %rsi      # 0x16013
leaq 0xae0c(%rip), %rdx      # 0x1757d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7ff5
leaq 0xae47(%rip), %rsi      # 0x175c9
movq %r15, %rdi
callq 0xb896
testq %rax, %rax
je 0xc7a6
movl 0x8(%rax), %edx
movq (%rax), %rcx
leaq 0x9912(%rip), %rsi      # 0x160ae
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7ff5
leaq 0xae33(%rip), %rsi      # 0x175e0
leaq 0xa035(%rip), %rcx      # 0x167e9
movq %rsp, %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7ff5
leaq 0xae33(%rip), %rsi      # 0x175fb
leaq 0x8dff(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0xc7f8
movl 0x8(%r14), %edx
movq (%r14), %rcx
leaq 0xae20(%rip), %rdi      # 0x1760b
movq %rsp, %r8
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4539
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_response_line_s
void mg_send_response_line_s(struct mg_connection *nc, int status_code,
                             const struct mg_str extra_headers) {
  mg_printf(nc, "HTTP/1.1 %d %s\r\nServer: %s\r\n", status_code,
            mg_status_message(status_code), mg_version_header);
  if (extra_headers.len > 0) {
    mg_printf(nc, "%.*s\r\n", (int) extra_headers.len, extra_headers.p);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r15
movl %esi, %edi
callq 0xc813
leaq 0x921f(%rip), %rsi      # 0x15b35
leaq 0x9c0e(%rip), %r8       # 0x1652b
movq %r15, %rdi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x7ff5
testq %r14, %r14
je 0xc952
leaq 0xa111(%rip), %rsi      # 0x16a49
movq %r15, %rdi
movl %r14d, %edx
movq %rbx, %rcx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x7ff5
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_send_redirect
void mg_http_send_redirect(struct mg_connection *nc, int status_code,
                           const struct mg_str location,
                           const struct mg_str extra_headers) {
  char bbody[100], *pbody = bbody;
  int bl = mg_asprintf(&pbody, sizeof(bbody),
                       "<p>Moved <a href='%.*s'>here</a>.\r\n",
                       (int) location.len, location.p);
  char bhead[150], *phead = bhead;
  mg_asprintf(&phead, sizeof(bhead),
              "Location: %.*s\r\n"
              "Content-Type: text/html\r\n"
              "Content-Length: %d\r\n"
              "Cache-Control: no-cache\r\n"
              "%.*s%s",
              (int) location.len, location.p, bl, (int) extra_headers.len,
              extra_headers.p, (extra_headers.len > 0 ? "\r\n" : ""));
  mg_send_response_line(nc, status_code, phead);
  if (phead != bhead) MG_FREE(phead);
  mg_send(nc, pbody, bl);
  if (pbody != bbody) MG_FREE(pbody);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %r9, %r15
movq %r8, 0x10(%rsp)
movq %rcx, %r12
movq %rdx, %r14
movl %esi, 0x4(%rsp)
movq %rdi, %rbx
leaq 0x20(%rsp), %rax
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x9193(%rip), %rdx      # 0x15b52
movl $0x64, %esi
movq %r14, %r8
xorl %eax, %eax
callq 0x7557
movl %eax, %ebp
leaq 0x90(%rsp), %rax
leaq 0x18(%rsp), %r13
movq %rax, (%r13)
testq %r15, %r15
leaq 0x9e02(%rip), %rax      # 0x167ed
leaq 0x9df9(%rip), %r10      # 0x167eb
cmoveq %rax, %r10
subq $0x8, %rsp
leaq 0x9175(%rip), %rdx      # 0x15b76
movl $0x96, %esi
movq %r13, %rdi
movl %r12d, %ecx
movq %r14, %r8
movl %ebp, %r9d
xorl %eax, %eax
pushq %r10
pushq 0x20(%rsp)
pushq %r15
callq 0x7557
addq $0x20, %rsp
movq (%r13), %rdi
callq 0x6b26
movq %rdx, %rcx
movq %rbx, %rdi
movl 0x4(%rsp), %esi
movq %rax, %rdx
callq 0xc8f6
movq (%r13), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0xca56
callq 0x3060
movq 0x8(%rsp), %r14
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movslq %ebp, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x48(%rcx,%rax,4)
movq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xca9e
callq 0x3060
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_head
void mg_send_head(struct mg_connection *c, int status_code,
                  int64_t content_length, const char *extra_headers) {
  mg_send_response_line(c, status_code, extra_headers);
  if (content_length < 0) {
    mg_printf(c, "%s", "Transfer-Encoding: chunked\r\n");
  } else {
    mg_printf(c, "Content-Length: %" INT64_FMT "\r\n", content_length);
  }
  mg_send(c, "\r\n", 2);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
movq %rcx, %rdi
callq 0x6b26
movq %rdx, %rcx
movq %rbx, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xc8f6
testq %r14, %r14
js 0xcae8
leaq 0x9110(%rip), %rsi      # 0x15bf0
movq %rbx, %rdi
movq %r14, %rdx
jmp 0xcaf9
leaq 0x9524(%rip), %rsi      # 0x16013
leaq 0x90dd(%rip), %rdx      # 0x15bd3
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7ff5
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq 0x48(%rcx,%rax,4), %rax
leaq 0x9cbd(%rip), %rsi      # 0x167eb
movl $0x2, %edx
movq %rbx, %rdi
popq %rbx
popq %r14
popq %rbp
jmpq *%rax
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_send_error
void mg_http_send_error(struct mg_connection *nc, int code,
                        const char *reason) {
  if (!reason) reason = mg_status_message(code);
  LOG(LL_DEBUG, ("%p %d %s", nc, code, reason));
  mg_send_head(nc, code, strlen(reason),
               "Content-Type: text/plain\r\nConnection: close");
  mg_send(nc, reason, strlen(reason));
  nc->flags |= MG_F_SEND_AND_CLOSE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
testq %rdx, %rdx
jne 0xcb5a
movl %ebp, %edi
callq 0xc813
movq %rax, %r14
leaq 0x90a5(%rip), %rsi      # 0x15c06
leaq 0x8a66(%rip), %rdx      # 0x155ce
movl $0x3, %edi
callq 0x4447
testl %eax, %eax
je 0xcb8c
leaq 0x909c(%rip), %rdi      # 0x15c19
movq %rbx, %rsi
movl %ebp, %edx
movq %r14, %rcx
xorl %eax, %eax
callq 0x4539
movq %r14, %rdi
callq 0x3180
leaq 0x9087(%rip), %rcx      # 0x15c22
movq %rbx, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xcab0
movq %r14, %rdi
callq 0x3180
movq %rax, %r15
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movslq %r15d, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x48(%rcx,%rax,4)
orb $0x4, 0xc9(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_url_decode
int mg_url_decode(const char *src, int src_len, char *dst, int dst_len,
                  int is_form_url_encoded) {
  int i, j, a, b;
#define HEXTOI(x) (isdigit(x) ? x - '0' : x - 'W')

  for (i = j = 0; i < src_len && j < dst_len - 1; i++, j++) {
    if (src[i] == '%') {
      if (i < src_len - 2 && isxdigit(*(const unsigned char *) (src + i + 1)) &&
          isxdigit(*(const unsigned char *) (src + i + 2))) {
        a = tolower(*(const unsigned char *) (src + i + 1));
        b = tolower(*(const unsigned char *) (src + i + 2));
        dst[j] = (char) ((HEXTOI(a) << 4) | HEXTOI(b));
        i += 2;
      } else {
        return -1;
      }
    } else if (is_form_url_encoded && src[i] == '+') {
      dst[j] = ' ';
    } else {
      dst[j] = src[i];
    }
  }

  dst[j] = '\0'; /* Null-terminate the destination */

  return i >= src_len ? j : -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, 0x4(%rsp)
movq %rdi, %r12
testl %esi, %esi
setg %al
setle %dil
cmpl $0x2, %ecx
setl %r8b
xorl %ebp, %ebp
orb %dil, %r8b
jne 0xd0e5
decl %ecx
leal -0x2(%rsi), %eax
movl %eax, (%rsp)
xorl %ebp, %ebp
xorl %ebx, %ebx
movq %rdx, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movslq %ebx, %r14
movb (%r12,%r14), %al
cmpb $0x25, %al
jne 0xd0bc
cmpl (%rsp), %ebx
jge 0xd0f7
callq 0x3660
movq (%rax), %r15
movq %r12, %rax
movzbl 0x1(%r12,%r14), %r12d
testb $0x10, 0x1(%r15,%r12,2)
je 0xd0f7
movzbl 0x2(%rax,%r14), %r14d
testb $0x10, 0x1(%r15,%r14,2)
je 0xd0f7
callq 0x3650
movq (%rax), %rax
movslq (%rax,%r12,4), %rcx
movslq (%rax,%r14,4), %rax
movzwl (%r15,%rcx,2), %edx
xorl %esi, %esi
btl $0xb, %edx
setae %sil
leal (%rsi,%rsi,8), %edx
addl %ecx, %edx
shll $0x4, %edx
movzwl (%r15,%rax,2), %ecx
leal 0xd0(%rax), %esi
addl $0xa9, %eax
btl $0xb, %ecx
cmovbl %esi, %eax
orl %edx, %eax
movq 0x20(%rsp), %rdx
movb %al, (%rdx,%rbp)
addl $0x2, %ebx
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %r12
jmp 0xd0d0
cmpl $0x0, 0x4(%rsp)
je 0xd0cd
cmpb $0x2b, %al
jne 0xd0cd
movb $0x20, (%rdx,%rbp)
jmp 0xd0d0
movb %al, (%rdx,%rbp)
incl %ebx
incq %rbp
cmpl %esi, %ebx
setl %al
jge 0xd0e5
cmpq %rcx, %rbp
jb 0xd019
movl %ebp, %ecx
movb $0x0, (%rdx,%rcx)
testb %al, %al
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmovel %ebp, %r13d
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r14
testq %rdx, %rdx
sete %al
testq %rcx, %rcx
sete %cl
orb %al, %cl
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jne 0xd1d5
movq %rdx, %r12
movq %rdi, %r13
movq (%rdi), %r15
testq %r15, %r15
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0xd1cb
movq 0x8(%r13), %rbx
testq %rbx, %rbx
je 0xd1cb
movq %rsi, 0x20(%rsp)
movq %rsi, %rdi
callq 0x3180
addq %rbx, %r15
movq %r12, 0x18(%rsp)
movb $0x0, (%r12)
movq (%r13), %rbx
movq %rax, 0x8(%rsp)
leaq (%rbx,%rax), %r12
movl $0xfffffffc, %ebp       # imm = 0xFFFFFFFC
cmpq %r15, %r12
jae 0xd1d5
movq %r14, 0x10(%rsp)
xorl %r14d, %r14d
leaq (%rbx,%r14), %rsi
cmpq (%r13), %rsi
je 0xd1a0
cmpb $0x26, -0x1(%rbx,%r14)
jne 0xd1ba
cmpb $0x3d, (%r12,%r14)
jne 0xd1ba
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rdx
callq 0x6bc6
testl %eax, %eax
je 0xd1e6
leaq (%r12,%r14), %rax
incq %rax
incq %r14
cmpq %r15, %rax
jb 0xd18e
jmp 0xd1d5
movb $0x0, (%r12)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %r14, %r12
incq %r12
movq 0x8(%rsp), %r13
movq %r13, %rdx
notq %rdx
addq %r15, %rdx
subq %rbx, %rdx
subq %r14, %rdx
movq %r12, %rdi
movl $0x26, %esi
callq 0x32c0
addl %r13d, %ebx
testq %rax, %rax
notl %ebx
cmovnel %eax, %r15d
addl %ebx, %r15d
subl %r14d, %r15d
movq %r12, %rdi
movl %r15d, %esi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movl $0x1, %r8d
callq 0xcfc2
cmpl $-0x1, %eax
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
cmovnel %eax, %ebp
jmp 0xd1d5
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_http_chunk
void mg_send_http_chunk(struct mg_connection *nc, const char *buf, size_t len) {
  char chunk_size[50];
  int n;

  n = snprintf(chunk_size, sizeof(chunk_size), "%lX\r\n", (unsigned long) len);
  mg_send(nc, chunk_size, n);
  mg_send(nc, buf, len);
  mg_send(nc, "\r\n", 2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x8af1(%rip), %rdx      # 0x15d54
movq %rsp, %r12
movl $0x32, %esi
movq %r12, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x31e0
movl %eax, %ebp
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movslq %ebp, %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq *0x48(%rcx,%rax,4)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movslq %r15d, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x48(%rcx,%rax,4)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
leaq 0x94ea(%rip), %rsi      # 0x167eb
movl $0x2, %edx
movq %rbx, %rdi
callq *0x48(%rcx,%rax,4)
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_printf_http_chunk
void mg_printf_http_chunk(struct mg_connection *nc, const char *fmt, ...) {
  char mem[MG_VPRINTF_BUFFER_SIZE], *buf = mem;
  int len;
  va_list ap;

  va_start(ap, fmt);
  len = mg_avprintf(&buf, sizeof(mem), fmt, ap);
  va_end(ap);

  if (len >= 0) {
    mg_send_http_chunk(nc, buf, len);
  }

  /* LCOV_EXCL_START */
  if (buf != mem && buf != NULL) {
    MG_FREE(buf);
  }
  /* LCOV_EXCL_STOP */
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %r10
movq %rdi, %rbx
leaq 0x30(%rsp), %rsi
movq %rdx, 0x10(%rsi)
movq %rcx, 0x18(%rsi)
movq %r8, 0x20(%rsi)
movq %r9, 0x28(%rsi)
testb %al, %al
je 0xd37d
movaps %xmm0, 0x60(%rsp)
movaps %xmm1, 0x70(%rsp)
movaps %xmm2, 0x80(%rsp)
movaps %xmm3, 0x90(%rsp)
movaps %xmm4, 0xa0(%rsp)
movaps %xmm5, 0xb0(%rsp)
movaps %xmm6, 0xc0(%rsp)
movaps %xmm7, 0xd0(%rsp)
leaq 0xe0(%rsp), %r14
leaq 0x8(%rsp), %rdi
movq %r14, (%rdi)
leaq 0x10(%rsp), %rcx
movq %rsi, 0x10(%rcx)
leaq 0x160(%rsp), %rax
movq %rax, 0x8(%rcx)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rcx)
movl $0x64, %esi
movq %r10, %rdx
callq 0x75d7
testl %eax, %eax
js 0xd3cf
movq 0x8(%rsp), %rsi
movl %eax, %edx
movq %rbx, %rdi
callq 0xd247
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0xd3e9
callq 0x3060
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_printf_html_escape
void mg_printf_html_escape(struct mg_connection *nc, const char *fmt, ...) {
  char mem[MG_VPRINTF_BUFFER_SIZE], *buf = mem;
  int i, j, len;
  va_list ap;

  va_start(ap, fmt);
  len = mg_avprintf(&buf, sizeof(mem), fmt, ap);
  va_end(ap);

  if (len >= 0) {
    for (i = j = 0; i < len; i++) {
      if (buf[i] == '<' || buf[i] == '>') {
        mg_send(nc, buf + j, i - j);
        mg_send(nc, buf[i] == '<' ? "&lt;" : "&gt;", 4);
        j = i + 1;
      }
    }
    mg_send(nc, buf + j, i - j);
  }

  /* LCOV_EXCL_START */
  if (buf != mem && buf != NULL) {
    MG_FREE(buf);
  }
  /* LCOV_EXCL_STOP */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rsi, %r10
movq %rdi, %rbx
leaq 0xa0(%rsp), %rsi
movq %rdx, 0x10(%rsi)
movq %rcx, 0x18(%rsi)
movq %r8, 0x20(%rsi)
movq %r9, 0x28(%rsi)
testb %al, %al
je 0xd468
movapd %xmm0, 0xd0(%rsp)
movaps %xmm1, 0xe0(%rsp)
movaps %xmm2, 0xf0(%rsp)
movaps %xmm3, 0x100(%rsp)
movaps %xmm4, 0x110(%rsp)
movaps %xmm5, 0x120(%rsp)
movaps %xmm6, 0x130(%rsp)
movaps %xmm7, 0x140(%rsp)
leaq 0x30(%rsp), %r14
movq %rsp, %rdi
movq %r14, (%rdi)
leaq 0x10(%rsp), %rcx
movq %rsi, 0x10(%rcx)
leaq 0x190(%rsp), %rax
movq %rax, 0x8(%rcx)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rcx)
movl $0x64, %esi
movq %r10, %rdx
callq 0x75d7
testl %eax, %eax
js 0xd5b5
movl %eax, 0xc(%rsp)
je 0xd570
movl %eax, %r12d
xorl %r13d, %r13d
leaq 0x889e(%rip), %rbp      # 0x15d5f
xorl %eax, %eax
movq (%rsp), %r14
movzbl (%r14,%r13), %ecx
orl $0x2, %ecx
cmpl $0x3e, %ecx
jne 0xd562
cltq
addq %rax, %r14
movl %r13d, %r15d
subl %eax, %r15d
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movslq %r15d, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x48(%rcx,%rax,4)
movq (%rsp), %rax
cmpb $0x3c, (%rax,%r13)
movq %rbp, %r14
leaq 0x8835(%rip), %rax      # 0x15d5a
cmoveq %rax, %r14
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movl $0x4, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x48(%rcx,%rax,4)
incq %r13
movl %r13d, %eax
jmp 0xd565
incq %r13
cmpq %r12, %r13
jne 0xd4c3
jmp 0xd572
xorl %eax, %eax
cltq
movq (%rsp), %r14
addq %rax, %r14
movl 0xc(%rsp), %ebp
subl %eax, %ebp
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movslq %ebp, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x48(%rcx,%rax,4)
leaq 0x30(%rsp), %r14
movq (%rsp), %rdi
cmpq %r14, %rdi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0xd5ce
callq 0x3060
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_parse_http_basic_auth
int mg_parse_http_basic_auth(struct mg_str *hdr, char *user, size_t user_len,
                             char *pass, size_t pass_len) {
  char *buf = NULL;
  char fmt[64];
  int res = 0;

  if (mg_strncmp(*hdr, mg_mk_str("Basic "), 6) != 0) return -1;

  buf = (char *) MG_MALLOC(hdr->len);
  cs_base64_decode((unsigned char *) hdr->p + 6, hdr->len, buf, NULL);

  /* e.g. "%123[^:]:%321[^\n]" */
  snprintf(fmt, sizeof(fmt), "%%%" SIZE_T_FMT "[^:]:%%%" SIZE_T_FMT "[^\n]",
           user_len - 1, pass_len - 1);
  if (sscanf(buf, fmt, user, pass) == 0) {
    res = -1;
  }

  MG_FREE(buf);
  return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r15
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, %rbx
leaq 0x88cc(%rip), %rdi      # 0x16106
callq 0x6b26
movq %rdx, %rcx
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
movl $0x6, %r8d
movq %rax, %rdx
callq 0x6d47
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0xd8db
movq %r14, 0x8(%rsp)
movq 0x8(%rbx), %r14
movq %r14, %rdi
callq 0x33e0
movq %rbp, (%rsp)
movq %rax, %rbp
movq (%rbx), %rdi
addq $0x6, %rdi
xorl %r13d, %r13d
movl %r14d, %esi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x4990
decq %r12
decq %r15
leaq 0x84d5(%rip), %rdx      # 0x15d72
leaq 0x10(%rsp), %rbx
movl $0x40, %esi
movq %rbx, %rdi
movq %r12, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x31e0
movq %rbp, %rdi
movq %rbx, %rsi
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
xorl %eax, %eax
callq 0x3420
cmpl $0x1, %eax
sbbl %r13d, %r13d
movq %rbp, %rdi
callq 0x3060
movl %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_hash_md5_v
void mg_hash_md5_v(size_t num_msgs, const uint8_t *msgs[],
                   const size_t *msg_lens, uint8_t *digest) {
  size_t i;
  cs_md5_ctx md5_ctx;
  cs_md5_init(&md5_ctx);
  for (i = 0; i < num_msgs; i++) {
    cs_md5_update(&md5_ctx, msgs[i], msg_lens[i]);
  }
  cs_md5_final(digest, &md5_ctx);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rcx, %rbx
movaps 0x7a3b(%rip), %xmm0     # 0x15340
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rdi, %rdi
je 0xd93d
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
xorl %ebp, %ebp
movq %rsp, %r13
movq (%r15,%rbp,8), %rsi
movq (%r14,%rbp,8), %rdx
movq %r13, %rdi
callq 0x4bdb
incq %rbp
cmpq %rbp, %r12
jne 0xd925
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x5404
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: cs_md5
void cs_md5(char buf[33], ...) {
  unsigned char hash[16];
  const uint8_t *msgs[20], *p;
  size_t msg_lens[20];
  size_t num_msgs = 0;
  va_list ap;

  va_start(ap, buf);
  while ((p = va_arg(ap, const unsigned char *) ) != NULL) {
    msgs[num_msgs] = p;
    msg_lens[num_msgs] = va_arg(ap, size_t);
    num_msgs++;
  }
  va_end(ap);

  mg_hash_md5_v(num_msgs, msgs, msg_lens, hash);
  cs_to_hex(buf, hash, sizeof(hash));
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdi, %rbx
leaq 0x170(%rsp), %r10
movq %rsi, 0x8(%r10)
movq %rdx, 0x10(%r10)
movq %rcx, 0x18(%r10)
movq %r8, 0x20(%r10)
movq %r9, 0x28(%r10)
testb %al, %al
je 0xd9c4
movaps %xmm0, 0x1a0(%rsp)
movaps %xmm1, 0x1b0(%rsp)
movaps %xmm2, 0x1c0(%rsp)
movaps %xmm3, 0x1d0(%rsp)
movaps %xmm4, 0x1e0(%rsp)
movaps %xmm5, 0x1f0(%rsp)
movaps %xmm6, 0x200(%rsp)
movaps %xmm7, 0x210(%rsp)
movq %r10, 0x10(%rsp)
leaq 0x240(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movabsq $0x3000000008, %rax     # imm = 0x3000000008
movq %rax, (%rsp)
movl $0x8, %eax
xorl %edi, %edi
cmpl $0x28, %eax
ja 0xda00
movq %rcx, %rdx
movl %eax, %ecx
addq %r10, %rcx
addl $0x8, %eax
movl %eax, (%rsp)
jmp 0xda09
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq (%rcx), %rcx
testq %rcx, %rcx
je 0xda44
movq %rcx, 0xd0(%rsp,%rdi,8)
cmpl $0x28, %eax
ja 0xda2e
movq %rdx, %rcx
movl %eax, %edx
addq %r10, %rdx
addl $0x8, %eax
movl %eax, (%rsp)
jmp 0xda37
leaq 0x8(%rdx), %rcx
movq %rcx, 0x8(%rsp)
movq (%rdx), %rdx
movq %rdx, 0x30(%rsp,%rdi,8)
incq %rdi
jmp 0xd9eb
leaq 0xd0(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x20(%rsp), %r14
movq %r14, %rcx
callq 0xd8ed
movl $0x10, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x747c
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_create_digest_auth_header
int mg_http_create_digest_auth_header(char *buf, size_t buf_len,
                                      const char *method, const char *uri,
                                      const char *auth_domain, const char *user,
                                      const char *passwd) {
  static const char colon[] = ":", qop[] = "auth";
  static const size_t one = 1;
  char ha1[33], resp[33], cnonce[40];

  snprintf(cnonce, sizeof(cnonce), "%x", (unsigned int) mg_time());
  cs_md5(ha1, user, (size_t) strlen(user), colon, one, auth_domain,
         (size_t) strlen(auth_domain), colon, one, passwd,
         (size_t) strlen(passwd), NULL);
  mg_mkmd5resp(method, strlen(method), uri, strlen(uri), ha1, sizeof(ha1) - 1,
               cnonce, strlen(cnonce), "1", one, cnonce, strlen(cnonce), qop,
               sizeof(qop) - 1, resp);
  return snprintf(buf, buf_len,
                  "Authorization: Digest username=\"%s\","
                  "realm=\"%s\",uri=\"%s\",qop=%s,nc=1,cnonce=%s,"
                  "nonce=%s,response=%s\r\n",
                  user, auth_domain, uri, qop, cnonce, cnonce, resp);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r9, %r15
movq %r8, %r14
movq %rcx, (%rsp)
movq %rdx, %r12
movq %rsi, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
movq 0xe0(%rsp), %rbx
callq 0x4aab
cvttsd2si %xmm0, %rcx
leaq 0x82cc(%rip), %rdx      # 0x15d86
leaq 0x50(%rsp), %rdi
movl $0x28, %esi
xorl %eax, %eax
callq 0x31e0
movq %r15, %rdi
callq 0x3180
movq %rax, %rbp
movq %r14, %rdi
movq %r14, 0x8(%rsp)
callq 0x3180
movq %rax, %r13
movq %rbx, %rdi
callq 0x3180
movq %rax, %r10
movl $0x1, %r11d
leaq 0x7968(%rip), %rcx      # 0x15466
leaq 0x20(%rsp), %rdi
movl $0x1, %r8d
movq %r15, %rsi
movq %rbp, %rdx
movq %r14, %r9
movl $0x0, %eax
pushq $0x0
pushq %r10
pushq %rbx
pushq %r11
pushq %rcx
pushq %r13
callq 0xd957
addq $0x30, %rsp
movq %r12, %rdi
callq 0x3180
movq %rax, %r13
movq (%rsp), %rbx
movq %rbx, %rdi
callq 0x3180
movq %rax, %rbp
leaq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x3180
subq $0x8, %rsp
leaq 0x88(%rsp), %r10
leaq 0x78dc(%rip), %r11      # 0x15440
movl $0x20, %r9d
movq %r12, %rdi
movq %r13, %rsi
leaq 0x28(%rsp), %r8
movq %rbx, %rdx
movq %rbp, %rcx
pushq %r10
movq %r10, %rbp
pushq $0x4
pushq %r11
movq %r11, %r13
pushq %rax
movq %r14, %r11
pushq %r14
movl $0x1, %r14d
pushq %r14
leaq 0x8cda(%rip), %r10      # 0x16876
pushq %r10
pushq %rax
pushq %r11
movq %r11, %r12
callq 0xdbe9
addq $0x50, %rsp
leaq 0x81d5(%rip), %rdx      # 0x15d89
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq %r15, %rcx
movq 0x8(%rsp), %r8
movq %rbx, %r9
xorl %eax, %eax
pushq %rbp
pushq %r12
pushq %r12
pushq %r13
callq 0x31e0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_reverse_proxy_handler
static void mg_reverse_proxy_handler(struct mg_connection *nc, int ev,
                                     void *ev_data MG_UD_ARG(void *user_data)) {
  struct http_message *hm = (struct http_message *) ev_data;
  struct mg_http_proto_data *pd = mg_http_get_proto_data(nc);

  if (pd == NULL || pd->reverse_proxy_data.linked_conn == NULL) {
    DBG(("%p: upstream closed", nc));
    return;
  }

  switch (ev) {
    case MG_EV_CONNECT:
      if (*(int *) ev_data != 0) {
        mg_http_send_error(pd->reverse_proxy_data.linked_conn, 502, NULL);
      }
      break;
    /* TODO(mkm): handle streaming */
    case MG_EV_HTTP_REPLY:
      mg_send(pd->reverse_proxy_data.linked_conn, hm->message.p,
              hm->message.len);
      pd->reverse_proxy_data.linked_conn->flags |= MG_F_SEND_AND_CLOSE;
      nc->flags |= MG_F_CLOSE_IMMEDIATELY;
      break;
    case MG_EV_CLOSE:
      pd->reverse_proxy_data.linked_conn->flags |= MG_F_SEND_AND_CLOSE;
      break;
  }

#if MG_ENABLE_CALLBACK_USERDATA
  (void) user_data;
#endif
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %rbx
movq 0x88(%rdi), %r14
testq %r14, %r14
jne 0xe88b
movl $0x1, %edi
movl $0x58, %esi
callq 0x3300
movq %rax, %r14
movq %rax, 0x88(%rbx)
leaq 0x487f(%rip), %rax      # 0x130fe
movq %rax, 0x90(%rbx)
testq %r14, %r14
je 0xe8ce
movq 0x48(%r14), %r12
testq %r12, %r12
je 0xe8ce
cmpl $0x65, %ebp
je 0xe914
cmpl $0x5, %ebp
je 0xe909
cmpl $0x2, %ebp
jne 0xe964
cmpl $0x0, (%r15)
je 0xe964
movq %r12, %rdi
movl $0x1f6, %esi            # imm = 0x1F6
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcb3c
leaq 0x7c96(%rip), %rsi      # 0x1656b
leaq 0x6cf2(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0xe964
leaq 0x7c93(%rip), %rdi      # 0x16584
movq %rbx, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4539
orb $0x4, 0xc9(%r12)
jmp 0xe964
movq (%r15), %r13
movslq 0x8(%r15), %r15
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r12)
movl 0xc8(%r12), %eax
andl $0x2, %eax
movq 0xc0(%r12), %rcx
movq 0x10(%rcx), %rcx
movq %r12, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq *0x48(%rcx,%rax,4)
movq 0x48(%r14), %rax
orq $0x400, 0xc8(%rax) # imm = 0x400
orb $0x8, 0xc9(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_basic_auth_header
void mg_basic_auth_header(const struct mg_str user, const struct mg_str pass,
                          struct mbuf *buf) {
  const char *header_prefix = "Authorization: Basic ";
  const char *header_suffix = "\r\n";

  struct cs_base64_ctx ctx;
  cs_base64_init(&ctx, mg_mbuf_append_base64_putc, buf);

  mbuf_append(buf, header_prefix, strlen(header_prefix));

  cs_base64_update(&ctx, user.p, user.len);
  if (pass.len > 0) {
    cs_base64_update(&ctx, ":", 1);
    cs_base64_update(&ctx, pass.p, pass.len);
  }
  cs_base64_finish(&ctx);
  mbuf_append(buf, header_suffix, strlen(header_suffix));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r13
movq %rsp, %rbp
movl $0x0, 0xc(%rbp)
leaq 0xef5(%rip), %rax       # 0x10e73
movq %rax, (%rbp)
movq %r8, 0x10(%rbp)
leaq 0x616a(%rip), %rsi      # 0x160f7
movl $0x15, %edx
movq %r8, %rdi
callq 0x6ae7
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x4613
testq %r14, %r14
je 0xffd2
leaq 0x54b2(%rip), %rsi      # 0x15466
movq %rsp, %r12
movl $0x1, %edx
movq %r12, %rdi
callq 0x4613
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x4613
movq %rsp, %rdi
callq 0x46ef
leaq 0x680a(%rip), %rsi      # 0x167eb
movl $0x2, %edx
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6ae7
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_register_http_endpoint_opt
void mg_register_http_endpoint_opt(struct mg_connection *nc,
                                   const char *uri_path,
                                   mg_event_handler_t handler,
                                   struct mg_http_endpoint_opts opts) {
  struct mg_http_proto_data *pd = NULL;
  struct mg_http_endpoint *new_ep = NULL;

  if (nc == NULL) return;
  new_ep = (struct mg_http_endpoint *) MG_CALLOC(1, sizeof(*new_ep));
  if (new_ep == NULL) return;

  pd = mg_http_get_proto_data(nc);
  new_ep->uri_pattern = mg_strdup(mg_mk_str(uri_path));
  if (opts.auth_domain != NULL && opts.auth_file != NULL) {
    new_ep->auth_domain = strdup(opts.auth_domain);
    new_ep->auth_file = strdup(opts.auth_file);
  }
  new_ep->handler = handler;
#if MG_ENABLE_CALLBACK_USERDATA
  new_ep->user_data = opts.user_data;
#endif
  new_ep->next = pd->endpoints;
  pd->endpoints = new_ep;
}

// Assembly:
testq %rdi, %rdi
je 0x1031a
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r13
movl $0x1, %edi
movl $0x30, %esi
callq 0x3300
testq %rax, %rax
je 0x1030c
movq %rax, %r14
leaq 0x40(%rsp), %rbp
movq 0x88(%r13), %r15
testq %r15, %r15
jne 0x102b2
movl $0x1, %edi
movl $0x58, %esi
callq 0x3300
movq %rax, %r15
movq %rax, 0x88(%r13)
leaq 0x2e53(%rip), %rax      # 0x130fe
movq %rax, 0x90(%r13)
movq %r12, %rdi
callq 0x6b26
movq %rax, %rdi
movq %rdx, %rsi
callq 0x6c14
movq %rax, 0x8(%r14)
movq %rdx, 0x10(%r14)
movq 0x8(%rbp), %rdi
movq 0x10(%rbp), %r12
testq %rdi, %rdi
setne %al
testq %r12, %r12
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x102fd
callq 0x35f0
movq %rax, 0x18(%r14)
movq %r12, %rdi
callq 0x35f0
movq %rax, 0x20(%r14)
movq %rbx, 0x28(%r14)
movq 0x38(%r15), %rax
movq %rax, (%r14)
movq %r14, 0x38(%r15)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_websocket_frame
void mg_send_websocket_frame(struct mg_connection *nc, int op, const void *data,
                             size_t len) {
  struct ws_mask_ctx ctx;
  DBG(("%p %d %d", nc, op, (int) len));
  mg_send_ws_header(nc, op, len, &ctx);
  mg_send(nc, data, len);

  mg_ws_mask_frame(&nc->send_mbuf, &ctx);

  if (op == WEBSOCKET_OP_CLOSE) {
    nc->flags |= MG_F_SEND_AND_CLOSE;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rcx, %r15
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x5cb8(%rip), %rsi      # 0x16023
leaq 0x525c(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x10396
leaq 0x534e(%rip), %rdi      # 0x156d5
movq %rbx, %rsi
movl %ebp, %edx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x4539
movq %rsp, %r12
movq %rbx, %rdi
movl %ebp, %esi
movq %r15, %rdx
movq %r12, %rcx
callq 0x103fd
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movslq %r15d, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x48(%rcx,%rax,4)
leaq 0x58(%rbx), %rdi
movq %r12, %rsi
callq 0x10543
cmpl $0x8, %ebp
jne 0x103f0
orb $0x4, 0xc9(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_ws_header
static void mg_send_ws_header(struct mg_connection *nc, int op, size_t len,
                              struct ws_mask_ctx *ctx) {
  int header_len;
  unsigned char header[10];

  header[0] = (op & WEBSOCKET_DONT_FIN ? 0x0 : 0x80) + (op & 0x0f);
  if (len < 126) {
    header[1] = (unsigned char) len;
    header_len = 2;
  } else if (len < 65535) {
    uint16_t tmp = htons((uint16_t) len);
    header[1] = 126;
    memcpy(&header[2], &tmp, sizeof(tmp));
    header_len = 4;
  } else {
    uint32_t tmp;
    header[1] = 127;
    tmp = htonl((uint32_t)((uint64_t) len >> 32));
    memcpy(&header[2], &tmp, sizeof(tmp));
    tmp = htonl((uint32_t)(len & 0xffffffff));
    memcpy(&header[6], &tmp, sizeof(tmp));
    header_len = 10;
  }

  /* client connections enable masking */
  if (nc->listener == NULL) {
    header[1] |= 1 << 7; /* set masking flag */
    mg_send(nc, header, header_len);
    ctx->mask = mg_ws_random_mask();
    mg_send(nc, &ctx->mask, sizeof(ctx->mask));
    ctx->pos = nc->send_mbuf.len;
  } else {
    mg_send(nc, header, header_len);
    ctx->pos = 0;
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdi, %r14
movl %esi, %eax
shrl %eax
andl $0x80, %eax
andl $0xf, %esi
orl %eax, %esi
addb $-0x80, %sil
movb %sil, 0xe(%rsp)
cmpq $0x7d, %rdx
ja 0x1043a
movb %dl, 0xf(%rsp)
orb $-0x80, %dl
movl $0x2, %r15d
jmp 0x1047b
cmpq $0xfffe, %rdx           # imm = 0xFFFE
ja 0x1045b
rolw $0x8, %dx
movb $0x7e, 0xf(%rsp)
movw %dx, 0x10(%rsp)
movl $0x4, %r15d
movb $-0x2, %dl
jmp 0x1047b
movb $0x7f, 0xf(%rsp)
movq %rdx, %rax
shrq $0x20, %rax
bswapl %eax
movl %eax, 0x10(%rsp)
bswapl %edx
movl %edx, 0x14(%rsp)
movl $0xa, %r15d
movb $-0x1, %dl
cmpq $0x0, 0x10(%r14)
je 0x104b8
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
leaq 0xe(%rsp), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq *0x48(%rcx,%rax,4)
xorl %eax, %eax
jmp 0x10534
leaq 0xe(%rsp), %r12
movb %dl, 0x1(%r12)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq *0x48(%rcx,%rax,4)
callq 0x3640
leaq 0x8(%rbx), %r15
movl %eax, 0x8(%rbx)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
movl $0x4, %edx
movq %r14, %rdi
movq %r15, %rsi
callq *0x48(%rcx,%rax,4)
movq 0x60(%r14), %rax
movq %rax, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_ws_mask_frame
static void mg_ws_mask_frame(struct mbuf *mbuf, struct ws_mask_ctx *ctx) {
  size_t i;
  if (ctx->pos == 0) return;
  for (i = 0; i < (mbuf->len - ctx->pos); i++) {
    mbuf->buf[ctx->pos + i] ^= ((char *) &ctx->mask)[i % 4];
  }
}

// Assembly:
movq (%rsi), %rax
testq %rax, %rax
je 0x10574
cmpq %rax, 0x8(%rdi)
je 0x10574
xorl %ecx, %ecx
movl %ecx, %edx
andl $0x3, %edx
movb 0x8(%rsi,%rdx), %dl
addq (%rdi), %rax
xorb %dl, (%rcx,%rax)
incq %rcx
movq 0x8(%rdi), %rdx
movq (%rsi), %rax
subq %rax, %rdx
cmpq %rdx, %rcx
jb 0x10553
retq