LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/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 0x5b93(%rip), %rsi      # 0x16002
leaq 0x5134(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x1049a
leaq 0x5226(%rip), %rdi      # 0x156b1
movq %rbx, %rsi
movl %ebp, %edx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x45a0
movq %rsp, %r12
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rdx
movq %r12, %rcx
callq 0x104e0
movq %rbx, %rdi
movq %r15, %rsi
movl %r14d, %edx
callq 0x808e
leaq 0x58(%rbx), %rdi
movq %r12, %rsi
callq 0x105a1
cmpl $0x8, %ebp
jne 0x104d3
orb $0x4, 0xc9(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x10515
movb %dl, 0xf(%rsp)
movl $0x2, %edx
jmp 0x10550
cmpq $0xfffe, %rdx           # imm = 0xFFFE
ja 0x10533
rolw $0x8, %dx
movb $0x7e, 0xf(%rsp)
movw %dx, 0x10(%rsp)
movl $0x4, %edx
jmp 0x10550
movb $0x7f, 0xf(%rsp)
movq %rdx, %rax
shrq $0x20, %rax
bswapl %eax
movl %eax, 0x10(%rsp)
bswapl %edx
movl %edx, 0x14(%rsp)
movl $0xa, %edx
cmpq $0x0, 0x10(%r14)
je 0x10568
leaq 0xe(%rsp), %rsi
movq %r14, %rdi
callq 0x808e
xorl %eax, %eax
jmp 0x10596
leaq 0xe(%rsp), %rsi
orb $-0x80, 0x1(%rsi)
movq %r14, %rdi
callq 0x808e
callq 0x3640
leaq 0x8(%rbx), %rsi
movl %eax, 0x8(%rbx)
movq %r14, %rdi
movl $0x4, %edx
callq 0x808e
movq 0x60(%r14), %rax
movq %rax, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/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:
cmpq $0x0, (%rsi)
je 0x105d3
movq (%rsi), %rax
cmpq %rax, 0x8(%rdi)
je 0x105d3
xorl %ecx, %ecx
movl %ecx, %edx
andl $0x3, %edx
movb 0x8(%rsi,%rdx), %dl
addq (%rdi), %rax
xorb %dl, (%rcx,%rax)
incq %rcx
movq 0x8(%rdi), %rdx
movq (%rsi), %rax
subq %rax, %rdx
cmpq %rdx, %rcx
jb 0x105b2
retq
// File: /workspace/github_c_makefile_star2_O1/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, %r15d
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
xorl %edx, %edx
movl %ecx, %r12d
testl %ecx, %ecx
jle 0x1060e
movq %r12, %rax
shlq $0x4, %rax
xorl %ecx, %ecx
addl 0x8(%r14,%rcx), %edx
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0x105fd
movslq %edx, %rdx
movq %rsp, %rcx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x104e0
testl %r15d, %r15d
jle 0x10641
shlq $0x4, %r12
xorl %r15d, %r15d
movq (%r14,%r15), %rsi
movl 0x8(%r14,%r15), %edx
movq %rbx, %rdi
callq 0x808e
addq $0x10, %r15
cmpq %r15, %r12
jne 0x10627
leaq 0x58(%rbx), %rdi
movq %rsp, %rsi
callq 0x105a1
cmpl $0x8, %ebp
jne 0x10659
orb $0x4, 0xc9(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x106c6
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)
movl $0x64, %esi
callq 0x76a7
testl %eax, %eax
jle 0x10717
movq 0x8(%rsp), %rdx
movl %eax, %ecx
movq %r14, %rdi
movl %ebx, %esi
callq 0x10451
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x10731
callq 0x3060
addq $0x150, %rsp            # imm = 0x150
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/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
movaps 0x4bea(%rip), %xmm0     # 0x15340
movups %xmm0, 0xc(%rsp)
movl $0xc3d2e1f0, %eax       # imm = 0xC3D2E1F0
movq %rax, 0x1c(%rsp)
movl $0x0, 0x24(%rsp)
testq %rdi, %rdi
je 0x1079a
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
xorl %ebp, %ebp
leaq 0xc(%rsp), %r13
movq (%r15,%rbp,8), %rsi
movl (%r14,%rbp,8), %edx
movq %r13, %rdi
callq 0x6699
incq %rbp
cmpq %rbp, %r12
jne 0x10782
leaq 0xc(%rsp), %rsi
movq %rbx, %rdi
callq 0x675c
addq $0x68, %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_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, 0x40(%rsp)
movq %rsi, %rdi
callq 0x6be8
movq %rax, %r15
movq %rdx, %r12
movq %rbx, %rdi
callq 0x6be8
movq %rax, 0x58(%rsp)
movq %rdx, 0x60(%rsp)
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
movaps 0x40(%rsp), %xmm0
movups %xmm0, 0x30(%rsp)
movups %xmm0, 0x20(%rsp)
movups 0x58(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x108b3
addq $0x68, %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_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 0x5321(%rip), %rdx      # 0x15e2e
leaq 0x5598(%rip), %rcx      # 0x160ac
leaq 0x5318(%rip), %r8       # 0x15e33
leaq 0x558d(%rip), %r9       # 0x160af
callq 0xe65a
movq %rax, %r14
testq %rax, %rax
je 0x10ba5
movq %r15, %rdi
callq 0x6be8
movq %rax, 0x80(%rsp)
movq %rdx, 0x88(%rsp)
movq %rbx, %rdi
callq 0x6be8
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 0x108b3
movq %r14, %rax
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_conn_addr_to_str
int mg_conn_addr_to_str(struct mg_connection *nc, char *buf, size_t len,
                        int flags) {
  union socket_address sa;
  memset(&sa, 0, sizeof(sa));
  mg_if_get_conn_addr(nc, flags & MG_SOCK_STRINGIFY_REMOTE, &sa);
  return mg_sock_addr_to_str(&sa, buf, len, flags);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %ebx
movq %rdx, %r14
movq %rsi, %r15
xorps %xmm0, %xmm0
movq %rsp, %r12
movaps %xmm0, (%r12)
movl %ecx, %esi
andl $0x4, %esi
movq 0xc0(%rdi), %rax
movq 0x10(%rax), %rax
movq %r12, %rdx
callq *0x78(%rax)
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0xaa56
addq $0x18, %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_hexdump_n
static int mg_hexdump_n(const void *buf, int len, char *dst, int dst_len,
                        int offset) {
  const unsigned char *p = (const unsigned char *) buf;
  char ascii[17] = "";
  int i, idx, n = 0;

  for (i = 0; i < len; i++) {
    idx = i % 16;
    if (idx == 0) {
      if (i > 0) n += snprintf(dst + n, MAX(dst_len - n, 0), "  %s\n", ascii);
      n += snprintf(dst + n, MAX(dst_len - n, 0), "%04x ", i + offset);
    }
    if (dst_len - n < 0) {
      return n;
    }
    n += snprintf(dst + n, MAX(dst_len - n, 0), " %02x", p[i]);
    ascii[idx] = p[i] < 0x20 || p[i] > 0x7e ? '.' : p[i];
    ascii[idx + 1] = '\0';
  }

  while (i++ % 16) n += snprintf(dst + n, MAX(dst_len - n, 0), "%s", "   ");
  n += snprintf(dst + n, MAX(dst_len - n, 0), "  %s\n", ascii);

  return n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %ebx
movq %rdx, %r14
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movb $0x0, 0x10(%rsp)
testl %esi, %esi
jle 0x10d74
movq %rdi, %r15
movl %esi, %eax
movq %rax, 0x30(%rsp)
movl %r8d, %eax
movq %rax, 0x20(%rsp)
xorl %ecx, %ecx
xorl %r13d, %r13d
xorl %eax, %eax
movq %rdi, 0x28(%rsp)
movq %r13, %rbp
andq $0xf, %rbp
je 0x10cb1
movl %eax, %r12d
jmp 0x10d12
testq %r13, %r13
je 0x10cdf
xorl %ecx, %ecx
movslq %eax, %r12
leaq (%r14,%r12), %rdi
movl %ebx, %esi
subl %r12d, %esi
testl %esi, %esi
cmovlel %ecx, %esi
leaq 0x6928(%rip), %rdx      # 0x175f8
movq %rsp, %rcx
xorl %eax, %eax
callq 0x31e0
addl %r12d, %eax
xorl %ecx, %ecx
movslq %eax, %r15
leaq (%r14,%r15), %rdi
movl %ebx, %esi
subl %r15d, %esi
testl %esi, %esi
cmovlel %ecx, %esi
movq 0x20(%rsp), %rax
leal (%rax,%r13), %ecx
leaq 0x68fe(%rip), %rdx      # 0x175fe
xorl %eax, %eax
callq 0x31e0
movl %eax, %r12d
addl %r15d, %r12d
movq 0x28(%rsp), %r15
movl %ebx, %eax
subl %r12d, %eax
js 0x10dee
movslq %r12d, %rdi
addq %r14, %rdi
movl %eax, %esi
movzbl (%r15,%r13), %ecx
leaq 0x68d3(%rip), %rdx      # 0x17604
xorl %eax, %eax
callq 0x31e0
addl %r12d, %eax
movzbl (%r15,%r13), %ecx
leal -0x7f(%rcx), %edx
cmpb $-0x5f, %dl
movl $0x2e, %edx
cmovbl %edx, %ecx
movl %r13d, %edx
andl $0xf, %edx
movb %cl, (%rsp,%rdx)
movq %rsp, %rcx
movb $0x0, 0x1(%rbp,%rcx)
incq %r13
cmpq %r13, 0x30(%rsp)
movl $0x0, %ecx
jne 0x10ca3
jmp 0x10d79
xorl %r13d, %r13d
xorl %eax, %eax
testb $0xf, %r13b
je 0x10dc1
incl %r13d
leaq 0x6881(%rip), %r12      # 0x1760a
movl %r13d, %ebp
movslq %eax, %r15
leaq (%r14,%r15), %rdi
movl %ebx, %esi
subl %r15d, %esi
testl %esi, %esi
movl $0x0, %eax
cmovlel %eax, %esi
leaq 0x5249(%rip), %rdx      # 0x15ff2
movq %r12, %rcx
xorl %eax, %eax
callq 0x31e0
addl %r15d, %eax
incl %ebp
testb $0xf, %r13b
movl %ebp, %r13d
jne 0x10d8c
movslq %eax, %r15
addq %r15, %r14
subl %r15d, %ebx
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
leaq 0x6820(%rip), %rdx      # 0x175f8
movq %rsp, %rcx
movq %r14, %rdi
movq %rbx, %rsi
xorl %eax, %eax
callq 0x31e0
movl %eax, %r12d
addl %r15d, %r12d
movl %r12d, %eax
addq $0x38, %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_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:
testl %edx, %edx
jle 0x10e65
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
cmpl $0x10, %ebx
movl $0x10, %r13d
cmovll %ebx, %r13d
movl %ebp, %edi
addq %r14, %rdi
movl %r13d, %esi
movq %r12, %rdx
movl $0x50, %ecx
movl %ebp, %r8d
callq 0x10c5e
movq %r12, %rdi
movq %r15, %rsi
callq 0x3230
addl %r13d, %ebp
subl %r13d, %ebx
jg 0x10e1f
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_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
movl $0x0, 0xc(%rbx)
leaq -0x33(%rip), %rax       # 0x10e69
movq %rax, (%rbx)
movq %rdi, 0x10(%rbx)
movq %rbx, %rdi
callq 0x467a
movq %rbx, %rdi
callq 0x4751
addq $0x20, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/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 0x69aa
testq %rbx, %rbx
je 0x10f83
xorl %r13d, %r13d
callq 0x3660
movq %rax, %r15
leaq 0xf(%rsp), %r12
leaq 0x10(%rsp), %rbp
movzbl (%r14,%r13), %eax
movb %al, 0xf(%rsp)
movq (%r15), %rcx
testb $0x8, (%rcx,%rax,2)
movq %r12, %rsi
jne 0x10f6a
movl $0xb, %edx
leaq 0x51d9(%rip), %rdi      # 0x160ef
movl %eax, %esi
callq 0x32c0
movq %r12, %rsi
testq %rax, %rax
jne 0x10f6a
movl $0x1, %edx
movq %rbp, %rdi
leaq 0x51c6(%rip), %rsi      # 0x160fa
callq 0x6ba9
movzbl 0xf(%rsp), %esi
shrl $0x4, %esi
leaq 0x46cd(%rip), %rax      # 0x15615
addq %rax, %rsi
movl $0x1, %edx
movq %rbp, %rdi
callq 0x6ba9
movzbl 0xf(%rsp), %esi
andl $0xf, %esi
leaq 0x46ae(%rip), %rax      # 0x15615
addq %rax, %rsi
movl $0x1, %edx
movq %rbp, %rdi
callq 0x6ba9
incq %r13
cmpq %r13, %rbx
jne 0x10ef5
leaq 0x5845(%rip), %rsi      # 0x167cf
leaq 0x10(%rsp), %rbx
movl $0x1, %edx
movq %rbx, %rdi
callq 0x6ba9
movq %rbx, %rdi
callq 0x6a1f
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
decq %rsi
callq 0x6c05
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_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
movl $0x23, %esi
movq %rbx, %rdx
callq 0x32c0
testq %rax, %rax
je 0x10ff3
decq %rbx
cmpq %r12, %rbx
movq %rbx, %r12
jae 0x11011
cmpq %rbx, %r12
jne 0x11011
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x30c0
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
sete %al
jmp 0x11013
xorl %eax, %eax
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_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 0x11830
movq 0x88(%rdi), %rbx
shlb $0x4, %al
orb %dl, %al
movb %al, 0x7(%rsp)
movl $0x1, %eax
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 0x117e4
addq $0x58, %rdi
leaq 0x7(%rsp), %rdx
movq %rax, %rcx
callq 0x6a28
callq 0x4b23
movsd %xmm0, 0x8(%rbx)
addq $0x10, %rsp
popq %rbx
retq
leaq 0x5e67(%rip), %rdi      # 0x1769e
leaq 0x3d6c(%rip), %rsi      # 0x155aa
leaq 0x5e72(%rip), %rcx      # 0x176b7
movl $0x28de, %edx           # imm = 0x28DE
callq 0x3220
// File: /workspace/github_c_makefile_star2_O1/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)
movq %r14, %rdi
movl $0x2, %edx
callq 0x808e
movq %r13, %rdi
callq 0x3180
movq %r14, %rdi
movq %r13, %rsi
movl %eax, %edx
callq 0x808e
testb $0x6, %bl
je 0x118c9
leaq 0xc(%rsp), %rsi
movq %r14, %rdi
movl $0x2, %edx
callq 0x808e
movq %r14, %rdi
movq %r12, %rsi
movq 0x10(%rsp), %rdx
callq 0x808e
movq 0x60(%r14), %rcx
subq %r15, %rcx
movzbl %bl, %edx
movq %r14, %rdi
movl $0x3, %esi
callq 0x117bc
addq $0x18, %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_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
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x60(%rdi), %rbp
rolw $0x8, %cx
leaq 0x6(%rsp), %rsi
movw %cx, (%rsi)
movl $0x2, %edx
callq 0x808e
testq %r14, %r14
je 0x1198f
addq $0x8, %r15
leaq 0x4(%rsp), %r12
movq -0x8(%r15), %rdi
callq 0x3180
rolw $0x8, %ax
movw %ax, 0x4(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl $0x2, %edx
callq 0x808e
movq -0x8(%r15), %r13
movq %r13, %rdi
callq 0x3180
movq %rbx, %rdi
movq %r13, %rsi
movl %eax, %edx
callq 0x808e
movq %rbx, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x808e
addq $0x10, %r15
decq %r14
jne 0x1193b
movq 0x60(%rbx), %rcx
subq %rbp, %rcx
movq %rbx, %rdi
movl $0x8, %esi
movl $0x2, %edx
callq 0x117bc
addq $0x8, %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_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
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %r8, 0x28(%rdi)
jbe 0x119fd
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 0x119fd
movb 0x2(%rcx,%r9), %al
movb %al, (%rdx)
movl %esi, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mqtt_unsubscribe
void mg_mqtt_unsubscribe(struct mg_connection *nc, char **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]));
    mg_send(nc, &topic_len_n, 2);
    mg_send(nc, topics[i], strlen(topics[i]));
  }

  mg_mqtt_prepend_header(nc, MG_MQTT_CMD_UNSUBSCRIBE, 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)
movl $0x2, %edx
callq 0x808e
testq %r14, %r14
je 0x11a83
xorl %ebp, %ebp
leaq 0xc(%rsp), %r12
movq (%r15,%rbp,8), %rdi
callq 0x3180
rolw $0x8, %ax
movw %ax, 0xc(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl $0x2, %edx
callq 0x808e
movq (%r15,%rbp,8), %r13
movq %r13, %rdi
callq 0x3180
movq %rbx, %rdi
movq %r13, %rsi
movl %eax, %edx
callq 0x808e
incq %rbp
cmpq %rbp, %r14
jne 0x11a40
movq 0x60(%rbx), %rcx
subq 0x10(%rsp), %rcx
movq %rbx, %rdi
movl $0xa, %esi
movl $0x2, %edx
callq 0x117bc
addq $0x18, %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_mqtt_connack
void mg_mqtt_connack(struct mg_connection *nc, uint8_t return_code) {
  uint8_t unused = 0;
  mg_send(nc, &unused, 1);
  mg_send(nc, &return_code, 1);
  mg_mqtt_prepend_header(nc, MG_MQTT_CMD_CONNACK, 0, 2);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x7(%rsp), %r14
movb %sil, (%r14)
leaq 0x6(%rsp), %rsi
movb $0x0, (%rsi)
movl $0x1, %edx
callq 0x808e
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x808e
movl $0x2, %ecx
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x117bc
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mqtt_suback
void mg_mqtt_suback(struct mg_connection *nc, uint8_t *qoss, size_t qoss_len,
                    uint16_t message_id) {
  size_t i;
  uint16_t message_id_net = htons(message_id);
  mg_send(nc, &message_id_net, 2);
  for (i = 0; i < qoss_len; i++) {
    mg_send(nc, &qoss[i], 1);
  }
  mg_mqtt_prepend_header(nc, MG_MQTT_CMD_SUBACK, MG_MQTT_QOS(1), 2 + qoss_len);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
rolw $0x8, %cx
leaq 0x6(%rsp), %rsi
movw %cx, (%rsi)
movl $0x2, %edx
callq 0x808e
testq %rbx, %rbx
je 0x11c30
movq %rbx, %r12
movq %r14, %rdi
movq %r15, %rsi
movl $0x1, %edx
callq 0x808e
incq %r15
decq %r12
jne 0x11c18
addq $0x2, %rbx
movq %r14, %rdi
movl $0x9, %esi
movl $0x2, %edx
movq %rbx, %rcx
callq 0x117bc
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_dns_next_record
struct mg_dns_resource_record *mg_dns_next_record(
    struct mg_dns_message *msg, int query,
    struct mg_dns_resource_record *prev) {
  struct mg_dns_resource_record *rr;

  for (rr = (prev == NULL ? msg->answers : prev + 1);
       rr - msg->answers < msg->num_answers; rr++) {
    if (rr->rtype == query) {
      return rr;
    }
  }
  return NULL;
}

// Assembly:
leaq 0x620(%rdi), %r8
leaq 0x30(%rdx), %rax
testq %rdx, %rdx
cmoveq %r8, %rax
movslq 0x18(%rdi), %rcx
movq %rax, %r9
subq %r8, %r9
sarq $0x4, %r9
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %r9
cmpq %rcx, %r9
jge 0x11d17
movq %rax, %r8
subq %rdi, %r8
addq $-0x5f0, %r8            # imm = 0xFA10
cmpl %esi, 0x10(%rax)
je 0x11d19
addq $0x30, %rax
movq %r8, %rdi
sarq $0x4, %rdi
imulq %rdx, %rdi
addq $0x30, %r8
cmpq %rcx, %rdi
jl 0x11cfa
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_dns_uncompress_name
size_t mg_dns_uncompress_name(struct mg_dns_message *msg, struct mg_str *name,
                              char *dst, int dst_len) {
  int chunk_len, num_ptrs = 0;
  char *old_dst = dst;
  const unsigned char *data = (unsigned char *) name->p;
  const unsigned char *end = (unsigned char *) msg->pkt.p + msg->pkt.len;

  if (data >= end) {
    return 0;
  }

  while ((chunk_len = *data++)) {
    int leeway = dst_len - (dst - old_dst);
    if (data >= end) {
      return 0;
    }

    if ((chunk_len & 0xc0) == 0xc0) {
      uint16_t off = (data[-1] & (~0xc0)) << 8 | data[0];
      if (off >= msg->pkt.len) {
        return 0;
      }
      /* Basic circular loop avoidance: allow up to 16 pointer hops. */
      if (++num_ptrs > 15) {
        return 0;
      }
      data = (unsigned char *) msg->pkt.p + off;
      continue;
    }
    if (chunk_len > 63) {
      return 0;
    }
    if (chunk_len > leeway) {
      chunk_len = leeway;
    }

    if (data + chunk_len >= end) {
      return 0;
    }

    memcpy(dst, data, chunk_len);
    data += chunk_len;
    dst += chunk_len;
    leeway -= chunk_len;
    if (leeway == 0) {
      return dst - old_dst;
    }
    *dst++ = '.';
  }

  if (dst != old_dst) {
    *--dst = 0;
  }
  return dst - old_dst;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq (%rsi), %rsi
movq (%rdi), %rbp
addq 0x8(%rdi), %rbp
cmpq %rbp, %rsi
jae 0x11e8c
movq %rdi, %r9
movb (%rsi), %al
movq %rdx, %rdi
testb %al, %al
je 0x11e91
xorl %r10d, %r10d
movq %rdx, %rdi
movq %rdx, 0x18(%rsp)
movl %ecx, 0xc(%rsp)
movq %r9, 0x10(%rsp)
incq %rsi
movl $0x1, %ebx
cmpq %rbp, %rsi
jae 0x11e48
movzbl %al, %r15d
movl %r15d, %r8d
notl %r8d
testb $-0x40, %r8b
jne 0x11ded
andl $0x3f, %r15d
shll $0x8, %r15d
movzbl (%rsi), %eax
orq %r15, %rax
cmpq %rax, 0x8(%r9)
jbe 0x11e48
leal 0x1(%r10), %r8d
cmpl $0xe, %r10d
jle 0x11e5c
movl %r8d, %r10d
jmp 0x11e48
cmpb $0x3f, %al
ja 0x11e48
movl %edx, %r14d
subl %edi, %r14d
addl %ecx, %r14d
cmpl %r15d, %r14d
movl %r15d, %eax
cmovll %r14d, %eax
movslq %eax, %r13
leaq (%rsi,%r13), %rax
cmpq %rbp, %rax
jae 0x11e48
movq %rax, 0x20(%rsp)
movq %r10, 0x28(%rsp)
movq %r13, %rdx
movq %rdi, 0x30(%rsp)
callq 0x3380
movq 0x30(%rsp), %rdi
addq %r13, %rdi
cmpl %r15d, %r14d
jle 0x11e6c
movb $0x2e, (%rdi)
incq %rdi
xorl %ebx, %ebx
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
jmp 0x11e7c
xorl %r12d, %r12d
testb $0x1, %bl
jne 0x11ea3
movb (%rsi), %al
testb %al, %al
jne 0x11da9
jmp 0x11e91
addq (%r9), %rax
movl $0x2, %ebx
movl %r8d, %r10d
movq %rax, %rsi
jmp 0x11e4b
movq %rdi, %r12
movq 0x18(%rsp), %rdx
subq %rdx, %r12
movq 0x20(%rsp), %rsi
movl 0xc(%rsp), %ecx
movq 0x10(%rsp), %r9
movq 0x28(%rsp), %r10
jmp 0x11e4b
xorl %r12d, %r12d
jmp 0x11ea3
cmpq %rdx, %rdi
je 0x11e9d
movb $0x0, -0x1(%rdi)
decq %rdi
subq %rdx, %rdi
movq %rdi, %r12
movq %r12, %rax
addq $0x38, %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_dns_insert_header
int mg_dns_insert_header(struct mbuf *io, size_t pos,
                         struct mg_dns_message *msg) {
  struct mg_dns_header header;

  memset(&header, 0, sizeof(header));
  header.transaction_id = msg->transaction_id;
  header.flags = htons(msg->flags);
  header.num_questions = htons(msg->num_questions);
  header.num_answers = htons(msg->num_answers);

  return mbuf_insert(io, pos, &header, sizeof(header));
}

// Assembly:
subq $0x18, %rsp
leaq 0x8(%rsp), %rax
movl $0x0, 0x8(%rax)
movq $0x0, (%rax)
movzwl 0x12(%rdx), %ecx
movw %cx, (%rax)
movzwl 0x10(%rdx), %ecx
rolw $0x8, %cx
movw %cx, 0x2(%rax)
movzwl 0x14(%rdx), %ecx
rolw $0x8, %cx
movw %cx, 0x4(%rax)
movzwl 0x18(%rdx), %ecx
rolw $0x8, %cx
movw %cx, 0x6(%rax)
movl $0xc, %ecx
movq %rax, %rdx
callq 0x6a28
addq $0x18, %rsp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_dns_copy_questions
int mg_dns_copy_questions(struct mbuf *io, struct mg_dns_message *msg) {
  unsigned char *begin, *end;
  struct mg_dns_resource_record *last_q;
  if (msg->num_questions <= 0) return 0;
  begin = (unsigned char *) msg->pkt.p + sizeof(struct mg_dns_header);
  last_q = &msg->questions[msg->num_questions - 1];
  end = (unsigned char *) last_q->name.p + last_q->name.len + 4;
  return mbuf_append(io, begin, end - begin);
}

// Assembly:
movl 0x14(%rsi), %ecx
testl %ecx, %ecx
jle 0x11f40
pushq %rax
movq (%rsi), %rax
addq $0xc, %rax
decl %ecx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movq 0x20(%rsi,%rcx), %rdx
addq 0x28(%rsi,%rcx), %rdx
subq %rax, %rdx
addq $0x4, %rdx
movq %rax, %rsi
callq 0x6ba9
addq $0x8, %rsp
retq
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_dns_encode_name
int mg_dns_encode_name(struct mbuf *io, const char *name, size_t len) {
  const char *s;
  unsigned char n;
  size_t pos = io->len;

  do {
    if ((s = strchr(name, '.')) == NULL) {
      s = name + len;
    }

    if (s - name > 127) {
      return -1; /* TODO(mkm) cover */
    }
    n = s - name;           /* chunk length */
    mbuf_append(io, &n, 1); /* send length */
    mbuf_append(io, name, n);

    if (*s == '.') {
      n++;
    }

    name += n;
    len -= n;
  } while (*s != '\0');
  mbuf_append(io, "\0", 1); /* Mark end of host name */

  return io->len - pos;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x8(%rdi), %r13
leaq 0x7(%rsp), %r12
movq %r15, %rdi
movl $0x2e, %esi
callq 0x31d0
leaq (%r15,%r14), %rbp
testq %rax, %rax
cmovneq %rax, %rbp
movq %rbp, %rax
subq %r15, %rax
cmpq $0x7f, %rax
jg 0x11fdf
movb %al, 0x7(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6ba9
movzbl 0x7(%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6ba9
cmpb $0x2e, (%rbp)
jne 0x11fb2
incb 0x7(%rsp)
movzbl 0x7(%rsp), %eax
addq %rax, %r15
subq %rax, %r14
cmpb $0x0, (%rbp)
jne 0x11f60
leaq 0x348e(%rip), %rsi      # 0x15458
movl $0x1, %edx
movq %rbx, %rdi
callq 0x6ba9
movl 0x8(%rbx), %eax
subl %r13d, %eax
jmp 0x11fe4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %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_dns_encode_record
int mg_dns_encode_record(struct mbuf *io, struct mg_dns_resource_record *rr,
                         const char *name, size_t nlen, const void *rdata,
                         size_t rlen) {
  size_t pos = io->len;
  uint16_t u16;
  uint32_t u32;

  if (rr->kind == MG_DNS_INVALID_RECORD) {
    return -1; /* LCOV_EXCL_LINE */
  }

  if (mg_dns_encode_name(io, name, nlen) == -1) {
    return -1;
  }

  u16 = htons(rr->rtype);
  mbuf_append(io, &u16, 2);
  u16 = htons(rr->rclass);
  mbuf_append(io, &u16, 2);

  if (rr->kind == MG_DNS_ANSWER) {
    u32 = htonl(rr->ttl);
    mbuf_append(io, &u32, 4);

    if (rr->rtype == MG_DNS_CNAME_RECORD) {
      int clen;
      /* fill size after encoding */
      size_t off = io->len;
      mbuf_append(io, &u16, 2);
      if ((clen = mg_dns_encode_name(io, (const char *) rdata, rlen)) == -1) {
        return -1;
      }
      u16 = clen;
      io->buf[off] = u16 >> 8;
      io->buf[off + 1] = u16 & 0xff;
    } else {
      u16 = htons((uint16_t) rlen);
      mbuf_append(io, &u16, 2);
      mbuf_append(io, rdata, rlen);
    }
  }

  return io->len - pos;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x0, 0x1c(%rsi)
je 0x12127
movq %r9, %r14
movq %r8, %r13
movq %rsi, %r12
movq %rdi, %rbx
movq 0x8(%rdi), %r15
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x11f43
cmpl $-0x1, %eax
je 0x12127
movq %r13, 0x8(%rsp)
movzwl 0x10(%r12), %eax
rolw $0x8, %ax
leaq 0x6(%rsp), %r13
movw %ax, (%r13)
movl $0x2, %edx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x6ba9
movzwl 0x14(%r12), %eax
rolw $0x8, %ax
movw %ax, (%r13)
movl $0x2, %edx
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %r13
callq 0x6ba9
cmpl $0x2, 0x1c(%r12)
jne 0x12121
movl 0x18(%r12), %eax
bswapl %eax
leaq 0x14(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %rbx, %rdi
callq 0x6ba9
cmpl $0x5, 0x10(%r12)
jne 0x120f5
movq 0x8(%rbx), %r15
leaq 0x6(%rsp), %rsi
movl $0x2, %edx
movq %rbx, %rdi
callq 0x6ba9
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x11f43
cmpl $-0x1, %eax
je 0x12127
movw %ax, 0x6(%rsp)
movq (%rbx), %rcx
movq %r15, %rdx
movb %ah, (%rcx,%rdx)
movb 0x6(%rsp), %al
movq (%rbx), %rcx
movb %al, 0x1(%rcx,%r15)
jmp 0x12121
movl %r14d, %eax
rolw $0x8, %ax
leaq 0x6(%rsp), %rsi
movw %ax, (%rsi)
movl $0x2, %edx
movq %rbx, %rdi
callq 0x6ba9
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x6ba9
movl 0x8(%rbx), %ebp
subl %r13d, %ebp
movl %ebp, %eax
addq $0x18, %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_send_dns_query
void mg_send_dns_query(struct mg_connection *nc, const char *name,
                       int query_type) {
  struct mg_dns_message *msg =
      (struct mg_dns_message *) MG_CALLOC(1, sizeof(*msg));
  struct mbuf pkt;
  struct mg_dns_resource_record *rr = &msg->questions[0];

  DBG(("%s %d", name, query_type));

  mbuf_init(&pkt, 64 /* Start small, it'll grow as needed. */);

  msg->transaction_id = ++mg_dns_tid;
  msg->flags = 0x100;
  msg->num_questions = 1;

  mg_dns_insert_header(&pkt, 0, msg);

  rr->rtype = query_type;
  rr->rclass = 1; /* Class: inet */
  rr->kind = MG_DNS_QUESTION;

  if (mg_dns_encode_record(&pkt, rr, name, strlen(name), NULL, 0) == -1) {
    /* TODO(mkm): return an error code */
    goto cleanup; /* LCOV_EXCL_LINE */
  }

  /* TCP DNS requires messages to be prefixed with len */
  if (!(nc->flags & MG_F_UDP)) {
    uint16_t len = htons((uint16_t) pkt.len);
    mbuf_insert(&pkt, 0, &len, 2);
  }

  mg_send(nc, pkt.buf, pkt.len);
  mbuf_free(&pkt);

cleanup:
  MG_FREE(msg);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
movl $0x1, %edi
movl $0xc20, %esi            # imm = 0xC20
callq 0x3300
movq %rax, %rbx
movq %rax, %r12
addq $0x20, %r12
leaq 0x3f8c(%rip), %rsi      # 0x160fc
leaq 0x3433(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x12198
leaq 0x3f82(%rip), %rdi      # 0x1610e
movq %r15, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x45a0
leaq 0x20(%rsp), %r13
movl $0x40, %esi
movq %r13, %rdi
callq 0x69aa
movl 0xc1d0(%rip), %eax      # 0x1e380
incl %eax
movl %eax, 0xc1c8(%rip)      # 0x1e380
movw %ax, 0x12(%rbx)
movw $0x100, 0x10(%rbx)      # imm = 0x100
movl $0x1, %r14d
movl %r14d, 0x14(%rbx)
leaq 0x10(%rsp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
movw %ax, (%rdx)
movl $0x1000001, 0x2(%rdx)   # imm = 0x1000001
movzwl 0x18(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x6(%rdx)
movl $0xc, %ecx
movq %r13, %rdi
xorl %esi, %esi
callq 0x6a28
movl %ebp, 0x30(%rbx)
movl %r14d, 0x34(%rbx)
movl %r14d, 0x3c(%rbx)
movq %r15, %rdi
callq 0x3180
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %rax, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x11ff3
cmpl $-0x1, %eax
je 0x1227f
movq 0x8(%rsp), %r14
testb $0x2, 0xc8(%r14)
jne 0x12263
leaq 0x20(%rsp), %rdi
movzwl 0x8(%rdi), %eax
rolw $0x8, %ax
leaq 0x10(%rsp), %rdx
movw %ax, (%rdx)
movl $0x2, %ecx
xorl %esi, %esi
callq 0x6a28
leaq 0x20(%rsp), %r15
movq (%r15), %rsi
movl 0x8(%r15), %edx
movq %r14, %rdi
callq 0x808e
movq %r15, %rdi
callq 0x6a01
movq %rbx, %rdi
callq 0x3060
addq $0x38, %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_parse_dns
int mg_parse_dns(const char *buf, int len, struct mg_dns_message *msg) {
  struct mg_dns_header *header = (struct mg_dns_header *) buf;
  unsigned char *data = (unsigned char *) buf + sizeof(*header);
  unsigned char *end = (unsigned char *) buf + len;
  int i;

  memset(msg, 0, sizeof(*msg));
  msg->pkt.p = buf;
  msg->pkt.len = len;

  if (len < (int) sizeof(*header)) return -1;

  msg->transaction_id = header->transaction_id;
  msg->flags = ntohs(header->flags);
  msg->num_questions = ntohs(header->num_questions);
  if (msg->num_questions > (int) ARRAY_SIZE(msg->questions)) {
    msg->num_questions = (int) ARRAY_SIZE(msg->questions);
  }
  msg->num_answers = ntohs(header->num_answers);
  if (msg->num_answers > (int) ARRAY_SIZE(msg->answers)) {
    msg->num_answers = (int) ARRAY_SIZE(msg->answers);
  }

  for (i = 0; i < msg->num_questions; i++) {
    data = mg_parse_dns_resource_record(data, end, &msg->questions[i], 0);
    if (data == NULL) return -1;
  }

  for (i = 0; i < msg->num_answers; i++) {
    data = mg_parse_dns_resource_record(data, end, &msg->answers[i], 1);
    if (data == NULL) return -1;
  }

  return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdx, %r14
movq %rdi, %r12
movslq %esi, %r15
movl $0xc20, %edx            # imm = 0xC20
movq %r14, %rdi
xorl %esi, %esi
callq 0x3240
movq %r12, (%r14)
movq %r15, 0x8(%r14)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0xc, %r15d
jl 0x12396
addq %r12, %r15
movzwl (%r12), %eax
movw %ax, 0x12(%r14)
movzwl 0x2(%r12), %eax
rolw $0x8, %ax
movw %ax, 0x10(%r14)
movzwl 0x4(%r12), %eax
rolw $0x8, %ax
cmpw $0x20, %ax
movl $0x20, %ecx
cmovbl %eax, %ecx
movl $0xffff, %edx           # imm = 0xFFFF
andl %edx, %ecx
movl %ecx, 0x14(%r14)
movzwl 0x6(%r12), %esi
rolw $0x8, %si
movl $0x20, %eax
cmpw $0x20, %si
cmovael %eax, %esi
leaq 0xc(%r12), %rax
andl %edx, %esi
movl %esi, 0x18(%r14)
testl %ecx, %ecx
jle 0x1235b
leaq 0x20(%r14), %r12
xorl %r13d, %r13d
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x123a2
testq %rax, %rax
je 0x12396
incq %r13
movslq 0x14(%r14), %rcx
addq $0x30, %r12
cmpq %rcx, %r13
jl 0x12336
cmpl $0x0, 0x18(%r14)
jle 0x12394
leaq 0x620(%r14), %r12
xorl %r13d, %r13d
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl $0x1, %ecx
callq 0x123a2
testq %rax, %rax
je 0x12396
incq %r13
movslq 0x18(%r14), %rcx
addq $0x30, %r12
cmpq %rcx, %r13
jl 0x1236c
xorl %ebx, %ebx
movl %ebx, %eax
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_parse_dns_resource_record
static unsigned char *mg_parse_dns_resource_record(
    unsigned char *data, unsigned char *end, struct mg_dns_resource_record *rr,
    int reply) {
  unsigned char *name = data;
  int chunk_len, data_len;

  while (data < end && (chunk_len = *data)) {
    if (((unsigned char *) data)[0] & 0xc0) {
      data += 1;
      break;
    }
    data += chunk_len + 1;
  }

  if (data > end - 5) {
    return NULL;
  }

  rr->name.p = (char *) name;
  rr->name.len = data - name + 1;
  data++;

  rr->rtype = data[0] << 8 | data[1];
  data += 2;

  rr->rclass = data[0] << 8 | data[1];
  data += 2;

  rr->kind = reply ? MG_DNS_ANSWER : MG_DNS_QUESTION;
  if (reply) {
    if (data >= end - 6) {
      return NULL;
    }

    rr->ttl = (uint32_t) data[0] << 24 | (uint32_t) data[1] << 16 |
              data[2] << 8 | data[3];
    data += 4;

    data_len = *data << 8 | *(data + 1);
    data += 2;

    rr->rdata.p = (char *) data;
    rr->rdata.len = data_len;
    data += data_len;
  }
  return data;
}

// Assembly:
movq %rdi, %r8
cmpq %rsi, %rdi
jae 0x123ca
movq %rdi, %r8
movzbl (%r8), %eax
testq %rax, %rax
je 0x123ca
cmpb $0x40, %al
jae 0x123c7
addq %rax, %r8
incq %r8
cmpq %rsi, %r8
jb 0x123ad
jmp 0x123ca
incq %r8
leaq -0x5(%rsi), %rax
cmpq %rax, %r8
ja 0x1244b
movq %rdi, (%rdx)
movq %r8, %rax
subq %rdi, %rax
incq %rax
movq %rax, 0x8(%rdx)
movzwl 0x1(%r8), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movl %eax, 0x10(%rdx)
movzwl 0x3(%r8), %edi
rolw $0x8, %di
leaq 0x5(%r8), %rax
xorl %r9d, %r9d
testl %ecx, %ecx
setne %r9b
incl %r9d
movzwl %di, %edi
movl %edi, 0x14(%rdx)
movl %r9d, 0x1c(%rdx)
testl %ecx, %ecx
je 0x1244a
addq $-0x6, %rsi
cmpq %rsi, %rax
jae 0x1244b
movl 0x5(%r8), %eax
bswapl %eax
movl %eax, 0x18(%rdx)
movzwl 0x9(%r8), %eax
rolw $0x8, %ax
movzwl %ax, %eax
leaq 0xb(%r8), %rcx
movq %rcx, 0x20(%rdx)
movq %rax, 0x28(%rdx)
addq %r8, %rax
addq $0xb, %rax
retq
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: dns_handler
static void dns_handler(struct mg_connection *nc, int ev,
                        void *ev_data MG_UD_ARG(void *user_data)) {
  struct mbuf *io = &nc->recv_mbuf;
  struct mg_dns_message msg;

  /* Pass low-level events to the user handler */
  nc->handler(nc, ev, ev_data MG_UD_ARG(user_data));

  switch (ev) {
    case MG_EV_RECV:
      if (!(nc->flags & MG_F_UDP)) {
        mbuf_remove(&nc->recv_mbuf, 2);
      }
      if (mg_parse_dns(nc->recv_mbuf.buf, nc->recv_mbuf.len, &msg) == -1) {
        /* reply + recursion allowed + format error */
        memset(&msg, 0, sizeof(msg));
        msg.flags = 0x8081;
        mg_dns_insert_header(io, 0, &msg);
        if (!(nc->flags & MG_F_UDP)) {
          uint16_t len = htons((uint16_t) io->len);
          mbuf_insert(io, 0, &len, 2);
        }
        mg_send(nc, io->buf, io->len);
      } else {
        /* Call user handler with parsed message */
        nc->handler(nc, MG_DNS_MESSAGE, &msg MG_UD_ARG(user_data));
      }
      mbuf_remove(io, io->len);
      break;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xc38, %rsp            # imm = 0xC38
movl %esi, %ebp
movq %rdi, %rbx
callq *0x98(%rdi)
cmpl $0x3, %ebp
jne 0x1256e
leaq 0x40(%rbx), %r14
testb $0x2, 0xc8(%rbx)
jne 0x12498
movl $0x2, %esi
movq %r14, %rdi
callq 0x6bb8
movq 0x40(%rbx), %rdi
movl 0x48(%rbx), %esi
leaq 0x18(%rsp), %rdx
callq 0x12296
cmpl $-0x1, %eax
je 0x124c6
leaq 0x18(%rsp), %rdx
movq %rbx, %rdi
movl $0x64, %esi
callq *0x98(%rbx)
jmp 0x12562
leaq 0x18(%rsp), %r15
movl $0xc20, %edx            # imm = 0xC20
movq %r15, %rdi
xorl %esi, %esi
callq 0x3240
movw $0x8081, 0x10(%r15)     # imm = 0x8081
leaq 0x8(%rsp), %rdx
movq $0x0, (%rdx)
movl $0x0, 0x8(%rdx)
movzwl 0x12(%r15), %eax
movzwl 0x14(%r15), %ecx
movw %ax, (%rdx)
movw $0x8180, 0x2(%rdx)      # imm = 0x8180
rolw $0x8, %cx
movw %cx, 0x4(%rdx)
movzwl 0x18(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x6(%rdx)
movl $0xc, %ecx
movq %r14, %rdi
xorl %esi, %esi
callq 0x6a28
testb $0x2, 0xc8(%rbx)
jne 0x12553
movzwl 0x48(%rbx), %eax
rolw $0x8, %ax
leaq 0x8(%rsp), %rdx
movw %ax, (%rdx)
movl $0x2, %ecx
movq %r14, %rdi
xorl %esi, %esi
callq 0x6a28
movq 0x40(%rbx), %rsi
movl 0x48(%rbx), %edx
movq %rbx, %rdi
callq 0x808e
movq 0x48(%rbx), %rsi
movq %r14, %rdi
callq 0x6bb8
addq $0xc38, %rsp            # imm = 0xC38
popq %rbx
popq %r14
popq %r15
popq %rbp
retq