LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
testl %ecx, %ecx
movl %esi, 0x4(%rsp)
jle 0x10612
movl %ecx, %r15d
movq %rdx, %r14
movl %ecx, %r13d
movq %r13, %rax
shlq $0x4, %rax
xorl %ecx, %ecx
xorl %edx, %edx
addl 0x8(%r14,%rcx), %edx
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0x105a6
movslq %edx, %rdx
leaq 0x8(%rsp), %rcx
movq %rbx, %rdi
callq 0x103fd
testl %r15d, %r15d
jle 0x10621
shlq $0x4, %r13
xorl %ebp, %ebp
movq (%r14,%rbp), %r15
movslq 0x8(%r14,%rbp), %r12
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *0x48(%rcx,%rax,4)
addq $0x10, %rbp
cmpq %rbp, %r13
jne 0x105cf
jmp 0x10621
leaq 0x8(%rsp), %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x103fd
leaq 0x58(%rbx), %rdi
leaq 0x8(%rsp), %rsi
callq 0x10543
cmpl $0x8, 0x4(%rsp)
jne 0x1063d
orb $0x4, 0xc9(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 0x106ac
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 0x75d7
testl %eax, %eax
jle 0x106fd
movq 0x8(%rsp), %rdx
movl %eax, %ecx
movq %r14, %rdi
movl %ebx, %esi
callq 0x1034d
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x10717
callq 0x3060
addq $0x150, %rsp            # imm = 0x150
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x4c04(%rip), %xmm0     # 0x15340
movaps %xmm0, (%rsp)
movl $0xc3d2e1f0, %eax       # imm = 0xC3D2E1F0
movq %rax, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
testq %rdi, %rdi
je 0x1077d
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
xorl %ebp, %ebp
movq %rsp, %r13
movq (%r15,%rbp,8), %rsi
movl (%r14,%rbp,8), %edx
movq %r13, %rdi
callq 0x65b5
incq %rbp
cmpq %rbp, %r12
jne 0x10765
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x6671
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_websocket_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 0x6b26
movq %rax, %r15
movq %rdx, %r12
movq %rbx, %rdi
callq 0x6b26
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 0x10894
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 0x5366(%rip), %rdx      # 0x15e4f
leaq 0x55dd(%rip), %rcx      # 0x160cd
leaq 0x535d(%rip), %r8       # 0x15e54
leaq 0x55d2(%rip), %r9       # 0x160d0
callq 0xe587
movq %rax, %r14
testq %rax, %rax
je 0x10b81
movq %r15, %rdi
callq 0x6b26
movq %rax, 0x80(%rsp)
movq %rdx, 0x88(%rsp)
movq %rbx, %rdi
callq 0x6b26
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 0x10894
movq %r14, %rax
addq $0xb0, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x10e6f
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
cmovbl %ebx, %r13d
movl %ebp, %edi
addq %r14, %rdi
movl %r13d, %esi
movq %r12, %rdx
movl $0x50, %ecx
movl %ebp, %r8d
callq 0x10c3a
movq %r12, %rdi
movq %r15, %rsi
callq 0x3230
addl %r13d, %ebp
subl %r13d, %ebx
jg 0x10e29
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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       # 0x10e73
movq %rax, (%rbx)
movq %rdi, 0x10(%rbx)
movq %rbx, %rdi
callq 0x4613
movq %rbx, %rdi
callq 0x46ef
addq $0x20, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x68dd
testq %rbx, %rbx
je 0x10f8d
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 0x10f74
movl $0xb, %edx
leaq 0x51ed(%rip), %rdi      # 0x1610d
movl %eax, %esi
callq 0x32c0
movq %r12, %rsi
testq %rax, %rax
jne 0x10f74
movl $0x1, %edx
movq %rbp, %rdi
leaq 0x51da(%rip), %rsi      # 0x16118
callq 0x6ae7
movzbl 0xf(%rsp), %esi
shrl $0x4, %esi
leaq 0x46e7(%rip), %rax      # 0x15639
addq %rax, %rsi
movl $0x1, %edx
movq %rbp, %rdi
callq 0x6ae7
movzbl 0xf(%rsp), %esi
andl $0xf, %esi
leaq 0x46c8(%rip), %rax      # 0x15639
addq %rax, %rsi
movl $0x1, %edx
movq %rbp, %rdi
callq 0x6ae7
incq %r13
cmpq %r13, %rbx
jne 0x10eff
leaq 0x5859(%rip), %rsi      # 0x167ed
leaq 0x10(%rsp), %rbx
movl $0x1, %edx
movq %rbx, %rdi
callq 0x6ae7
movq %rbx, %rdi
callq 0x6952
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
decq %rsi
callq 0x6b43
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 0x11013
decq %rbx
cmpq %r12, %rbx
jae 0x11018
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x30c0
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
sete %al
jmp 0x1101a
cmpq %rbx, %r12
je 0x10ffa
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: 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 0x11b55
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 0x11b09
addq $0x58, %rdi
leaq 0x7(%rsp), %rdx
movq %rax, %rcx
callq 0x695b
callq 0x4aab
movsd %xmm0, 0x8(%rbx)
addq $0x10, %rsp
popq %rbx
retq
leaq 0x5b60(%rip), %rdi      # 0x176bc
leaq 0x3a6b(%rip), %rsi      # 0x155ce
leaq 0x5b6b(%rip), %rcx      # 0x176d5
movl $0x28de, %edx           # imm = 0x28DE
callq 0x3220
// File: /workspace/github_c_makefile_star2_O3/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, %r12
movq %r8, 0x8(%rsp)
movl %ecx, %ebx
movl %edx, %ebp
movq %rsi, %r13
movq %rdi, %r14
movq 0x60(%rdi), %rax
movq %rax, 0x10(%rsp)
movq %rsi, %rdi
callq 0x3180
rolw $0x8, %ax
leaq 0x6(%rsp), %r15
movw %ax, (%r15)
rolw $0x8, %bp
movw %bp, 0x4(%rsp)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
movl $0x2, %edx
movq %r14, %rdi
movq %r15, %rsi
callq *0x48(%rcx,%rax,4)
movq %r13, %rdi
callq 0x3180
movq %rax, %r15
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
movslq %r15d, %rdx
movq %r14, %rdi
movq %r13, %rsi
callq *0x48(%rcx,%rax,4)
testb $0x6, %bl
je 0x11c61
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
leaq 0x4(%rsp), %rsi
movl $0x2, %edx
movq %r14, %rdi
callq *0x48(%rcx,%rax,4)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
movslq %r12d, %rdx
movq %r14, %rdi
movq 0x8(%rsp), %rsi
callq *0x48(%rcx,%rax,4)
movq 0x60(%r14), %rcx
subq 0x10(%rsp), %rcx
movzbl %bl, %edx
movq %r14, %rdi
movl $0x3, %esi
callq 0x11ae1
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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), %r12
movw %cx, (%r12)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movl $0x2, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq *0x48(%rcx,%rax,4)
testq %r14, %r14
je 0x11deb
addq $0x8, %r15
leaq 0xc(%rsp), %r12
movq -0x8(%r15), %rdi
callq 0x3180
rolw $0x8, %ax
movw %ax, 0xc(%rsp)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movl $0x2, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq *0x48(%rcx,%rax,4)
movq -0x8(%r15), %r13
movq %r13, %rdi
callq 0x3180
movq %rax, %rbp
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movslq %ebp, %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq *0x48(%rcx,%rax,4)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq *0x48(%rcx,%rax,4)
addq $0x10, %r15
decq %r14
jne 0x11d2c
movq 0x60(%rbx), %rcx
subq 0x10(%rsp), %rcx
movq %rbx, %rdi
movl $0x8, %esi
movl $0x2, %edx
callq 0x11ae1
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 0x11e5b
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 0x11e5b
movb 0x2(%rcx,%r9), %al
movb %al, (%rdx)
movl %esi, %eax
retq
// File: /workspace/github_c_makefile_star2_O3/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), %r12
movw %cx, (%r12)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movl $0x2, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq *0x48(%rcx,%rax,4)
testq %r14, %r14
je 0x11f56
xorl %r12d, %r12d
movq (%r15,%r12,8), %rdi
callq 0x3180
rolw $0x8, %ax
movw %ax, 0xc(%rsp)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movl $0x2, %edx
movq %rbx, %rdi
leaq 0xc(%rsp), %rsi
callq *0x48(%rcx,%rax,4)
movq (%r15,%r12,8), %r13
movq %r13, %rdi
callq 0x3180
movq %rax, %rbp
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movslq %ebp, %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq *0x48(%rcx,%rax,4)
incq %r12
cmpq %r12, %r14
jne 0x11ec7
movq 0x60(%rbx), %rcx
subq 0x10(%rsp), %rcx
movq %rbx, %rdi
movl $0xa, %esi
movl $0x2, %edx
callq 0x11ae1
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xf(%rsp), %r14
movb %sil, (%r14)
leaq 0xe(%rsp), %r15
movb $0x0, (%r15)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq *0x48(%rcx,%rax,4)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x48(%rcx,%rax,4)
movl $0x2, %ecx
movq %rbx, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0x11ae1
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_mqtt_short_command
static void mg_send_mqtt_short_command(struct mg_connection *nc, uint8_t cmd,
                                       uint16_t message_id) {
  uint16_t message_id_net = htons(message_id);
  uint8_t flags = (cmd == MG_MQTT_CMD_PUBREL ? 2 : 0);
  mg_send(nc, &message_id_net, 2);
  mg_mqtt_prepend_header(nc, cmd, flags, 2 /* len */);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
rolw $0x8, %dx
leaq 0x6(%rsp), %r15
movw %dx, (%r15)
xorl %ebp, %ebp
cmpl $0x6, %esi
sete %bpl
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
movl $0x2, %edx
movq %r14, %rdi
movq %r15, %rsi
callq *0x48(%rcx,%rax,4)
addl %ebp, %ebp
movl $0x2, %ecx
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
callq 0x11ae1
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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), %r12
movw %cx, (%r12)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
movl $0x2, %edx
movq %r14, %rdi
movq %r12, %rsi
callq *0x48(%rcx,%rax,4)
testq %rbx, %rbx
je 0x1214c
movq %rbx, %r12
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rsi
callq *0x48(%rcx,%rax,4)
incq %r15
decq %r12
jne 0x12112
addq $0x2, %rbx
movq %r14, %rdi
movl $0x9, %esi
movl $0x2, %edx
movq %rbx, %rcx
callq 0x11ae1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: 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 0x12204
movq %rax, %r8
subq %rdi, %r8
addq $-0x5f0, %r8            # imm = 0xFA10
cmpl %esi, 0x10(%rax)
je 0x12206
addq $0x30, %rax
movq %r8, %rdi
sarq $0x4, %rdi
imulq %rdx, %rdi
addq $0x30, %r8
cmpq %rcx, %rdi
jl 0x121e7
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movl %ecx, (%rsp)
movq (%rsi), %rsi
movq (%rdi), %rbp
addq 0x8(%rdi), %rbp
cmpq %rbp, %rsi
jae 0x12359
movb (%rsi), %r8b
movq %rdx, %rax
testb %r8b, %r8b
je 0x12354
movq %rdi, %r12
xorl %eax, %eax
movq %rdx, %r10
xorl %r11d, %r11d
movq %rdx, 0x8(%rsp)
incq %rsi
cmpq %rbp, %rsi
jae 0x1235b
movzbl %r8b, %ebx
movl %ebx, %ecx
notl %ecx
testb $-0x40, %cl
jne 0x122d8
andl $0x3f, %ebx
shll $0x8, %ebx
movzbl (%rsi), %r14d
orq %rbx, %r14
cmpq %r14, 0x8(%r12)
jbe 0x1235b
cmpl $0xe, %r11d
jg 0x1235b
incl %r11d
addq (%r12), %r14
jmp 0x12332
cmpb $0x3f, %r8b
ja 0x1235b
movl %edx, %r15d
subl %r10d, %r15d
addl (%rsp), %r15d
cmpl %ebx, %r15d
movl %ebx, %ecx
cmovll %r15d, %ecx
movslq %ecx, %r13
leaq (%rsi,%r13), %r14
cmpq %rbp, %r14
jae 0x1235b
movl %r11d, 0x4(%rsp)
movq %r10, %rdi
movq %r13, %rdx
movq %r10, 0x10(%rsp)
callq 0x3380
movq 0x10(%rsp), %r10
addq %r13, %r10
cmpl %ebx, %r15d
jle 0x1236a
movb $0x2e, (%r10)
incq %r10
xorl %eax, %eax
movq 0x8(%rsp), %rdx
movl 0x4(%rsp), %r11d
movb (%r14), %r8b
movq %r14, %rsi
testb %r8b, %r8b
jne 0x12294
movq %rdx, %rax
cmpq %rdx, %r10
je 0x12354
movb $0x0, -0x1(%r10)
decq %r10
movq %r10, %rax
subq %rdx, %rax
jmp 0x1235b
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subq 0x8(%rsp), %r10
movq %r10, %rax
jmp 0x1235b
// File: /workspace/github_c_makefile_star2_O3/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 0xc(%rsp), %rax
movl $0x0, 0x8(%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 0x695b
addq $0x18, %rsp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x123f8
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 0x6ae7
addq $0x8, %rsp
retq
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x1249d
movb %al, 0x7(%rsp)
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6ae7
movzbl 0x7(%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6ae7
movb (%rbp), %al
movb 0x7(%rsp), %cl
cmpb $0x2e, %al
jne 0x12474
incb %cl
movb %cl, 0x7(%rsp)
movb (%rbp), %al
movzbl %cl, %ecx
addq %rcx, %r15
subq %rcx, %r14
testb %al, %al
jne 0x12418
leaq 0x2fe0(%rip), %rsi      # 0x15468
movl $0x1, %edx
movq %rbx, %rdi
callq 0x6ae7
movl 0x8(%rbx), %eax
subl %r13d, %eax
jmp 0x124a2
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_O3/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 0x125e5
movq %r9, %r14
movq %r8, %r13
movq %rsi, %r12
movq %rdi, %rbx
movq 0x8(%rdi), %r15
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x123fb
cmpl $-0x1, %eax
je 0x125e5
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 0x6ae7
movzwl 0x14(%r12), %eax
rolw $0x8, %ax
movw %ax, (%r13)
movl $0x2, %edx
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %r13
callq 0x6ae7
cmpl $0x2, 0x1c(%r12)
jne 0x125df
movl 0x18(%r12), %eax
bswapl %eax
leaq 0x14(%rsp), %rsi
movl %eax, (%rsi)
movl $0x4, %edx
movq %rbx, %rdi
callq 0x6ae7
cmpl $0x5, 0x10(%r12)
jne 0x125b3
movq 0x8(%rbx), %r15
leaq 0x6(%rsp), %rsi
movl $0x2, %edx
movq %rbx, %rdi
callq 0x6ae7
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x123fb
cmpl $-0x1, %eax
je 0x125e5
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 0x125df
movl %r14d, %eax
rolw $0x8, %ax
leaq 0x6(%rsp), %rsi
movw %ax, (%rsi)
movl $0x2, %edx
movq %rbx, %rdi
callq 0x6ae7
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r14, %rdx
callq 0x6ae7
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_O3/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 0x3aec(%rip), %rsi      # 0x1611a
leaq 0x2f99(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x12656
leaq 0x3ae2(%rip), %rdi      # 0x1612c
movq %r15, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x4539
leaq 0x20(%rsp), %r13
movl $0x40, %esi
movq %r13, %rdi
callq 0x68dd
movl 0xbd12(%rip), %eax      # 0x1e380
incl %eax
movl %eax, 0xbd0a(%rip)      # 0x1e380
movw %ax, 0x12(%rbx)
movw $0x100, 0x10(%rbx)      # imm = 0x100
movl $0x1, %r14d
movl %r14d, 0x14(%rbx)
leaq 0x14(%rsp), %rdx
movl $0x0, 0x8(%rdx)
movw %ax, (%rdx)
movl $0x1000001, 0x2(%rdx)   # imm = 0x1000001
movw $0x0, 0x6(%rdx)
movl $0xc, %ecx
movq %r13, %rdi
xorl %esi, %esi
callq 0x695b
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 0x124b1
cmpl $-0x1, %eax
je 0x12758
movq 0x8(%rsp), %r14
testb $0x2, 0xc8(%r14)
jne 0x12714
leaq 0x20(%rsp), %rdi
movzwl 0x8(%rdi), %eax
rolw $0x8, %ax
leaq 0x14(%rsp), %rdx
movw %ax, (%rdx)
movl $0x2, %ecx
xorl %esi, %esi
callq 0x695b
leaq 0x20(%rsp), %r15
movq (%r15), %r12
movslq 0x8(%r15), %r13
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq *0x48(%rcx,%rax,4)
movq %r15, %rdi
callq 0x6934
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_O3/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
leaq 0x10(%rdx), %rdi
movl $0xc10, %edx            # imm = 0xC10
xorl %esi, %esi
callq 0x3240
movq %r12, (%r14)
movq %r15, 0x8(%r14)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0xc, %r15d
jl 0x12874
movzwl (%r12), %eax
movw %ax, 0x12(%r14)
movzwl 0x2(%r12), %eax
rolw $0x8, %ax
addq %r12, %r15
movw %ax, 0x10(%r14)
movzwl 0x4(%r12), %edx
movl %edx, %eax
rolw $0x8, %ax
cmpw $0x20, %ax
movl $0x20, %ecx
cmovbl %eax, %ecx
movl $0xffff, %esi           # imm = 0xFFFF
andl %esi, %ecx
movl %ecx, 0x14(%r14)
movzwl 0x6(%r12), %ecx
rolw $0x8, %cx
movl $0x20, %eax
cmpw $0x20, %cx
cmovael %eax, %ecx
leaq 0xc(%r12), %rax
andl %esi, %ecx
movl %ecx, 0x18(%r14)
testw %dx, %dx
je 0x1283c
leaq 0x20(%r14), %r12
xorl %r13d, %r13d
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
callq 0x12880
testq %rax, %rax
je 0x12874
incq %r13
movslq 0x14(%r14), %rcx
addq $0x30, %r12
cmpq %rcx, %r13
jl 0x12813
movl 0x18(%r14), %ecx
testl %ecx, %ecx
jle 0x12872
leaq 0x620(%r14), %r12
xorl %r13d, %r13d
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
movl $0x1, %ecx
callq 0x12880
testq %rax, %rax
je 0x12874
incq %r13
movslq 0x18(%r14), %rcx
addq $0x30, %r12
cmpq %rcx, %r13
jl 0x1284a
xorl %ebx, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 0x128a8
movq %rdi, %r8
movzbl (%r8), %eax
testq %rax, %rax
je 0x128a8
cmpb $0x40, %al
jae 0x128a5
addq %rax, %r8
incq %r8
cmpq %rsi, %r8
jb 0x1288b
jmp 0x128a8
incq %r8
leaq -0x5(%rsi), %rax
cmpq %rax, %r8
ja 0x12929
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 0x12928
addq $-0x6, %rsi
cmpq %rsi, %rax
jae 0x12929
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_O3/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 %r12
pushq %rbx
subq $0xc30, %rsp            # imm = 0xC30
movl %esi, %ebp
movq %rdi, %rbx
callq *0x98(%rdi)
cmpl $0x3, %ebp
jne 0x12a4b
leaq 0x40(%rbx), %r14
testb $0x2, 0xc8(%rbx)
jne 0x12978
movl $0x2, %esi
movq %r14, %rdi
callq 0x6af6
movq 0x40(%rbx), %rdi
movl 0x48(%rbx), %esi
leaq 0x10(%rsp), %rdx
callq 0x1276f
cmpl $-0x1, %eax
je 0x129a6
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movl $0x64, %esi
callq *0x98(%rbx)
jmp 0x12a3f
leaq 0x10(%rsp), %r15
movl $0xc20, %edx            # imm = 0xC20
movq %r15, %rdi
xorl %esi, %esi
callq 0x3240
movw $0x8081, 0x10(%r15)     # imm = 0x8081
movq %rsp, %rdx
movl $0x0, 0x8(%rdx)
movl $0x81800000, %eax       # imm = 0x81800000
movq %rax, (%rdx)
movl $0xc, %ecx
movq %r14, %rdi
xorl %esi, %esi
callq 0x695b
testb $0x2, 0xc8(%rbx)
jne 0x12a08
movzwl 0x48(%rbx), %eax
rolw $0x8, %ax
movq %rsp, %rdx
movw %ax, (%rdx)
movl $0x2, %ecx
movq %r14, %rdi
xorl %esi, %esi
callq 0x695b
movq 0x40(%rbx), %r15
movslq 0x48(%rbx), %r12
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movl 0xc8(%rbx), %eax
andl $0x2, %eax
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *0x48(%rcx,%rax,4)
movq 0x48(%rbx), %rsi
movq %r14, %rdi
callq 0x6af6
addq $0xc30, %rsp            # imm = 0xC30
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_resolve_from_hosts_file
int mg_resolve_from_hosts_file(const char *name, union socket_address *usa) {
#if MG_ENABLE_FILESYSTEM && defined(MG_HOSTS_FILE_NAME)
  /* TODO(mkm) cache /etc/hosts */
  FILE *fp;
  char line[1024];
  char *p;
  char alias[256];
  unsigned int a, b, c, d;
  int len = 0;

  if ((fp = mg_fopen(MG_HOSTS_FILE_NAME, "r")) == NULL) {
    return -1;
  }

  for (; fgets(line, sizeof(line), fp) != NULL;) {
    if (line[0] == '#') continue;

    if (sscanf(line, "%u.%u.%u.%u%n", &a, &b, &c, &d, &len) == 0) {
      /* TODO(mkm): handle ipv6 */
      continue;
    }
    for (p = line + len; sscanf(p, "%s%n", alias, &len) == 1; p += len) {
      if (strcmp(alias, name) == 0) {
        usa->sin.sin_addr.s_addr = htonl(a << 24 | b << 16 | c << 8 | d);
        fclose(fp);
        return 0;
      }
    }
  }

  fclose(fp);
#else
  (void) name;
  (void) usa;
#endif

  return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x538, %rsp            # imm = 0x538
movq %rsi, %r14
movq %rdi, %r15
movl $0x0, 0x14(%rsp)
leaq 0x36b1(%rip), %rdi      # 0x16132
leaq 0x46b5(%rip), %rsi      # 0x1713d
callq 0x3370
testq %rax, %rax
je 0x12b68
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %rax, %rdx
callq 0x32e0
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x12b98
movq %r14, 0x28(%rsp)
leaq 0x14(%rsp), %r13
leaq 0x3681(%rip), %r14      # 0x1614b
leaq 0x430(%rsp), %rbp
cmpb $0x23, 0x30(%rsp)
je 0x12b46
movq %r13, (%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x3654(%rip), %rsi      # 0x1613d
leaq 0x24(%rsp), %rdx
leaq 0x20(%rsp), %rcx
leaq 0x1c(%rsp), %r8
leaq 0x18(%rsp), %r9
xorl %eax, %eax
callq 0x3420
testl %eax, %eax
je 0x12b46
movslq 0x14(%rsp), %rax
leaq (%rsp,%rax), %r12
addq $0x30, %r12
movq %r12, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x3420
cmpl $0x1, %eax
jne 0x12b46
movq %rbp, %rdi
movq %r15, %rsi
callq 0x3310
testl %eax, %eax
je 0x12b6f
movslq 0x14(%rsp), %rax
addq %rax, %r12
jmp 0x12b15
leaq 0x30(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %rbx, %rdx
callq 0x32e0
testq %rax, %rax
jne 0x12ad2
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x12b98
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x12ba0
movl 0x24(%rsp), %eax
shll $0x18, %eax
movl 0x20(%rsp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movl 0x1c(%rsp), %eax
shll $0x8, %eax
orl %ecx, %eax
orl 0x18(%rsp), %eax
bswapl %eax
movq 0x28(%rsp), %rcx
movl %eax, 0x4(%rcx)
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x3160
movl %ebp, %eax
addq $0x538, %rsp            # imm = 0x538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_set_nameserver
void mg_set_nameserver(struct mg_mgr *mgr, const char *nameserver) {
  MG_FREE((char *) mgr->nameserver);
  mgr->nameserver = NULL;
  if (nameserver != NULL) {
    mgr->nameserver = strdup(nameserver);
  }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq 0x30(%rdi), %rdi
callq 0x3060
movq $0x0, 0x30(%rbx)
testq %r14, %r14
je 0x12df9
movq %r14, %rdi
callq 0x35f0
movq %rax, 0x30(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq