LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/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, %rbp
movq %rdx, %r13
movl %esi, 0x4(%rsp)
movq %rdi, %rbx
leaq 0x20(%rsp), %rax
leaq 0x8(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x8bec(%rip), %rdx      # 0x14b35
pushq $0x64
popq %rsi
movq %r13, %r8
xorl %eax, %eax
callq 0x71ab
movl %eax, %r14d
leaq 0x90(%rsp), %rax
leaq 0x18(%rsp), %r12
movq %rax, (%r12)
testq %r15, %r15
leaq 0x985c(%rip), %rax      # 0x157d0
leaq 0x9853(%rip), %r10      # 0x157ce
cmoveq %rax, %r10
subq $0x8, %rsp
leaq 0x8bcf(%rip), %rdx      # 0x14b59
movl $0x96, %esi
movq %r12, %rdi
movl %ebp, %ecx
movq %r13, %r8
movl %r14d, %r9d
xorl %eax, %eax
pushq %r10
pushq 0x20(%rsp)
pushq %r15
callq 0x71ab
addq $0x20, %rsp
movq (%r12), %rdx
movq %rbx, %rdi
movl 0x4(%rsp), %esi
callq 0xbee7
movq (%r12), %rdi
leaq 0x90(%rsp), %rax
cmpq %rax, %rdi
je 0xbfd3
callq 0x3060
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x7b89
movq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xbff7
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_O2/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 %r14
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rdi, %rbx
movq %rcx, %rdx
callq 0xbee7
testq %r14, %r14
js 0xc02f
leaq 0x8bac(%rip), %rsi      # 0x14bd3
movq %rbx, %rdi
movq %r14, %rdx
jmp 0xc040
leaq 0x8fc0(%rip), %rsi      # 0x14ff6
leaq 0x8b79(%rip), %rdx      # 0x14bb6
movq %rbx, %rdi
xorl %eax, %eax
callq 0x7bce
leaq 0x9780(%rip), %rsi      # 0x157ce
pushq $0x2
popq %rdx
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x7b89
// File: /workspace/github_c_makefile_star2_O2/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 0xc07b
movl %ebp, %edi
callq 0xbdb1
movq %rax, %r14
leaq 0x8b67(%rip), %rsi      # 0x14be9
leaq 0x8525(%rip), %rdx      # 0x145ae
pushq $0x3
popq %rdi
callq 0x4227
testl %eax, %eax
je 0xc0ab
leaq 0x8b60(%rip), %rdi      # 0x14bfc
movq %rbx, %rsi
movl %ebp, %edx
movq %r14, %rcx
xorl %eax, %eax
callq 0x430a
movq %r14, %rdi
callq 0x3180
leaq 0x8b4b(%rip), %rcx      # 0x14c05
movq %rbx, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xc009
movq %r14, %rdi
callq 0x3180
movq %rbx, %rdi
movq %r14, %rsi
movl %eax, %edx
callq 0x7b89
orb $0x4, 0xc9(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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, 0xc(%rsp)
movq %rdi, %r15
decl %ecx
leal -0x2(%rsi), %eax
movl %eax, 0x8(%rsp)
movslq %ecx, %r12
xorl %r13d, %r13d
xorl %ebx, %ebx
movq %rsi, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %r12, 0x10(%rsp)
cmpl %esi, %ebx
jge 0xc582
cmpq %r12, %r13
jge 0xc582
movslq %ebx, %rbp
movb (%r15,%rbp), %al
cmpb $0x25, %al
jne 0xc55d
cmpl 0x8(%rsp), %ebx
jge 0xc57d
callq 0x3660
movq (%rax), %r14
movq %r15, %rax
movzbl 0x1(%r15,%rbp), %r15d
testb $0x10, 0x1(%r14,%r15,2)
je 0xc57d
movzbl 0x2(%rax,%rbp), %ebp
testb $0x10, 0x1(%r14,%rbp,2)
je 0xc57d
movq %rax, %r12
callq 0x3650
movq (%rax), %rax
movslq (%rax,%r15,4), %rcx
movslq (%rax,%rbp,4), %rax
movzwl (%r14,%rcx,2), %edx
xorl %esi, %esi
btl $0xb, %edx
setae %sil
leal (%rsi,%rsi,8), %edx
addl %ecx, %edx
shll $0x4, %edx
movzwl (%r14,%rax,2), %ecx
leal 0xd0(%rax), %esi
addl $0xa9, %eax
btl $0xb, %ecx
cmovbl %esi, %eax
orl %edx, %eax
movq 0x18(%rsp), %rdx
movb %al, (%rdx,%r13)
addl $0x2, %ebx
movq 0x20(%rsp), %rsi
movq %r12, %r15
movq 0x10(%rsp), %r12
jmp 0xc573
cmpl $0x0, 0xc(%rsp)
je 0xc56f
cmpb $0x2b, %al
jne 0xc56f
movb $0x20, (%rdx,%r13)
jmp 0xc573
movb %al, (%rdx,%r13)
incl %ebx
incq %r13
jmp 0xc4ab
pushq $-0x1
popq %rax
jmp 0xc590
cmpl %esi, %ebx
movb $0x0, (%rdx,%r13)
pushq $-0x1
popq %rax
cmovgel %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movq %rdx, %r14
testq %rdx, %rdx
sete %al
testq %rcx, %rcx
sete %dl
orb %al, %dl
je 0xc5c7
pushq $-0x2
jmp 0xc64f
movq %rsi, %r12
movq %rdi, %r13
movq (%rdi), %r15
testq %r15, %r15
sete %al
testq %rsi, %rsi
sete %dl
orb %al, %dl
jne 0xc645
movq 0x8(%r13), %rbx
testq %rbx, %rbx
je 0xc645
movq %rcx, 0x10(%rsp)
movq %r12, %rdi
callq 0x3180
addq %rbx, %r15
movq %r14, 0x8(%rsp)
movb $0x0, (%r14)
movq (%r13), %r14
movq %rax, (%rsp)
leaq (%r14,%rax), %rbx
xorl %ebp, %ebp
leaq (%rbx,%rbp), %rax
cmpq %r15, %rax
jae 0xc64d
leaq (%r14,%rbp), %rsi
cmpq (%r13), %rsi
je 0xc62b
cmpb $0x26, -0x1(%r14,%rbp)
jne 0xc640
cmpb $0x3d, (%rax)
jne 0xc640
movq %r12, %rdi
movq (%rsp), %rdx
callq 0x6915
testl %eax, %eax
je 0xc661
incq %rbp
jmp 0xc610
movb $0x0, (%r14)
pushq $-0x1
jmp 0xc64f
pushq $-0x4
popq %rcx
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
addq %rbp, %rbx
incq %rbx
movq (%rsp), %r12
movq %r12, %rdx
notq %rdx
addq %r15, %rdx
subq %r14, %rdx
subq %rbp, %rdx
pushq $0x26
popq %rsi
movq %rbx, %rdi
callq 0x32c0
addl %r12d, %r14d
testq %rax, %rax
notl %r14d
cmovnel %eax, %r15d
addl %r14d, %r15d
subl %ebp, %r15d
pushq $0x1
popq %r8
movq %rbx, %rdi
movl %r15d, %esi
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0xc475
cmpl $-0x1, %eax
pushq $-0x3
popq %rcx
cmovnel %eax, %ecx
jmp 0xc650
// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x8660(%rip), %rdx      # 0x14d37
movq %rsp, %r12
pushq $0x32
popq %rsi
movq %r12, %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x31e0
movq %rbx, %rdi
movq %r12, %rsi
movl %eax, %edx
callq 0x7b89
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x7b89
leaq 0x90c2(%rip), %rsi      # 0x157ce
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x7b89
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/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 0xc786
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)
pushq $0x64
popq %rsi
movq %r10, %rdx
callq 0x722b
testl %eax, %eax
js 0xc7d6
movq 0x8(%rsp), %rsi
movl %eax, %edx
movq %rbx, %rdi
callq 0xc6bc
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0xc7f0
callq 0x3060
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/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 0xc865
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)
pushq $0x64
popq %rsi
movq %r10, %rdx
callq 0x722b
testl %eax, %eax
js 0xc921
movl %eax, %ebp
movl %eax, %r12d
xorl %r13d, %r13d
pushq $0x4
popq %r14
xorl %eax, %eax
movq 0x8(%rsp), %rsi
movslq %eax, %rcx
cmpq %r13, %r12
je 0xc912
movzbl (%rsi,%r13), %edx
orl $0x2, %edx
cmpl $0x3e, %edx
je 0xc8d3
incq %r13
jmp 0xc8b9
addq %rcx, %rsi
movl %r13d, %edx
subl %ecx, %edx
movq %rbx, %rdi
callq 0x7b89
movq 0x8(%rsp), %rax
cmpb $0x3c, (%rax,%r13)
leaq 0x844e(%rip), %rsi      # 0x14d42
leaq 0x8442(%rip), %rax      # 0x14d3d
cmoveq %rax, %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x7b89
incq %r13
movl %r13d, %eax
jmp 0xc8b4
addq %rcx, %rsi
subl %ecx, %ebp
movq %rbx, %rdi
movl %ebp, %edx
callq 0x7b89
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0xc93b
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_O2/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, %rbx
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r13
leaq 0x8572(%rip), %rdi      # 0x150e9
callq 0x6875
movq %rdx, %rcx
movq (%r13), %rdi
movq 0x8(%r13), %rsi
pushq $0x6
popq %r8
movq %rax, %rdx
callq 0x6a46
testl %eax, %eax
je 0xcb9d
pushq $-0x1
popq %r13
jmp 0xcc10
movq %rbx, 0x8(%rsp)
movq 0x8(%r13), %rbx
movq %rbx, %rdi
callq 0x33e0
movq %rax, %rbp
movq (%r13), %rdi
addq $0x6, %rdi
xorl %r13d, %r13d
movl %ebx, %esi
movq %rax, %rdx
xorl %ecx, %ecx
callq 0x473d
decq %r12
decq %r15
leaq 0x8180(%rip), %rdx      # 0x14d55
leaq 0x10(%rsp), %rbx
pushq $0x40
popq %rsi
movq %rbx, %rdi
movq %r12, %rcx
movq %r15, %r8
xorl %eax, %eax
callq 0x31e0
movq %rbp, %rdi
movq %rbx, %rsi
movq %r14, %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_O2/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
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movaps 0x770d(%rip), %xmm0     # 0x14350
movq %rsp, %r13
movaps %xmm0, (%r13)
andq $0x0, 0x10(%r13)
xorl %ebp, %ebp
cmpq %rbp, %r12
je 0xcc6c
movq (%r15,%rbp,8), %rsi
movq (%r14,%rbp,8), %rdx
movq %r13, %rdi
callq 0x4933
incq %rbp
jmp 0xcc52
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x5180
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 0xccf3
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)
pushq $0x8
popq %rax
xorl %edi, %edi
cmpl $0x28, %eax
ja 0xcd2d
movq %rcx, %rdx
movl %eax, %ecx
addq %r10, %rcx
addl $0x8, %eax
movl %eax, (%rsp)
jmp 0xcd36
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq (%rcx), %rcx
testq %rcx, %rcx
je 0xcd71
movq %rcx, 0xd0(%rsp,%rdi,8)
cmpl $0x28, %eax
ja 0xcd5b
movq %rdx, %rcx
movl %eax, %edx
addq %r10, %rdx
addl $0x8, %eax
movl %eax, (%rsp)
jmp 0xcd64
leaq 0x8(%rdx), %rcx
movq %rcx, 0x8(%rsp)
movq (%rdx), %rdx
movq %rdx, 0x30(%rsp,%rdi,8)
incq %rdi
jmp 0xcd18
leaq 0xd0(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x20(%rsp), %r14
movq %r14, %rcx
callq 0xcc22
pushq $0x10
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x70e1
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x483c
cvttsd2si %xmm0, %rcx
leaq 0x7f84(%rip), %rdx      # 0x14d69
leaq 0x50(%rsp), %rdi
pushq $0x28
popq %rsi
xorl %eax, %eax
callq 0x31e0
movq %r15, %rdi
callq 0x3180
movq %rax, %r13
movq %r14, %rdi
movq %r14, 0x8(%rsp)
callq 0x3180
movq %rax, %rbp
movq %rbx, %rdi
callq 0x3180
movq %rax, %r10
pushq $0x1
popq %r8
leaq 0x7621(%rip), %rcx      # 0x14446
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r14, %r9
movl $0x0, %eax
pushq $0x0
pushq %r10
pushq %rbx
pushq %r8
pushq %rcx
pushq %rbp
callq 0xcc86
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 0x759c(%rip), %r11      # 0x14420
pushq $0x20
popq %r9
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %rbp, %rcx
leaq 0x28(%rsp), %r8
pushq %r10
movq %r10, %rbp
pushq $0x4
pushq %r11
movq %r11, %r13
pushq %rax
movq %r14, %r11
pushq %r14
pushq $0x1
popq %r14
pushq %r14
leaq 0x89a1(%rip), %r10      # 0x15859
pushq %r10
pushq %rax
pushq %r11
movq %r11, %r12
callq 0xcf05
addq $0x50, %rsp
leaq 0x7e9c(%rip), %rdx      # 0x14d6c
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_O2/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
callq 0xb106
testq %rax, %rax
je 0xdaa0
movq %rax, %r15
movq 0x48(%rax), %rdi
testq %rdi, %rdi
je 0xdaa0
cmpl $0x65, %ebp
je 0xdade
cmpl $0x5, %ebp
je 0xdad5
cmpl $0x2, %ebp
jne 0xdb00
cmpl $0x0, (%r14)
je 0xdb00
movl $0x1f6, %esi            # imm = 0x1F6
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xc060
leaq 0x7aa7(%rip), %rsi      # 0x1554e
leaq 0x6b00(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0xdb00
leaq 0x7aa6(%rip), %rdi      # 0x15567
movq %rbx, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x430a
orb $0x4, 0xc9(%rdi)
jmp 0xdb00
movq (%r14), %rsi
movl 0x8(%r14), %edx
callq 0x7b89
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_O2/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 %rsp, %r13
andl $0x0, 0xc(%r13)
movq %rdi, %rbp
leaq 0xd2b(%rip), %rax       # 0x10321
movq %rax, (%r13)
movq %r8, 0x10(%r13)
leaq 0x5ad5(%rip), %rsi      # 0x150da
pushq $0x15
popq %rdx
movq %r8, %rdi
callq 0x6836
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x43dc
testq %r14, %r14
je 0xf646
leaq 0x4e1c(%rip), %rsi      # 0x14446
movq %rsp, %r12
pushq $0x1
popq %rdx
movq %r12, %rdi
callq 0x43dc
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq 0x43dc
movq %rsp, %rdi
callq 0x44ad
leaq 0x6179(%rip), %rsi      # 0x157ce
pushq $0x2
popq %rdx
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6836
// File: /workspace/github_c_makefile_star2_O2/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 0xf8f5
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
callq 0x3300
testq %rax, %rax
je 0xf8ec
movq %rax, %r14
leaq 0x30(%rsp), %r13
movq %r15, %rdi
callq 0xb106
movq %rax, %r15
movq %r12, %rdi
callq 0x6875
movq %rax, %rdi
movq %rdx, %rsi
callq 0x6969
movq %rax, 0x8(%r14)
movq %rdx, 0x10(%r14)
movq 0x8(%r13), %rdi
movq 0x10(%r13), %r12
testq %rdi, %rdi
setne %al
testq %r12, %r12
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xf8dd
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)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x56c3(%rip), %rsi      # 0x15006
leaq 0x4c64(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0xf96c
leaq 0x4d58(%rip), %rdi      # 0x146b5
movq %rbx, %rsi
movl %ebp, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x430a
movq %rsp, %r12
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rdx
movq %r12, %rcx
callq 0xf9b2
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x7b89
leaq 0x58(%rbx), %rdi
movq %r12, %rsi
callq 0xfa75
cmpl $0x8, %ebp
jne 0xf9a5
orb $0x4, 0xc9(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 %r14
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 0xf9e8
movb %dl, 0xf(%rsp)
orb $-0x80, %dl
pushq $0x2
popq %rax
jmp 0xfa23
cmpq $0xfffe, %rdx           # imm = 0xFFFE
ja 0xfa06
rolw $0x8, %dx
movb $0x7e, 0xf(%rsp)
movw %dx, 0x10(%rsp)
pushq $0x4
popq %rax
movb $-0x2, %dl
jmp 0xfa23
movb $0x7f, 0xf(%rsp)
movq %rdx, %rax
shrq $0x20, %rax
bswapl %eax
movl %eax, 0x10(%rsp)
bswapl %edx
movl %edx, 0x14(%rsp)
pushq $0xa
popq %rax
movb $-0x1, %dl
cmpq $0x0, 0x10(%r14)
je 0xfa3d
leaq 0xe(%rsp), %rsi
movq %r14, %rdi
movl %eax, %edx
callq 0x7b89
xorl %eax, %eax
jmp 0xfa6a
leaq 0xe(%rsp), %rsi
movb %dl, 0x1(%rsi)
movq %r14, %rdi
movl %eax, %edx
callq 0x7b89
callq 0x3640
leaq 0x8(%rbx), %rsi
movl %eax, 0x8(%rbx)
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0x7b89
movq 0x60(%r14), %rax
movq %rax, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/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 0xfaa2
xorl %ecx, %ecx
movq 0x8(%rdi), %rdx
subq %rax, %rdx
cmpq %rdx, %rcx
jae 0xfaa2
movl %ecx, %edx
andl $0x3, %edx
addq (%rdi), %rax
movb 0x8(%rsi,%rdx), %dl
xorb %dl, (%rcx,%rax)
incq %rcx
movq (%rsi), %rax
jmp 0xfa7f
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_websocket_framev
void mg_send_websocket_framev(struct mg_connection *nc, int op,
                              const struct mg_str *strv, int strvcnt) {
  struct ws_mask_ctx ctx;
  int i;
  int len = 0;
  for (i = 0; i < strvcnt; i++) {
    len += strv[i].len;
  }

  mg_send_ws_header(nc, op, len, &ctx);

  for (i = 0; i < strvcnt; i++) {
    mg_send(nc, strv[i].p, strv[i].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
movl %ecx, %r14d
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %rbx
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %r14d
shlq $0x4, %r14
xorl %ecx, %ecx
cmpq %rax, %r14
je 0xfad8
addl 0x8(%r15,%rax), %ecx
addq $0x10, %rax
jmp 0xfac8
movslq %ecx, %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movl %ebp, %esi
callq 0xf9b2
xorl %r12d, %r12d
cmpq %r12, %r14
je 0xfb07
movq (%r15,%r12), %rsi
movl 0x8(%r15,%r12), %edx
movq %rbx, %rdi
callq 0x7b89
addq $0x10, %r12
jmp 0xfaeb
leaq 0x58(%rbx), %rdi
movq %rsp, %rsi
callq 0xfa75
cmpl $0x8, %ebp
jne 0xfb1f
orb $0x4, 0xc9(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_printf_websocket_frame
void mg_printf_websocket_frame(struct mg_connection *nc, int op,
                               const char *fmt, ...) {
  char mem[MG_VPRINTF_BUFFER_SIZE], *buf = mem;
  va_list ap;
  int len;

  va_start(ap, fmt);
  if ((len = mg_avprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
    mg_send_websocket_frame(nc, op, buf, len);
  }
  va_end(ap);

  if (buf != mem && buf != NULL) {
    MG_FREE(buf);
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x150, %rsp            # imm = 0x150
movl %esi, %ebx
movq %rdi, %r14
leaq 0x30(%rsp), %rsi
movq %rcx, 0x18(%rsi)
movq %r8, 0x20(%rsi)
movq %r9, 0x28(%rsi)
testb %al, %al
je 0xfb8c
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 0x170(%rsp), %rax
movq %rax, 0x8(%rcx)
movabsq $0x3000000018, %rax     # imm = 0x3000000018
movq %rax, (%rcx)
pushq $0x64
popq %rsi
callq 0x722b
testl %eax, %eax
jle 0xfbdb
movq 0x8(%rsp), %rdx
movl %eax, %ecx
movq %r14, %rdi
movl %ebx, %esi
callq 0xf925
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0xfbf5
callq 0x3060
addq $0x150, %rsp            # imm = 0x150
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_hash_sha1_v
void mg_hash_sha1_v(size_t num_msgs, const uint8_t *msgs[],
                    const size_t *msg_lens, uint8_t *digest) {
  size_t i;
  cs_sha1_ctx sha_ctx;
  cs_sha1_init(&sha_ctx);
  for (i = 0; i < num_msgs; i++) {
    cs_sha1_update(&sha_ctx, msgs[i], msg_lens[i]);
  }
  cs_sha1_final(digest, &sha_ctx);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movaps 0x472d(%rip), %xmm0     # 0x14350
movq %rsp, %r13
movaps %xmm0, (%r13)
movl $0xc3d2e1f0, %eax       # imm = 0xC3D2E1F0
movq %rax, 0x10(%r13)
andl $0x0, 0x18(%r13)
xorl %ebp, %ebp
cmpq %rbp, %r12
je 0xfc55
movq (%r15,%rbp,8), %rsi
movl (%r14,%rbp,8), %edx
movq %r13, %rdi
callq 0x6347
incq %rbp
jmp 0xfc3b
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x63ef
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_websocket_handshake
void mg_send_websocket_handshake(struct mg_connection *nc, const char *path,
                                 const char *extra_headers) {
  struct mg_str null_str = MG_NULL_STR;
  mg_send_websocket_handshake3v(
      nc, mg_mk_str(path), null_str /* host */, null_str /* protocol */,
      mg_mk_str(extra_headers), null_str /* user */, null_str /* pass */);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %rbx
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq %rsi, %rdi
callq 0x6875
movq %rax, %r15
movq %rdx, %r12
movq %rbx, %rdi
callq 0x6875
movq %rax, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, 0x30(%rsp)
movups %xmm0, 0x20(%rsp)
movups 0x40(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0xfd69
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_connect_ws_opt
struct mg_connection *mg_connect_ws_opt(
    struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data),
    struct mg_connect_opts opts, const char *url, const char *protocol,
    const char *extra_headers) {
  struct mg_str null_str = MG_NULL_STR;
  struct mg_str host = MG_NULL_STR, path = MG_NULL_STR, user_info = MG_NULL_STR;
  struct mg_connection *nc =
      mg_connect_http_base(mgr, MG_CB(ev_handler, user_data), opts, "http",
                           "ws", "https", "wss", url, &path, &user_info, &host);
  if (nc != NULL) {
    mg_send_websocket_handshake3v(nc, path, host, mg_mk_str(protocol),
                                  mg_mk_str(extra_headers), user_info,
                                  null_str);
  }
  return nc;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0xb0, %rsp
movq %r8, %rbx
movq %rcx, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
leaq 0x60(%rsp), %rax
movaps %xmm0, (%rax)
leaq 0x50(%rsp), %rcx
movaps %xmm0, (%rcx)
leaq 0x90(%rsp), %r8
movaps %xmm0, (%r8)
movq 0xf0(%rsp), %r9
movq %r9, 0x20(%rsp)
movaps 0xd0(%rsp), %xmm0
movaps 0xe0(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rax, 0x40(%rsp)
movq %r8, 0x38(%rsp)
movq %rcx, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
leaq 0x4e76(%rip), %rdx      # 0x14e32
leaq 0x50ed(%rip), %rcx      # 0x150b0
leaq 0x4e6d(%rip), %r8       # 0x14e37
leaq 0x50e2(%rip), %r9       # 0x150b3
callq 0xd7a3
movq %rax, %r14
testq %rax, %rax
je 0x10054
movq %r15, %rdi
callq 0x6875
movq %rax, 0x80(%rsp)
movq %rdx, 0x88(%rsp)
movq %rbx, %rdi
callq 0x6875
movq %rax, 0x70(%rsp)
movq %rdx, 0x78(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %r8
movaps 0xa0(%rsp), %xmm0
movups %xmm0, 0x30(%rsp)
movaps 0x90(%rsp), %xmm0
movups %xmm0, 0x20(%rsp)
movups 0x70(%rsp), %xmm0
movups %xmm0, 0x10(%rsp)
movups 0x80(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0xfd69
movq %r14, %rax
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_hexdumpf
void mg_hexdumpf(FILE *fp, const void *buf, int len) {
  char tmp[80];
  int offset = 0, n;
  while (len > 0) {
    n = (len < 16 ? len : 16);
    mg_hexdump_n(((const char *) buf) + offset, n, tmp, sizeof(tmp), offset);
    fputs(tmp, fp);
    offset += n;
    len -= n;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
xorl %ebp, %ebp
movq %rsp, %r12
testl %ebx, %ebx
jle 0x1030f
cmpl $0x10, %ebx
pushq $0x10
popq %r13
cmovbl %ebx, %r13d
movl %ebp, %edi
addq %r14, %rdi
movl %r13d, %esi
movq %r12, %rdx
pushq $0x50
popq %rcx
movl %ebp, %r8d
callq 0x1010a
movq %r12, %rdi
movq %r15, %rsi
callq 0x3230
addl %r13d, %ebp
subl %r13d, %ebx
jmp 0x102d7
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mbuf_append_base64
void mg_mbuf_append_base64(struct mbuf *mbuf, const void *data, size_t len) {
  struct cs_base64_ctx ctx;
  cs_base64_init(&ctx, mg_mbuf_append_base64_putc, mbuf);
  cs_base64_update(&ctx, (const char *) data, len);
  cs_base64_finish(&ctx);
}

// Assembly:
pushq %rbx
subq $0x20, %rsp
leaq 0x8(%rsp), %rbx
andl $0x0, 0xc(%rbx)
leaq -0x2e(%rip), %rax       # 0x10321
movq %rax, (%rbx)
movq %rdi, 0x10(%rbx)
movq %rbx, %rdi
callq 0x43dc
movq %rbx, %rdi
callq 0x44ad
addq $0x20, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_url_encode
struct mg_str mg_url_encode(const struct mg_str src) {
  static const char *dont_escape = "._-$,;~()/";
  static const char *hex = "0123456789abcdef";
  size_t i = 0;
  struct mbuf mb;
  mbuf_init(&mb, src.len);

  for (i = 0; i < src.len; i++) {
    const unsigned char c = *((const unsigned char *) src.p + i);
    if (isalnum(c) || strchr(dont_escape, c) != NULL) {
      mbuf_append(&mb, &c, 1);
    } else {
      mbuf_append(&mb, "%", 1);
      mbuf_append(&mb, &hex[c >> 4], 1);
      mbuf_append(&mb, &hex[c & 15], 1);
    }
  }
  mbuf_append(&mb, "", 1);
  mbuf_trim(&mb);
  return mg_mk_str_n(mb.buf, mb.len - 1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x10(%rsp), %rdi
callq 0x662f
xorl %r13d, %r13d
leaq 0xf(%rsp), %r15
pushq $0x1
popq %rbp
cmpq %r13, %rbx
je 0x1042f
movzbl (%r14,%r13), %r12d
movb %r12b, 0xf(%rsp)
callq 0x3660
movq (%rax), %rax
testb $0x8, (%rax,%r12,2)
movq %r15, %rsi
jne 0x1041a
leaq 0x4d2f(%rip), %rdi      # 0x150f0
movl %r12d, %esi
pushq $0xb
popq %rdx
callq 0x32c0
movq %r15, %rsi
testq %rax, %rax
jne 0x1041a
leaq 0x10(%rsp), %r12
movq %r12, %rdi
leaq 0x4d18(%rip), %rsi      # 0x150fb
movq %rbp, %rdx
callq 0x6836
movzbl 0xf(%rsp), %esi
shrl $0x4, %esi
leaq 0x421f(%rip), %rax      # 0x14619
addq %rax, %rsi
movq %r12, %rdi
movq %rbp, %rdx
callq 0x6836
movzbl 0xf(%rsp), %esi
andl $0xf, %esi
leaq 0x4202(%rip), %rax      # 0x14619
addq %rax, %rsi
leaq 0x10(%rsp), %rdi
movq %rbp, %rdx
callq 0x6836
incq %r13
jmp 0x10395
leaq 0x539a(%rip), %rsi      # 0x157d0
leaq 0x10(%rsp), %rbx
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x6836
movq %rbx, %rdi
callq 0x66a1
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
decq %rsi
callq 0x6892
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mqtt_match_topic_expression
int mg_mqtt_match_topic_expression(struct mg_str exp, struct mg_str topic) {
  /* TODO(mkm): implement real matching */
  if (memchr(exp.p, '#', exp.len)) {
    /* exp `foo/#` will become `foo/` */
    exp.len -= 1;
    /*
     * topic should be longer than the expression: e.g. topic `foo/bar` does
     * match `foo/#`, but neither `foo` nor `foo/` do.
     */
    if (topic.len <= exp.len) {
      return 0;
    }

    /* Truncate topic so that it'll pass the next length check */
    topic.len = exp.len;
  }
  if (topic.len != exp.len) {
    return 0;
  }
  return strncmp(topic.p, exp.p, exp.len) == 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
pushq $0x23
popq %rsi
movq %rbx, %rdx
callq 0x32c0
testq %rax, %rax
je 0x104b1
decq %rbx
cmpq %r12, %rbx
jae 0x104b6
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x30c0
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
sete %al
jmp 0x104b8
cmpq %rbx, %r12
je 0x10498
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mqtt_prepend_header
static void mg_mqtt_prepend_header(struct mg_connection *nc, uint8_t cmd,
                                   uint8_t flags, size_t len) {
  struct mg_mqtt_proto_data *pd = (struct mg_mqtt_proto_data *) nc->proto_data;
  size_t off = nc->send_mbuf.len - len;
  uint8_t header = cmd << 4 | (uint8_t) flags;

  uint8_t buf[1 + sizeof(size_t)];
  uint8_t *vlen = &buf[1];

  assert(nc->send_mbuf.len >= len);

  buf[0] = header;

  /* mqtt variable length encoding */
  do {
    *vlen = len % 0x80;
    len /= 0x80;
    if (len > 0) *vlen |= 0x80;
    vlen++;
  } while (len > 0);

  mbuf_insert(&nc->send_mbuf, off, buf, vlen - buf);
  pd->last_control_time = mg_time();
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movl %esi, %eax
movq 0x60(%rdi), %rsi
subq %rcx, %rsi
jb 0x10c6f
movq 0x88(%rdi), %rbx
shlb $0x4, %al
orb %dl, %al
movb %al, 0x7(%rsp)
pushq $0x1
popq %rax
movq %rcx, %rdx
movl %ecx, %r8d
andb $0x7f, %r8b
shrq $0x7, %rdx
cmpq $0x7f, %rcx
seta %r9b
shlb $0x7, %r9b
orb %r8b, %r9b
movb %r9b, 0x7(%rsp,%rax)
incq %rax
cmpq $0x7f, %rcx
movq %rdx, %rcx
ja 0x10c23
addq $0x58, %rdi
leaq 0x7(%rsp), %rdx
movq %rax, %rcx
callq 0x66aa
callq 0x483c
movsd %xmm0, 0x8(%rbx)
addq $0x10, %rsp
popq %rbx
retq
leaq 0x5a29(%rip), %rdi      # 0x1669f
leaq 0x3931(%rip), %rsi      # 0x145ae
leaq 0x5a34(%rip), %rcx      # 0x166b8
movl $0x28de, %edx           # imm = 0x28DE
callq 0x3220
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mqtt_publish
void mg_mqtt_publish(struct mg_connection *nc, const char *topic,
                     uint16_t message_id, int flags, const void *data,
                     size_t len) {
  size_t old_len = nc->send_mbuf.len;

  uint16_t topic_len = htons((uint16_t) strlen(topic));
  uint16_t message_id_net = htons(message_id);

  mg_send(nc, &topic_len, 2);
  mg_send(nc, topic, strlen(topic));
  if (MG_MQTT_GET_QOS(flags) > 0) {
    mg_send(nc, &message_id_net, 2);
  }
  mg_send(nc, data, len);

  mg_mqtt_prepend_header(nc, MG_MQTT_CMD_PUBLISH, flags,
                         nc->send_mbuf.len - old_len);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, 0x10(%rsp)
movq %r8, %r12
movl %ecx, %ebx
movl %edx, %ebp
movq %rsi, %r13
movq %rdi, %r14
movq 0x60(%rdi), %r15
movq %rsi, %rdi
callq 0x3180
rolw $0x8, %ax
leaq 0xe(%rsp), %rsi
movw %ax, (%rsi)
rolw $0x8, %bp
movw %bp, 0xc(%rsp)
pushq $0x2
popq %rdx
movq %r14, %rdi
callq 0x7b89
movq %r13, %rdi
callq 0x3180
movq %r14, %rdi
movq %r13, %rsi
movl %eax, %edx
callq 0x7b89
testb $0x6, %bl
je 0x10d04
leaq 0xc(%rsp), %rsi
pushq $0x2
popq %rdx
movq %r14, %rdi
callq 0x7b89
movq %r14, %rdi
movq %r12, %rsi
movq 0x10(%rsp), %rdx
callq 0x7b89
movq 0x60(%r14), %rcx
subq %r15, %rcx
movzbl %bl, %edx
pushq $0x3
popq %rsi
movq %r14, %rdi
callq 0x10bfd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mqtt_subscribe
void mg_mqtt_subscribe(struct mg_connection *nc,
                       const struct mg_mqtt_topic_expression *topics,
                       size_t topics_len, uint16_t message_id) {
  size_t old_len = nc->send_mbuf.len;

  uint16_t message_id_n = htons(message_id);
  size_t i;

  mg_send(nc, (char *) &message_id_n, 2);
  for (i = 0; i < topics_len; i++) {
    uint16_t topic_len_n = htons((uint16_t) strlen(topics[i].topic));
    mg_send(nc, &topic_len_n, 2);
    mg_send(nc, topics[i].topic, strlen(topics[i].topic));
    mg_send(nc, &topics[i].qos, 1);
  }

  mg_mqtt_prepend_header(nc, MG_MQTT_CMD_SUBSCRIBE, MG_MQTT_QOS(1),
                         nc->send_mbuf.len - old_len);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x60(%rdi), %rax
movq %rax, 0x10(%rsp)
rolw $0x8, %cx
leaq 0xe(%rsp), %rsi
movw %cx, (%rsi)
pushq $0x2
popq %rdx
callq 0x7b89
addq $0x8, %r15
leaq 0xc(%rsp), %r12
pushq $0x1
popq %r13
subq $0x1, %r14
jb 0x10dcc
movq -0x8(%r15), %rdi
callq 0x3180
rolw $0x8, %ax
movw %ax, 0xc(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
pushq $0x2
popq %rdx
callq 0x7b89
movq -0x8(%r15), %rbp
movq %rbp, %rdi
callq 0x3180
movq %rbx, %rdi
movq %rbp, %rsi
movl %eax, %edx
callq 0x7b89
movq %rbx, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x7b89
addq $0x10, %r15
jmp 0x10d79
movq 0x60(%rbx), %rcx
subq 0x10(%rsp), %rcx
pushq $0x8
popq %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x10bfd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mqtt_next_subscribe_topic
int mg_mqtt_next_subscribe_topic(struct mg_mqtt_message *msg,
                                 struct mg_str *topic, uint8_t *qos, int pos) {
  unsigned char *buf = (unsigned char *) msg->payload.p + pos;
  int new_pos;

  if ((size_t) pos >= msg->payload.len) return -1;

  topic->len = buf[0] << 8 | buf[1];
  topic->p = (char *) buf + 2;
  new_pos = pos + 2 + topic->len + 1;
  if ((size_t) new_pos > msg->payload.len) return -1;
  *qos = buf[2 + topic->len];
  return new_pos;
}

// Assembly:
movslq %ecx, %r8
pushq $-0x1
popq %rax
cmpq %r8, 0x28(%rdi)
jbe 0x10e36
movq 0x20(%rdi), %rcx
addq %r8, %rcx
movzwl (%rcx), %r9d
rolw $0x8, %r9w
movzwl %r9w, %r9d
movq %r9, 0x8(%rsi)
leaq 0x2(%rcx), %r10
movq %r10, (%rsi)
leal (%r8,%r9), %esi
addl $0x3, %esi
movslq %esi, %r8
cmpq %r8, 0x28(%rdi)
jb 0x10e36
movb 0x2(%rcx,%r9), %al
movb %al, (%rdx)
movl %esi, %eax
retq