LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_tun_if_destroy_conn
void mg_tun_if_destroy_conn(struct mg_connection *nc) {
  struct mg_tun_client *client = (struct mg_tun_client *) nc->iface->data;

  if (nc->flags & MG_F_LISTENING) {
    mg_tun_destroy_client(client);
  } else if (client->disp) {
    uint32_t stream_id = (uint32_t)(uintptr_t) nc->mgr_data;
    struct mg_str msg = {NULL, 0};

    LOG(LL_DEBUG, ("closing 0x%x:", (unsigned int) stream_id));
    mg_tun_send_frame(client->disp, stream_id, MG_TUN_DATA_FRAME,
                      MG_TUN_F_END_STREAM, msg);
  }
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq 0xc0(%rdi), %rax
movq 0x8(%rax), %rbx
testb $0x1, 0xc8(%rdi)
jne 0xacb8
cmpq $0x0, 0x20(%rbx)
je 0xacc6
movl 0xb8(%rdi), %ebp
leaq 0xacf3(%rip), %rsi      # 0x15968
leaq 0xa92e(%rip), %rdx      # 0x155aa
movl $0x3, %edi
callq 0x44b4
testl %eax, %eax
je 0xac9a
leaq 0xacee(%rip), %rdi      # 0x1597f
movl %ebp, %esi
xorl %eax, %eax
callq 0x45a0
movq 0x20(%rbx), %rdi
movl %ebp, %esi
xorl %edx, %edx
movl $0x1, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xabe5
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xaccd
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_tun_if_find_conn
struct mg_connection *mg_tun_if_find_conn(struct mg_tun_client *client,
                                          uint32_t stream_id) {
  struct mg_connection *nc = NULL;

  for (nc = client->mgr->active_connections; nc != NULL; nc = nc->next) {
    if (nc->iface != client->iface || (nc->flags & MG_F_LISTENING)) {
      continue;
    }
    if (stream_id == (uint32_t)(uintptr_t) nc->mgr_data) {
      return nc;
    }
  }

  if (stream_id > client->last_stream_id) {
    /* create a new connection */
    LOG(LL_DEBUG, ("new stream 0x%x, accepting", (unsigned int) stream_id));
    nc = mg_if_accept_new_conn(client->listener);
    nc->mgr_data = (void *) (uintptr_t) stream_id;
    client->last_stream_id = stream_id;
  } else {
    LOG(LL_DEBUG,
        ("Ignoring stream 0x%x (last_stream_id 0x%x)", (unsigned int) stream_id,
         (unsigned int) client->last_stream_id));
  }

  return nc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq (%rdi), %rax
movq (%rax), %r15
testq %r15, %r15
je 0xad74
movq 0x8(%r14), %rax
cmpq %rax, 0xc0(%r15)
jne 0xad6c
testb $0x1, 0xc8(%r15)
jne 0xad6c
cmpl %ebx, 0xb8(%r15)
je 0xade3
movq (%r15), %r15
testq %r15, %r15
jne 0xad50
movl 0x1c(%r14), %ebp
leaq 0xac0e(%rip), %rsi      # 0x1598d
leaq 0xa824(%rip), %rdx      # 0x155aa
movl $0x3, %edi
callq 0x44b4
cmpl %ebx, %ebp
jae 0xadc3
testl %eax, %eax
je 0xada8
leaq 0xac02(%rip), %rdi      # 0x159a1
movl %ebx, %esi
xorl %eax, %eax
callq 0x45a0
movq 0x28(%r14), %rdi
callq 0x8157
movq %rax, %r15
movl %ebx, %eax
movq %rax, 0xb8(%r15)
movl %ebx, 0x1c(%r14)
jmp 0xade3
testl %eax, %eax
je 0xade0
movl 0x1c(%r14), %edx
leaq 0xabea(%rip), %rdi      # 0x159bc
xorl %r15d, %r15d
movl %ebx, %esi
xorl %eax, %eax
callq 0x45a0
jmp 0xade3
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_normalize_uri_path
int mg_normalize_uri_path(const struct mg_str *in, struct mg_str *out) {
  const char *s = in->p, *se = s + in->len;
  char *cp = (char *) out->p, *d;

  if (in->len == 0 || *s != '/') {
    out->len = 0;
    return 0;
  }

  d = cp;

  while (s < se) {
    const char *next = s;
    struct mg_str component;
    parse_uri_component(&next, se, "/", &component);
    if (mg_vcmp(&component, ".") == 0) {
      /* Yum. */
    } else if (mg_vcmp(&component, "..") == 0) {
      /* Backtrack to previous slash. */
      if (d > cp + 1 && *(d - 1) == '/') d--;
      while (d > cp && *(d - 1) != '/') d--;
    } else {
      memmove(d, s, next - s);
      d += next - s;
    }
    s = next;
  }
  if (d == cp) *d++ = '/';

  out->p = cp;
  out->len = d - cp;
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x8(%rdi), %r14
testq %r14, %r14
je 0xb3e6
movq (%rdi), %rbp
cmpb $0x2f, (%rbp)
jne 0xb3e6
movq %rsi, 0x20(%rsp)
movq (%rsi), %r8
testq %r14, %r14
jle 0xb3ed
addq %rbp, %r14
xorl %r12d, %r12d
leaq 0x10(%rsp), %rdi
movq %r8, %r13
movq %r8, 0x8(%rsp)
movq %rbp, %r15
movq %rbp, 0x10(%rsp)
movl $0x1, %ebp
cmpb $0x2f, (%r15)
movq %r15, %rax
je 0xb31f
movl $0x1, %eax
leaq (%r15,%rax), %rbp
cmpq %r14, %rbp
jae 0xb32f
incq %rax
cmpb $0x2f, (%rbp)
jne 0xb2fc
xorl %ecx, %ecx
cmpq %r14, %rbp
setb %cl
addq %r15, %rax
decq %rax
movq %rcx, %rbp
movq %rax, %rcx
subq %r15, %rcx
movq %rcx, 0x18(%rsp)
addq %rax, %rbp
jmp 0xb334
movq %rax, 0x18(%rsp)
movq %rdi, %rbx
leaq 0xa6ad(%rip), %rsi      # 0x159eb
callq 0x6c0c
testl %eax, %eax
je 0xb37d
movq %rbx, %rdi
leaq 0xa699(%rip), %rsi      # 0x159ea
callq 0x6c0c
testl %eax, %eax
je 0xb387
movq %rbp, %rbx
subq %r15, %rbx
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x3500
addq %rbx, %r12
movq 0x8(%rsp), %r8
leaq 0x10(%rsp), %rdi
jmp 0xb3d1
movq 0x8(%rsp), %r8
movq %rbx, %rdi
jmp 0xb3d1
cmpq $0x2, %r12
jl 0xb3a3
leaq -0x1(%r12), %rax
movq 0x8(%rsp), %r8
cmpb $0x2f, -0x1(%r8,%r12)
cmoveq %rax, %r12
jmp 0xb3a8
movq 0x8(%rsp), %r8
leaq 0x10(%rsp), %rdi
movq %r12, %rax
sarq $0x3f, %r12
andq %rax, %r12
testq %rax, %rax
jle 0xb3d1
leaq -0x1(%rax), %rcx
cmpb $0x2f, -0x1(%r8,%rax)
movq %rcx, %rax
jne 0xb3b7
incq %rcx
movq %rcx, %r12
leaq (%r8,%r12), %r13
cmpq %r14, %rbp
jb 0xb2e1
testq %r12, %r12
sete %al
jmp 0xb3f2
xorl %r13d, %r13d
xorl %eax, %eax
jmp 0xb40e
movb $0x1, %al
movq %r8, %r13
testb %al, %al
je 0xb3fe
movb $0x2f, (%r13)
incq %r13
movq 0x20(%rsp), %rsi
movq %r8, (%rsi)
subq %r8, %r13
movl $0x1, %eax
movq %r13, 0x8(%rsi)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_get_request_len
static int mg_http_get_request_len(const char *s, int buf_len) {
  const unsigned char *buf = (unsigned char *) s;
  int i;

  for (i = 0; i < buf_len; i++) {
    if (!isprint(buf[i]) && buf[i] != '\r' && buf[i] != '\n' && buf[i] < 128) {
      return -1;
    } else if (buf[i] == '\n' && i + 1 < buf_len && buf[i + 1] == '\n') {
      return i + 2;
    } else if (buf[i] == '\n' && i + 2 < buf_len && buf[i + 1] == '\r' &&
               buf[i + 2] == '\n') {
      return i + 3;
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
xorl %ebx, %ebx
testl %esi, %esi
jle 0xb8e0
movl %esi, %ebp
movq %rdi, %r14
callq 0x3660
movq (%rax), %rcx
movl %ebp, %edx
movq %rdx, %rsi
negq %rsi
movl $0x1, %eax
movzbl -0x1(%r14,%rax), %edi
cmpl $0xa, %edi
je 0xb895
testb %dil, %dil
js 0xb895
cmpb $0xd, %dil
je 0xb895
movzwl (%rcx,%rdi,2), %r8d
andl $0x4000, %r8d           # imm = 0x4000
je 0xb8d5
cmpb $0xa, %dil
jne 0xb8c3
cmpq %rdx, %rax
jae 0xb8a7
cmpb $0xa, (%r14,%rax)
je 0xb8dc
cmpb $0xa, %dil
jne 0xb8c3
leal 0x1(%rax), %edi
cmpl %ebp, %edi
jge 0xb8c3
cmpb $0xd, (%r14,%rax)
jne 0xb8c3
cmpb $0xa, 0x1(%r14,%rax)
je 0xb8e7
leaq (%rsi,%rax), %rdi
incq %rdi
incq %rax
cmpq $0x1, %rdi
jne 0xb871
jmp 0xb8e0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xb8e0
incl %eax
movl %eax, %ebx
movl %ebx, %eax
popq %rbx
popq %r14
popq %rbp
retq
addl $0x2, %eax
jmp 0xb8de
// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %rsi, %r14
movq %rdi, %r13
movq %rdi, (%rcx)
movq %rdi, %rbx
cmpq %rsi, %rdi
jae 0xb92a
movq %r13, %rbx
movzbl (%rbx), %esi
movq %r15, %rdi
callq 0x31d0
testq %rax, %rax
jne 0xb92a
incq %rbx
cmpq %r14, %rbx
jne 0xb90f
movq %r14, %rbx
movq %rbx, %rax
subq %r13, %rax
movq %rax, 0x8(%r12)
cmpq %r14, %rbx
jae 0xb95b
movq %r14, %r12
subq %rbx, %r12
movzbl (%rbx), %esi
movq %r15, %rdi
callq 0x31d0
testq %rax, %rax
je 0xb95b
incq %rbx
decq %r12
jne 0xb940
movq %r14, %rbx
movq %rbx, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/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
cmpl $0x26, %r15d
jg 0xba98
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 0xaa77(%rip), %rdx      # 0x16445
movq %rbx, %rcx
callq 0xb8ec
movq %rax, %rdi
movq %rbp, %rsi
leaq 0xadea(%rip), %rdx      # 0x167cd
movq %r13, %rcx
callq 0xb8ec
movq %rax, %rbp
movq 0x8(%r12,%r14), %rcx
testq %rcx, %rcx
sete %al
je 0xba23
movq (%r13), %rdx
cmpb $0x20, -0x1(%rdx,%rcx)
jne 0xba23
decq %rcx
movq %rcx, %rsi
movq %rcx, 0x8(%r13)
subq $0x1, %rsi
setb %al
jb 0xba23
cmpb $0x20, -0x1(%rdx,%rcx)
movq %rsi, %rcx
je 0xba0c
movq 0x8(%rbx), %rcx
testq %rcx, %rcx
je 0xba30
testb %al, %al
jne 0xba8e
testq %rcx, %rcx
setne %cl
notb %al
testb %cl, %al
jne 0xba51
xorl %eax, %eax
movq %rax, (%r13)
movq %rax, (%rbx)
movq %rax, 0x8(%r13)
movq %rax, 0x8(%rbx)
movb $0x1, %al
jmp 0xba90
movq (%rbx), %rdi
movl $0xe, %edx
leaq 0xa9e8(%rip), %rsi      # 0x16448
callq 0x6c88
testl %eax, %eax
jne 0xba8b
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
xorl %eax, %eax
testb %al, %al
je 0xb99e
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x3180
movq %rax, %r15
movq 0x80(%r14), %rax
testq %rax, %rax
je 0xbb1a
addq $0x2f8, %r14            # imm = 0x2F8
movq -0x280(%r14), %rdi
testq %rdi, %rdi
setne %cl
cmpq %r15, %rax
sete %al
andb %cl, %al
cmpb $0x1, %al
jne 0xbafb
movq %rbx, %rsi
movq %r15, %rdx
callq 0x6c88
testl %eax, %eax
je 0xbb13
movb $0x1, %al
testb %al, %al
je 0xbb1d
movq -0x268(%r14), %rax
addq $0x10, %r14
testq %rax, %rax
jne 0xbad3
jmp 0xbb1a
xorl %eax, %eax
movq %r14, %r12
jmp 0xbafd
xorl %r12d, %r12d
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/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 0xbbb7
movq %rsi, %rbx
movq %rdi, %r14
cmpq $0x0, 0x88(%rdi)
jne 0xbb6d
movl $0x1, %edi
movl $0x58, %esi
callq 0x3300
movq %rax, 0x88(%r14)
leaq 0x70bb(%rip), %rax      # 0x12c21
movq %rax, 0x90(%r14)
movq 0x88(%r14), %rax
movq 0x38(%rax), %r15
xorl %r12d, %r12d
testq %r15, %r15
je 0xbbb7
xorl %r14d, %r14d
movq 0x8(%r15), %rdi
movq 0x10(%r15), %rsi
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
callq 0x789b
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 0xbb83
jmp 0xbbba
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x7a51
testb $0x20, 0xc9(%rbx)
je 0xc386
movq %r14, 0x48(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/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
cmpq $0x0, 0x88(%rdi)
jne 0xc3d0
movl $0x1, %edi
movl $0x58, %esi
callq 0x3300
movq %rax, 0x88(%rbx)
leaq 0x6858(%rip), %rax      # 0x12c21
movq %rax, 0x90(%rbx)
movq 0x88(%rbx), %r12
cmpl $0x64, %ebp
jne 0xc41f
movq 0x10(%rbx), %rdi
leaq 0x30(%r14), %rsi
callq 0xbb2c
testq %rax, %rax
je 0xc41f
movq %rax, %r15
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 0x12d0a
testl %eax, %eax
je 0xc449
movq 0x28(%r15), %rax
movq %rax, 0x40(%r12)
movq 0x40(%r12), %rsi
testq %rsi, %rsi
jne 0xc430
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 0x7a51
movq 0x18(%r15), %r14
callq 0x4b23
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd 0x8ea2(%rip), %xmm0     # 0x15308
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rax, %rcx
leaq 0xa2e9(%rip), %rsi      # 0x16761
movq %rbx, %rdi
movq %r14, %rdx
xorl %eax, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x80d3
// File: /workspace/github_c_makefile_star2_O1/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 0xab7f(%rip), %rax      # 0x1753a
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 0x1073e
movq %rsp, %rdx
movq %r12, %rdi
movl $0x14, %esi
callq 0x47a8
leaq 0x95f6(%rip), %rsi      # 0x15ff2
leaq 0xab5c(%rip), %rdx      # 0x1755f
movq %rbx, %rdi
xorl %eax, %eax
callq 0x80d3
leaq 0xab97(%rip), %rsi      # 0x175ab
movq %r15, %rdi
callq 0xbaa7
testq %rax, %rax
je 0xca38
movl 0x8(%rax), %edx
movq (%rax), %rcx
leaq 0x965f(%rip), %rsi      # 0x1608d
movq %rbx, %rdi
xorl %eax, %eax
callq 0x80d3
leaq 0xab83(%rip), %rsi      # 0x175c2
leaq 0x9d85(%rip), %rcx      # 0x167cb
movq %rsp, %rdx
movq %rbx, %rdi
xorl %eax, %eax
callq 0x80d3
leaq 0xab83(%rip), %rsi      # 0x175dd
leaq 0x8b49(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0xca8a
movl 0x8(%r14), %edx
movq (%r14), %rcx
leaq 0xab70(%rip), %rdi      # 0x175ed
movq %rsp, %r8
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/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 0xcaa5
leaq 0x8f6c(%rip), %rsi      # 0x15b14
leaq 0x995e(%rip), %r8       # 0x1650d
movq %r15, %rdi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x80d3
testq %r14, %r14
je 0xcbe4
leaq 0x9e61(%rip), %rsi      # 0x16a2b
movq %r15, %rdi
movl %r14d, %edx
movq %rbx, %rcx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x80d3
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x8ee0(%rip), %rdx      # 0x15b31
movl $0x64, %esi
movq %r14, %r8
xorl %eax, %eax
callq 0x7627
movl %eax, %ebp
leaq 0x90(%rsp), %rax
leaq 0x18(%rsp), %r13
movq %rax, (%r13)
testq %r15, %r15
leaq 0x9b52(%rip), %rax      # 0x167cf
leaq 0x9b49(%rip), %r10      # 0x167cd
cmoveq %rax, %r10
subq $0x8, %rsp
leaq 0x8ec2(%rip), %rdx      # 0x15b55
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 0x7627
addq $0x20, %rsp
movq (%r13), %rdi
callq 0x6be8
movq %rdx, %rcx
movq %rbx, %rdi
movl 0x4(%rsp), %esi
movq %rax, %rdx
callq 0xcb88
movq (%r13), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0xcce8
callq 0x3060
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x808e
movq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xcd0b
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_O1/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 0x6be8
movq %rdx, %rcx
movq %rbx, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xcb88
testq %r14, %r14
js 0xcd55
leaq 0x8e82(%rip), %rsi      # 0x15bcf
movq %rbx, %rdi
movq %r14, %rdx
jmp 0xcd66
leaq 0x9296(%rip), %rsi      # 0x15ff2
leaq 0x8e4f(%rip), %rdx      # 0x15bb2
movq %rbx, %rdi
xorl %eax, %eax
callq 0x80d3
leaq 0x9a59(%rip), %rsi      # 0x167cd
movq %rbx, %rdi
movl $0x2, %edx
popq %rbx
popq %r14
popq %rbp
jmp 0x808e
// File: /workspace/github_c_makefile_star2_O1/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 %r14
pushq %rbx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
testq %rdx, %rdx
jne 0xcda0
movl %ebp, %edi
callq 0xcaa5
movq %rax, %r14
leaq 0x8e3e(%rip), %rsi      # 0x15be5
leaq 0x87fc(%rip), %rdx      # 0x155aa
movl $0x3, %edi
callq 0x44b4
testl %eax, %eax
je 0xcdd2
leaq 0x8e35(%rip), %rdi      # 0x15bf8
movq %rbx, %rsi
movl %ebp, %edx
movq %r14, %rcx
xorl %eax, %eax
callq 0x45a0
movq %r14, %rdi
callq 0x3180
leaq 0x8e20(%rip), %rcx      # 0x15c01
movq %rbx, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xcd1d
movq %r14, %rdi
callq 0x3180
movq %rbx, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x808e
orb $0x4, 0xc9(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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, %r15
testl %esi, %esi
setg %al
setle %dil
cmpl $0x2, %ecx
setl %r8b
xorl %r13d, %r13d
orb %dil, %r8b
jne 0xd2fe
decl %ecx
leal -0x2(%rsi), %eax
movl %eax, (%rsp)
movslq %ecx, %rcx
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rdx, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %r15, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movslq %ebx, %r14
movb (%r15,%r14), %al
cmpb $0x25, %al
jne 0xd2d3
cmpl (%rsp), %ebx
jge 0xd311
callq 0x3660
movq (%rax), %rbp
movq %r15, %rax
movzbl 0x1(%r15,%r14), %r15d
testb $0x10, 0x1(%rbp,%r15,2)
je 0xd311
movzbl 0x2(%rax,%r14), %r14d
testb $0x10, 0x1(%rbp,%r14,2)
je 0xd311
callq 0x3650
movq (%rax), %rax
movslq (%rax,%r15,4), %rcx
movslq (%rax,%r14,4), %rax
movzwl (%rbp,%rcx,2), %edx
xorl %esi, %esi
btl $0xb, %edx
setae %sil
leal (%rsi,%rsi,8), %edx
addl %ecx, %edx
shll $0x4, %edx
movzwl (%rbp,%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,%r13)
addl $0x2, %ebx
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %rcx
jmp 0xd2e9
cmpl $0x0, 0x4(%rsp)
je 0xd2e5
cmpb $0x2b, %al
jne 0xd2e5
movb $0x20, (%rdx,%r13)
jmp 0xd2e9
movb %al, (%rdx,%r13)
incl %ebx
incq %r13
cmpl %esi, %ebx
setl %al
jge 0xd2fe
cmpq %rcx, %r13
jl 0xd22f
movl %r13d, %ecx
movb $0x0, (%rdx,%rcx)
testb %al, %al
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmovel %r13d, %r12d
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0xd3ef
movq %rdx, %r12
movq %rdi, %r13
movq (%rdi), %r15
testq %r15, %r15
sete %al
testq %rsi, %rsi
sete %cl
orb %al, %cl
jne 0xd3e5
movq 0x8(%r13), %rbx
testq %rbx, %rbx
je 0xd3e5
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 0xd3ef
movq %r14, 0x10(%rsp)
xorl %r14d, %r14d
leaq (%rbx,%r14), %rsi
cmpq (%r13), %rsi
je 0xd3ba
cmpb $0x26, -0x1(%rbx,%r14)
jne 0xd3d4
cmpb $0x3d, (%r12,%r14)
jne 0xd3d4
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rdx
callq 0x6c88
testl %eax, %eax
je 0xd400
leaq (%r12,%r14), %rax
incq %rax
incq %r14
cmpq %r15, %rax
jb 0xd3a8
jmp 0xd3ef
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 0xd1d3
cmpl $-0x1, %eax
movl $0xfffffffd, %ebp       # imm = 0xFFFFFFFD
cmovnel %eax, %ebp
jmp 0xd3ef
// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq 0x88b7(%rip), %rdx      # 0x15d33
movq %rsp, %r12
movl $0x32, %esi
movq %r12, %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x31e0
movq %r15, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x808e
movq %r15, %rdi
movq %r14, %rsi
movl %ebx, %edx
callq 0x808e
leaq 0x931b(%rip), %rsi      # 0x167cd
movq %r15, %rdi
movl $0x2, %edx
callq 0x808e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/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 0xd52e
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 0x76a7
testl %eax, %eax
js 0xd580
movq 0x8(%rsp), %rsi
movl %eax, %edx
movq %rbx, %rdi
callq 0xd461
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0xd59a
callq 0x3060
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/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 $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 0xd60f
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), %r15
leaq 0x8(%rsp), %rdi
movq %r15, (%rdi)
leaq 0x10(%rsp), %rcx
movq %rsi, 0x10(%rcx)
leaq 0x180(%rsp), %rax
movq %rax, 0x8(%rcx)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rcx)
movl $0x64, %esi
movq %r10, %rdx
callq 0x76a7
testl %eax, %eax
js 0xd6db
je 0xd6be
movl %eax, %r12d
xorl %r14d, %r14d
leaq 0x86d4(%rip), %r13      # 0x15d39
leaq 0x86d2(%rip), %rbp      # 0x15d3e
xorl %eax, %eax
movq 0x8(%rsp), %rsi
movzbl (%rsi,%r14), %ecx
orl $0x2, %ecx
cmpl $0x3e, %ecx
jne 0xd6b4
cltq
addq %rax, %rsi
movl %r14d, %edx
subl %eax, %edx
movq %rbx, %rdi
callq 0x808e
movq 0x8(%rsp), %rax
cmpb $0x3c, (%rax,%r14)
movq %rbp, %rsi
cmoveq %r13, %rsi
movq %rbx, %rdi
movl $0x4, %edx
callq 0x808e
leal 0x1(%r14), %eax
incq %r14
cmpq %r14, %r12
jne 0xd66e
jmp 0xd6c3
xorl %eax, %eax
xorl %r14d, %r14d
cltq
movq 0x8(%rsp), %rsi
addq %rax, %rsi
subl %eax, %r14d
movq %rbx, %rdi
movl %r14d, %edx
callq 0x808e
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0xd6f5
callq 0x3060
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x8776(%rip), %rdi      # 0x160e8
callq 0x6be8
movq %rdx, %rcx
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
movl $0x6, %r8d
movq %rax, %rdx
callq 0x6e09
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
testl %eax, %eax
jne 0xda13
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 0x4a0c
decq %r12
decq %r15
leaq 0x837c(%rip), %rdx      # 0x15d51
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_O1/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 0x7903(%rip), %xmm0     # 0x15340
movups %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rdi, %rdi
je 0xda75
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 0x4c53
incq %rbp
cmpq %rbp, %r12
jne 0xda5d
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x54c4
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0xdafc
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 0xdb38
movq %rcx, %rdx
movl %eax, %ecx
addq %r10, %rcx
addl $0x8, %eax
movl %eax, (%rsp)
jmp 0xdb41
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq (%rcx), %rcx
testq %rcx, %rcx
je 0xdb7c
movq %rcx, 0xd0(%rsp,%rdi,8)
cmpl $0x28, %eax
ja 0xdb66
movq %rdx, %rcx
movl %eax, %edx
addq %r10, %rdx
addl $0x8, %eax
movl %eax, (%rsp)
jmp 0xdb6f
leaq 0x8(%rdx), %rcx
movq %rcx, 0x8(%rsp)
movq (%rdx), %rdx
movq %rdx, 0x30(%rsp,%rdi,8)
incq %rdi
jmp 0xdb23
leaq 0xd0(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x20(%rsp), %r14
movq %r14, %rcx
callq 0xda25
movl $0x10, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x754c
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x4b23
cvttsd2si %xmm0, %rcx
leaq 0x8173(%rip), %rdx      # 0x15d65
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 0x7820(%rip), %rcx      # 0x15456
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 0xda8f
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 0x7794(%rip), %r11      # 0x15430
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 0x8b84(%rip), %r10      # 0x16858
pushq %r10
pushq %rax
pushq %r11
movq %r11, %r12
callq 0xdd21
addq $0x50, %rsp
leaq 0x807c(%rip), %rdx      # 0x15d68
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_O1/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 %rbx
pushq %rax
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
cmpq $0x0, 0x88(%rdi)
jne 0xe937
movl $0x1, %edi
movl $0x58, %esi
callq 0x3300
movq %rax, 0x88(%rbx)
leaq 0x42f1(%rip), %rax      # 0x12c21
movq %rax, 0x90(%rbx)
movq 0x88(%rbx), %r15
testq %r15, %r15
je 0xe977
movq 0x48(%r15), %rdi
testq %rdi, %rdi
je 0xe977
cmpl $0x65, %ebp
je 0xe9b7
cmpl $0x5, %ebp
je 0xe9ae
cmpl $0x2, %ebp
jne 0xe9d9
cmpl $0x0, (%r14)
je 0xe9d9
movl $0x1f6, %esi            # imm = 0x1F6
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xcd85
leaq 0x7bcf(%rip), %rsi      # 0x1654d
leaq 0x6c25(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0xe9d9
leaq 0x7bcc(%rip), %rdi      # 0x16566
movq %rbx, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x45a0
orb $0x4, 0xc9(%rdi)
jmp 0xe9d9
movq (%r14), %rsi
movl 0x8(%r14), %edx
callq 0x808e
movq 0x48(%r15), %rax
orq $0x400, 0xc8(%rax) # imm = 0x400
orb $0x8, 0xc9(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0xdd7(%rip), %rax       # 0x10e69
movq %rax, (%rbp)
movq %r8, 0x10(%rbp)
leaq 0x6038(%rip), %rsi      # 0x160d9
movl $0x15, %edx
movq %r8, %rdi
callq 0x6ba9
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x467a
testq %r14, %r14
je 0x100e6
leaq 0x538e(%rip), %rsi      # 0x15456
movq %rsp, %r12
movl $0x1, %edx
movq %r12, %rdi
callq 0x467a
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x467a
movq %rsp, %rdi
callq 0x4751
leaq 0x66d8(%rip), %rsi      # 0x167cd
movl $0x2, %edx
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6ba9
// File: /workspace/github_c_makefile_star2_O1/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 0x1041e
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
movl $0x1, %edi
movl $0x30, %esi
callq 0x3300
testq %rax, %rax
je 0x10415
movq %rax, %r14
leaq 0x30(%rsp), %r13
cmpq $0x0, 0x88(%r12)
jne 0x103b1
movl $0x1, %edi
movl $0x58, %esi
callq 0x3300
movq %rax, 0x88(%r12)
leaq 0x2878(%rip), %rax      # 0x12c21
movq %rax, 0x90(%r12)
movq 0x88(%r12), %r12
movq %r15, %rdi
callq 0x6be8
movq %rax, %rdi
movq %rdx, %rsi
callq 0x6cd6
movq %rax, 0x8(%r14)
movq %rdx, 0x10(%r14)
movq 0x8(%r13), %rdi
movq 0x10(%r13), %r15
testq %rdi, %rdi
setne %al
testq %r15, %r15
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x10404
callq 0x35f0
movq %rax, 0x18(%r14)
movq %r15, %rdi
callq 0x35f0
movq %rax, 0x20(%r14)
movq %rbx, 0x28(%r14)
movq 0x38(%r12), %rax
movq %rax, (%r14)
movq %r14, 0x38(%r12)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq