LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/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)
pushq $0x2
popq %rdx
callq 0x7b89
xorl %ebp, %ebp
leaq 0xc(%rsp), %r12
cmpq %rbp, %r14
je 0x10eb5
movq (%r15,%rbp,8), %rdi
callq 0x3180
rolw $0x8, %ax
movw %ax, 0xc(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
pushq $0x2
popq %rdx
callq 0x7b89
movq (%r15,%rbp,8), %r13
movq %r13, %rdi
callq 0x3180
movq %rbx, %rdi
movq %r13, %rsi
movl %eax, %edx
callq 0x7b89
incq %rbp
jmp 0x10e72
movq 0x60(%rbx), %rcx
subq 0x10(%rsp), %rcx
pushq $0xa
popq %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x10bfd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mqtt_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 %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0xf(%rsp), %r14
movb %sil, (%r14)
leaq 0xe(%rsp), %rsi
movb $0x0, (%rsi)
pushq $0x1
popq %rbp
movl %ebp, %edx
callq 0x7b89
movq %rbx, %rdi
movq %r14, %rsi
movl %ebp, %edx
callq 0x7b89
pushq $0x2
popq %rsi
pushq $0x2
popq %rcx
movq %rbx, %rdi
xorl %edx, %edx
callq 0x10bfd
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 %r14
pushq %rbx
subq $0x10, %rsp
movl %esi, %ebx
movq %rdi, %r14
rolw $0x8, %dx
leaq 0xe(%rsp), %rsi
movw %dx, (%rsi)
xorl %ebp, %ebp
cmpl $0x6, %ebx
sete %bpl
pushq $0x2
popq %rdx
callq 0x7b89
addl %ebp, %ebp
pushq $0x2
popq %rcx
movq %r14, %rdi
movl %ebx, %esi
movl %ebp, %edx
callq 0x10bfd
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
rolw $0x8, %cx
leaq 0xe(%rsp), %rsi
movw %cx, (%rsi)
pushq $0x2
popq %rdx
callq 0x7b89
pushq $0x1
popq %rbp
movq %rbx, %r12
subq $0x1, %r12
jb 0x10fcd
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x7b89
incq %r15
jmp 0x10fb5
addq $0x2, %rbx
pushq $0x9
popq %rsi
pushq $0x2
popq %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x10bfd
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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), %rax
leaq 0x30(%rdx), %rcx
testq %rdx, %rdx
cmoveq %rax, %rcx
movslq 0x18(%rdi), %r9
movq %rcx, %r8
subq %rdi, %r8
addq $-0x620, %r8            # imm = 0xF9E0
pushq $0x30
popq %rdi
movq %r8, %rax
cqto
idivq %rdi
cmpq %r9, %rax
jge 0x1105f
cmpl %esi, 0x10(%rcx)
je 0x11061
addq $0x30, %rcx
addq $0x30, %r8
jmp 0x11043
xorl %ecx, %ecx
movq %rcx, %rax
retq
// File: /workspace/github_c_makefile_star2_O2/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, 0x4(%rsp)
movq (%rsi), %rsi
movq (%rdi), %r12
addq 0x8(%rdi), %r12
xorl %eax, %eax
cmpq %r12, %rsi
jae 0x111ac
movq %rdx, %rbx
xorl %r9d, %r9d
movq %rdx, %r8
movq %rdi, 0x8(%rsp)
movl %r9d, (%rsp)
movzbl (%rsi), %r15d
testl %r15d, %r15d
je 0x1118c
incq %rsi
cmpq %r12, %rsi
jae 0x11188
movl %r15d, %eax
notl %eax
testb $-0x40, %al
je 0x11155
cmpb $0x3f, %r15b
ja 0x11188
movl %ebx, %ebp
subl %r8d, %ebp
addl 0x4(%rsp), %ebp
cmpl %r15d, %ebp
movl %r15d, %eax
cmovll %ebp, %eax
movslq %eax, %r13
leaq (%rsi,%r13), %r14
cmpq %r12, %r14
jae 0x11188
movq %r8, %rdi
movq %r13, %rdx
movq %r8, 0x10(%rsp)
callq 0x3380
movq 0x10(%rsp), %r8
addq %r13, %r8
cmpl %r15d, %ebp
jle 0x1119e
movb $0x2e, (%r8)
incq %r8
movq %r14, %rsi
jmp 0x110e6
andl $0x3f, %r15d
shll $0x8, %r15d
movzbl (%rsi), %esi
orq %r15, %rsi
movq 0x8(%rsp), %rdi
cmpq %rsi, 0x8(%rdi)
jbe 0x11188
movl (%rsp), %r9d
cmpl $0xe, %r9d
movl $0x0, %eax
ja 0x111ac
incl %r9d
addq (%rdi), %rsi
jmp 0x110e2
xorl %eax, %eax
jmp 0x111ac
cmpq %rbx, %r8
je 0x111a6
movb $0x0, -0x1(%r8)
decq %r8
movq %r8, %rax
jmp 0x111a9
subq %rbx, %r8
movq %r8, %rax
jmp 0x111ac
movq %rbx, %rax
subq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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
andl $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)
pushq $0xc
popq %rcx
movq %rax, %rdx
callq 0x66aa
addq $0x18, %rsp
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x11236
pushq %rax
movq (%rsi), %rax
addq $0xc, %rax
decl %ecx
imulq $0x30, %rcx, %rcx
movq 0x20(%rsi,%rcx), %rdx
addq 0x28(%rsi,%rcx), %rdx
subq %rax, %rdx
addq $0x4, %rdx
movq %rax, %rsi
callq 0x6836
addq $0x8, %rsp
retq
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O2/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
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movq %rax, 0x10(%rsp)
pushq $0x2e
popq %r12
pushq $0x1
popq %rbp
movq %r15, %rdi
movl %r12d, %esi
callq 0x31d0
leaq (%r15,%r14), %r13
testq %rax, %rax
cmovneq %rax, %r13
movq %r13, %rax
subq %r15, %rax
cmpq $0x7f, %rax
jg 0x112e4
movb %al, 0xf(%rsp)
movq %rbx, %rdi
leaq 0xf(%rsp), %rsi
movq %rbp, %rdx
callq 0x6836
movzbl 0xf(%rsp), %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6836
movb (%r13), %al
movb 0xf(%rsp), %cl
cmpb $0x2e, %al
jne 0x112bc
incb %cl
movb %cl, 0xf(%rsp)
movb (%r13), %al
movzbl %cl, %ecx
addq %rcx, %r15
subq %rcx, %r14
testb %al, %al
jne 0x11260
leaq 0x3178(%rip), %rsi      # 0x14448
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x6836
movl 0x8(%rbx), %eax
subl 0x10(%rsp), %eax
jmp 0x112e7
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 $0x28, %rsp
pushq $-0x1
popq %rbp
cmpl $0x0, 0x1c(%rsi)
je 0x1142b
movq %r9, %r14
movq %r8, %r13
movq %rsi, %r12
movq %rdi, %rbx
movq 0x8(%rdi), %r15
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x11239
cmpl $-0x1, %eax
je 0x1142b
movq %r13, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movzwl 0x10(%r12), %eax
rolw $0x8, %ax
leaq 0xe(%rsp), %r13
movw %ax, (%r13)
pushq $0x2
popq %r14
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x6836
movzwl 0x14(%r12), %eax
rolw $0x8, %ax
movw %ax, (%r13)
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x6836
cmpl $0x2, 0x1c(%r12)
jne 0x11425
movl 0x18(%r12), %eax
bswapl %eax
leaq 0x24(%rsp), %rsi
movl %eax, (%rsi)
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0x6836
cmpl $0x5, 0x10(%r12)
jne 0x113f6
movq 0x8(%rbx), %r14
leaq 0xe(%rsp), %rsi
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x6836
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x11239
cmpl $-0x1, %eax
je 0x1142b
movw %ax, 0xe(%rsp)
movq (%rbx), %rcx
movq %r14, %rdx
movb %ah, (%rcx,%rdx)
movb 0xe(%rsp), %al
movq (%rbx), %rcx
movb %al, 0x1(%rcx,%r14)
jmp 0x11425
movq 0x18(%rsp), %r14
movl %r14d, %eax
rolw $0x8, %ax
leaq 0xe(%rsp), %rsi
movw %ax, (%rsi)
pushq $0x2
popq %rdx
movq %rbx, %rdi
callq 0x6836
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x6836
movl 0x8(%rbx), %ebp
subl %r15d, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 $0x28, %rsp
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, 0x8(%rsp)
pushq $0x1
popq %rdi
movl $0xc20, %esi            # imm = 0xC20
callq 0x3300
movq %rax, %rbx
movq %rax, %r12
addq $0x20, %r12
leaq 0x3c8b(%rip), %rsi      # 0x150fd
leaq 0x3135(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x11498
leaq 0x3c83(%rip), %rdi      # 0x1510f
movq %r15, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x430a
leaq 0x10(%rsp), %r13
pushq $0x40
popq %rsi
movq %r13, %rdi
callq 0x662f
movl 0xced2(%rip), %eax      # 0x1e380
incl %eax
movl %eax, 0xceca(%rip)      # 0x1e380
movw %ax, 0x12(%rbx)
movw $0x100, 0x10(%rbx)      # imm = 0x100
pushq $0x1
popq %r14
movl %r14d, 0x14(%rbx)
movq %r13, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x111bb
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 0x112f6
cmpl $-0x1, %eax
je 0x1154e
movq 0x8(%rsp), %r14
testb $0x2, 0xc8(%r14)
jne 0x11532
leaq 0x10(%rsp), %rdi
movzwl 0x8(%rdi), %eax
rolw $0x8, %ax
leaq 0x6(%rsp), %rdx
movw %ax, (%rdx)
pushq $0x2
popq %rcx
xorl %esi, %esi
callq 0x66aa
leaq 0x10(%rsp), %r15
movq (%r15), %rsi
movl 0x8(%r15), %edx
movq %r14, %rdi
callq 0x7b89
movq %r15, %rdi
callq 0x6683
movq %rbx, %rdi
callq 0x3060
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rdi, %r15
movslq %esi, %r14
leaq 0x10(%rdx), %rdi
movl $0xc10, %edx            # imm = 0xC10
xorl %esi, %esi
callq 0x3240
movq %r15, (%rbx)
movq %r14, 0x8(%rbx)
pushq $-0x1
popq %rbp
cmpl $0xc, %r14d
jl 0x11655
movzwl (%r15), %eax
movw %ax, 0x12(%rbx)
movzwl 0x2(%r15), %eax
rolw $0x8, %ax
movw %ax, 0x10(%rbx)
movzwl 0x4(%r15), %eax
rolw $0x8, %ax
addq %r15, %r14
cmpw $0x20, %ax
pushq $0x20
popq %rcx
movl %ecx, %edx
cmovbl %eax, %edx
movl $0xffff, %esi           # imm = 0xFFFF
andl %esi, %edx
movl %edx, 0x14(%rbx)
movzwl 0x6(%r15), %edx
rolw $0x8, %dx
leaq 0xc(%r15), %rax
cmpw $0x20, %dx
cmovael %ecx, %edx
andl %esi, %edx
movl %edx, 0x18(%rbx)
leaq 0x20(%rbx), %rdx
pushq $-0x1
popq %r15
movslq 0x14(%rbx), %rcx
incq %r15
cmpq %rcx, %r15
jge 0x1161c
leaq 0x30(%rdx), %r12
movq %rax, %rdi
movq %r14, %rsi
xorl %ecx, %ecx
callq 0x11666
movq %r12, %rdx
testq %rax, %rax
jne 0x115f5
jmp 0x11655
leaq 0x620(%rbx), %rdx
pushq $-0x1
popq %r12
pushq $0x1
popq %r15
movslq 0x18(%rbx), %rcx
incq %r12
cmpq %rcx, %r12
jge 0x11653
leaq 0x30(%rdx), %r13
movq %rax, %rdi
movq %r14, %rsi
movl %r15d, %ecx
callq 0x11666
movq %r13, %rdx
testq %rax, %rax
jne 0x1162b
jmp 0x11655
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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, %r8
jae 0x11686
movzbl (%r8), %eax
testq %rax, %rax
je 0x11686
cmpb $0x40, %al
jae 0x11683
addq %rax, %r8
incq %r8
jmp 0x11669
incq %r8
leaq -0x5(%rsi), %rax
cmpq %rax, %r8
ja 0x11707
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 0x11706
addq $-0x6, %rsi
cmpq %rsi, %rax
jae 0x11707
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_O2/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 $0xc28, %rsp            # imm = 0xC28
movl %esi, %ebp
movq %rdi, %rbx
callq *0x98(%rdi)
cmpl $0x3, %ebp
jne 0x117e4
leaq 0x40(%rbx), %r14
testb $0x2, 0xc8(%rbx)
jne 0x11752
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x6845
movq 0x40(%rbx), %rdi
movl 0x48(%rbx), %esi
leaq 0x8(%rsp), %rdx
callq 0x11565
cmpl $-0x1, %eax
je 0x1177b
pushq $0x64
popq %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq *0x98(%rbx)
jmp 0x117d8
leaq 0x8(%rsp), %r15
movl $0xc20, %edx            # imm = 0xC20
movq %r15, %rdi
xorl %esi, %esi
callq 0x3240
movw $0x8081, 0x10(%r15)     # imm = 0x8081
movq %r14, %rdi
xorl %esi, %esi
movq %r15, %rdx
callq 0x111bb
testb $0x2, 0xc8(%rbx)
jne 0x117c9
movzwl 0x48(%rbx), %eax
rolw $0x8, %ax
leaq 0x6(%rsp), %rdx
movw %ax, (%rdx)
pushq $0x2
popq %rcx
movq %r14, %rdi
xorl %esi, %esi
callq 0x66aa
movq 0x40(%rbx), %rsi
movl 0x48(%rbx), %edx
movq %rbx, %rdi
callq 0x7b89
movq 0x48(%rbx), %rsi
movq %r14, %rdi
callq 0x6845
addq $0xc28, %rsp            # imm = 0xC28
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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, %rbx
movq %rdi, %r15
andl $0x0, 0x14(%rsp)
leaq 0x3900(%rip), %rdi      # 0x15115
leaq 0x4904(%rip), %rsi      # 0x16120
callq 0x3370
testq %rax, %rax
je 0x1190e
movq %rax, %r14
movq %rbx, 0x28(%rsp)
leaq 0x14(%rsp), %r13
leaq 0x38f0(%rip), %rbx      # 0x1512e
leaq 0x30(%rsp), %rbp
leaq 0x130(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
movq %r14, %rdx
callq 0x32e0
testq %rax, %rax
je 0x11925
cmpb $0x23, 0x130(%rsp)
je 0x11843
movq %r13, (%rsp)
leaq 0x130(%rsp), %rdi
leaq 0x38a2(%rip), %rsi      # 0x15120
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 0x11843
leaq 0x130(%rsp), %r12
movq %r12, %rax
movslq 0x14(%rsp), %r12
addq %rax, %r12
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %r13, %rcx
xorl %eax, %eax
callq 0x3420
cmpl $0x1, %eax
jne 0x11843
movq %rbp, %rdi
movq %r15, %rsi
callq 0x3310
testl %eax, %eax
jne 0x118a5
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 %ebx, %ebx
movq %r14, %rdi
callq 0x3160
jmp 0x11911
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x538, %rsp            # imm = 0x538
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $-0x1
popq %rbx
jmp 0x11904
// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, 0x30(%rbx)
testq %r14, %r14
je 0x11b60
movq %r14, %rdi
callq 0x35f0
movq %rax, 0x30(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_tun_log_frame
void mg_tun_log_frame(struct mg_tun_frame *frame) {
  LOG(LL_DEBUG, ("Got TUN frame: type=0x%x, flags=0x%x stream_id=0x%x, "
                 "len=%d",
                 frame->type, frame->flags, (unsigned int) frame->stream_id,
                 (int) frame->body.len));
#if MG_ENABLE_HEXDUMP
  {
    char hex[512];
    mg_hexdump(frame->body.p, frame->body.len, hex, sizeof(hex) - 1);
    hex[sizeof(hex) - 1] = '\0';
    LOG(LL_DEBUG, ("body:\n%s", hex));
  }
#else
  LOG(LL_DEBUG, ("body: '%.*s'", (int) frame->body.len, frame->body.p));
#endif
}

// Assembly:
pushq %rbx
subq $0x200, %rsp            # imm = 0x200
movq %rdi, %rbx
leaq 0x35eb(%rip), %rsi      # 0x15165
leaq 0x2a2d(%rip), %rdx      # 0x145ae
pushq $0x3
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x11ba9
movzbl (%rbx), %esi
movzbl 0x1(%rbx), %edx
movl 0x4(%rbx), %ecx
movl 0x10(%rbx), %r8d
leaq 0x35d4(%rip), %rdi      # 0x15176
xorl %eax, %eax
callq 0x430a
movq 0x8(%rbx), %rdi
movl 0x10(%rbx), %esi
movq %rsp, %rbx
movq %rbx, %rdx
movl $0x1ff, %ecx            # imm = 0x1FF
callq 0xa2bb
movb $0x0, 0x1ff(%rbx)
leaq 0x3597(%rip), %rsi      # 0x15165
leaq 0x29d9(%rip), %rdx      # 0x145ae
pushq $0x3
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x11bf2
leaq 0x35ca(%rip), %rdi      # 0x151b2
movq %rsp, %rsi
xorl %eax, %eax
callq 0x430a
addq $0x200, %rsp            # imm = 0x200
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_tun_reconnect_ev_handler
void mg_tun_reconnect_ev_handler(struct mg_connection *nc, int ev,
                                 void *ev_data MG_UD_ARG(void *user_data)) {
#if !MG_ENABLE_CALLBACK_USERDATA
  void *user_data = nc->user_data;
#else
  (void) nc;
#endif
  struct mg_tun_client *client = (struct mg_tun_client *) user_data;
  (void) ev_data;

  switch (ev) {
    case MG_EV_TIMER:
      if (!(client->listener->flags & MG_F_TUN_DO_NOT_RECONNECT)) {
        mg_tun_do_reconnect(client);
      } else {
        /* Reconnecting is suppressed, we'll check again at the next poll */
        mg_tun_reconnect(client, 0);
      }
      break;
  }
}

// Assembly:
pushq %rbx
subq $0x60, %rsp
cmpl $0x6, %esi
jne 0x11cb3
movq 0xa0(%rdi), %rbx
movq 0x28(%rbx), %rax
testb $-0x80, 0xc9(%rax)
jne 0x11c7c
xorps %xmm0, %xmm0
andq $0x0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq (%rbx), %rdi
movq 0x10(%rbx), %rdx
movq 0x50(%rsp), %rax
movq %rax, 0x20(%rsp)
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0xc92(%rip), %rsi       # 0x128ed
leaq 0x4af3(%rip), %rcx      # 0x16755
xorl %r8d, %r8d
callq 0xff42
testq %rax, %rax
je 0x11c88
movq %rax, 0x20(%rbx)
movq %rbx, 0xa0(%rax)
jmp 0x11cb3
movq %rbx, %rdi
xorl %esi, %esi
addq $0x60, %rsp
popq %rbx
jmp 0x11cb9
leaq 0x4acd(%rip), %rsi      # 0x1675c
leaq 0x2918(%rip), %rdx      # 0x145ae
xorl %edi, %edi
callq 0x4227
testl %eax, %eax
je 0x11cb3
movq 0x10(%rbx), %rsi
leaq 0x4ac4(%rip), %rdi      # 0x16770
xorl %eax, %eax
callq 0x430a
addq $0x60, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_tun_reconnect
static void mg_tun_reconnect(struct mg_tun_client *client, int timeout) {
  if (client->reconnect == NULL) {
    client->reconnect = mg_add_sock(client->mgr, INVALID_SOCKET,
                                    MG_CB(mg_tun_reconnect_ev_handler, client));
#if !MG_ENABLE_CALLBACK_USERDATA
    client->reconnect->user_data = client;
#endif
  }
  client->reconnect->ev_timer_time = mg_time() + timeout;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
cmpq $0x0, 0x30(%rdi)
jne 0x11ce5
movq (%rbx), %rdi
leaq -0xd7(%rip), %rdx       # 0x11bfb
pushq $-0x1
popq %rsi
callq 0x91ac
movq %rax, 0x30(%rbx)
movq %rbx, 0xa0(%rax)
callq 0x483c
cvtsi2sd %ebp, %xmm1
addsd %xmm0, %xmm1
movq 0x30(%rbx), %rax
movsd %xmm1, 0x78(%rax)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_tun_parse_frame
int mg_tun_parse_frame(void *data, size_t len, struct mg_tun_frame *frame) {
  const size_t header_size = sizeof(uint32_t) + sizeof(uint8_t) * 2;
  if (len < header_size) {
    return -1;
  }

  frame->type = *(uint8_t *) (data);
  frame->flags = *(uint8_t *) ((char *) data + 1);
  memcpy(&frame->stream_id, (char *) data + 2, sizeof(uint32_t));
  frame->stream_id = ntohl(frame->stream_id);
  frame->body.p = (char *) data + header_size;
  frame->body.len = len - header_size;
  return 0;
}

// Assembly:
cmpq $0x6, %rsi
jae 0x11d0c
pushq $-0x1
popq %rax
retq
movb (%rdi), %al
movb %al, (%rdx)
movb 0x1(%rdi), %al
movb %al, 0x1(%rdx)
movl 0x2(%rdi), %eax
bswapl %eax
movl %eax, 0x4(%rdx)
addq $0x6, %rdi
movq %rdi, 0x8(%rdx)
addq $-0x6, %rsi
movq %rsi, 0x10(%rdx)
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: cs_base64_emit_code
static void cs_base64_emit_code(struct cs_base64_ctx *ctx, int v) {
  if (v < NUM_UPPERCASES) {
    ctx->b64_putc(v + 'A', ctx->user_data);
  } else if (v < (NUM_LETTERS)) {
    ctx->b64_putc(v - NUM_UPPERCASES + 'a', ctx->user_data);
  } else if (v < (NUM_LETTERS + NUM_DIGITS)) {
    ctx->b64_putc(v - NUM_LETTERS + '0', ctx->user_data);
  } else {
    ctx->b64_putc(v - NUM_LETTERS - NUM_DIGITS == 0 ? '+' : '/',
                  ctx->user_data);
  }
}

// Assembly:
cmpl $0x19, %esi
jg 0x11d3c
addb $0x41, %sil
jmp 0x11d45
cmpl $0x33, %esi
ja 0x11d55
addb $0x47, %sil
movq (%rdi), %rcx
movq 0x10(%rdi), %rax
movsbl %sil, %edi
movq %rax, %rsi
jmpq *%rcx
movq (%rdi), %rcx
movq 0x10(%rdi), %rax
cmpl $0x3d, %esi
ja 0x11d67
addb $-0x4, %sil
jmp 0x11d4c
xorl %edx, %edx
cmpl $0x3e, %esi
setne %dl
leal 0x2b(,%rdx,4), %edi
jmp 0x11d50
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_conn_destructor
static void mg_http_conn_destructor(void *proto_data) {
  struct mg_http_proto_data *pd = (struct mg_http_proto_data *) proto_data;
#if MG_ENABLE_FILESYSTEM
  mg_http_free_proto_data_file(&pd->file);
#endif
#if MG_ENABLE_HTTP_CGI
  mg_http_free_proto_data_cgi(&pd->cgi);
#endif
#if MG_ENABLE_HTTP_STREAMING_MULTIPART
  mg_http_free_proto_data_mp_stream(&pd->mp_stream);
#endif
  mg_http_free_proto_data_endpoints(&pd->endpoints);
  mg_http_free_reverse_proxy_data(&pd->reverse_proxy_data);
  MG_FREE(proto_data);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
callq 0x11df2
leaq 0x20(%rbx), %rdi
callq 0x11e14
movq 0x38(%rbx), %r14
testq %r14, %r14
je 0x11dc2
movq (%r14), %r15
movq 0x8(%r14), %rdi
callq 0x3060
movq 0x18(%r14), %rdi
callq 0x3060
movq 0x20(%r14), %rdi
callq 0x3060
movq %r14, %rdi
callq 0x3060
movq %r15, %r14
jmp 0x11d92
movq 0x48(%rbx), %rdi
testq %rdi, %rdi
je 0x11de5
callq 0xb106
movq 0x48(%rax), %rcx
testq %rcx, %rcx
je 0x11de5
orb $0x4, 0xc9(%rcx)
andq $0x0, 0x48(%rax)
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x3060
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_free_proto_data_file
static void mg_http_free_proto_data_file(struct mg_http_proto_data_file *d) {
  if (d != NULL) {
    if (d->fp != NULL) {
      fclose(d->fp);
    }
    memset(d, 0, sizeof(struct mg_http_proto_data_file));
  }
}

// Assembly:
testq %rdi, %rdi
je 0x11e13
pushq %rbx
movq %rdi, %rbx
movq (%rdi), %rdi
testq %rdi, %rdi
je 0x11e08
callq 0x3160
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movups %xmm0, (%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_free_proto_data_cgi
MG_INTERNAL void mg_http_free_proto_data_cgi(struct mg_http_proto_data_cgi *d) {
  if (d == NULL) return;
  if (d->cgi_nc != NULL) {
    d->cgi_nc->flags |= MG_F_CLOSE_IMMEDIATELY;
    d->cgi_nc->user_data = NULL;
  }
  memset(d, 0, sizeof(*d));
}

// Assembly:
testq %rdi, %rdi
je 0x11e34
movq (%rdi), %rax
testq %rax, %rax
je 0x11e30
orb $0x8, 0xc9(%rax)
andq $0x0, 0xa0(%rax)
andq $0x0, (%rdi)
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_is_authorized
static int mg_http_is_authorized(struct http_message *hm, struct mg_str path,
                                 int is_directory, const char *domain,
                                 const char *passwords_file,
                                 int is_global_pass_file) {
  char buf[MG_MAX_PATH];
  const char *p;
  FILE *fp;
  int authorized = 1;

  if (domain != NULL && passwords_file != NULL) {
    if (is_global_pass_file) {
      fp = mg_fopen(passwords_file, "r");
    } else if (is_directory) {
      snprintf(buf, sizeof(buf), "%.*s%c%s", (int) path.len, path.p, DIRSEP,
               passwords_file);
      fp = mg_fopen(buf, "r");
    } else {
      p = strrchr(path.p, DIRSEP);
      if (p == NULL) p = path.p;
      snprintf(buf, sizeof(buf), "%.*s%c%s", (int) (p - path.p), path.p, DIRSEP,
               passwords_file);
      fp = mg_fopen(buf, "r");
    }

    if (fp != NULL) {
      authorized = mg_http_check_digest_auth(hm, domain, fp);
      fclose(fp);
    }
  }

  LOG(LL_DEBUG,
      ("%.*s %s %d %d", (int) path.len, path.p,
       passwords_file ? passwords_file : "", is_global_pass_file, authorized));
  return authorized;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1028, %rsp           # imm = 0x1028
movq %r9, %r15
movq %r8, %r13
movq %rdx, %r8
movq %rsi, %r10
movl 0x1060(%rsp), %r14d
testq %r13, %r13
sete %al
testq %r9, %r9
sete %dl
pushq $0x1
popq %r12
orb %al, %dl
movq %r8, 0x18(%rsp)
jne 0x11e8f
testl %r14d, %r14d
movq %rdi, 0x10(%rsp)
je 0x11e97
movq %r10, %rbx
leaq 0x4299(%rip), %rsi      # 0x16120
movq %r15, %rdi
jmp 0x11f1d
movq %r10, %rbx
jmp 0x11f45
testl %ecx, %ecx
je 0x11ed3
movq %r15, (%rsp)
leaq 0x388f(%rip), %rdx      # 0x15735
leaq 0x20(%rsp), %rbp
pushq $0x2f
popq %r9
movl $0x1000, %esi           # imm = 0x1000
movq %rbp, %rdi
movl %r8d, %ecx
movq %r10, %rbx
movq %r10, %r8
xorl %eax, %eax
callq 0x31e0
leaq 0x4252(%rip), %rsi      # 0x16120
movq %rbp, %rdi
jmp 0x11f1d
pushq $0x2f
popq %rsi
movq %r10, %rdi
movq %r10, %rbp
callq 0x31f0
testq %rax, %rax
cmovel %ebp, %eax
subl %ebp, %eax
movq %r15, (%rsp)
leaq 0x3841(%rip), %rdx      # 0x15735
leaq 0x20(%rsp), %rdi
movl $0x1000, %esi           # imm = 0x1000
movl %eax, %ecx
movq %rbp, %rbx
movq %rbp, %r8
pushq $0x2f
popq %r9
xorl %eax, %eax
callq 0x31e0
leaq 0x4208(%rip), %rsi      # 0x16120
leaq 0x20(%rsp), %rdi
callq 0x3370
movq %rax, %rbp
testq %rax, %rax
je 0x11f45
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xcfca
movl %eax, %r12d
movq %rbp, %rdi
callq 0x3160
leaq 0x37f2(%rip), %rsi      # 0x1573e
leaq 0x265b(%rip), %rdx      # 0x145ae
pushq $0x3
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x11f89
testq %r15, %r15
leaq 0x3867(%rip), %rcx      # 0x157d0
cmovneq %r15, %rcx
leaq 0x37e0(%rip), %rdi      # 0x15754
movq 0x18(%rsp), %rsi
movq %rbx, %rdx
movl %r14d, %r8d
movl %r12d, %r9d
xorl %eax, %eax
callq 0x430a
movl %r12d, %eax
addq $0x1028, %rsp           # imm = 0x1028
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_send_digest_auth_request
static void mg_http_send_digest_auth_request(struct mg_connection *c,
                                             const char *domain) {
  mg_printf(c,
            "HTTP/1.1 401 Unauthorized\r\n"
            "WWW-Authenticate: Digest qop=\"auth\", "
            "realm=\"%s\", nonce=\"%lu\"\r\n"
            "Content-Length: 0\r\n\r\n",
            domain, (unsigned long) mg_time());
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
callq 0x483c
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd 0x2347(%rip), %xmm0     # 0x14308
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rax, %rcx
leaq 0x378f(%rip), %rsi      # 0x15762
movq %r14, %rdi
movq %rbx, %rdx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x7bce
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_is_file_hidden
static int mg_is_file_hidden(const char *path,
                             const struct mg_serve_http_opts *opts,
                             int exclude_specials) {
  const char *p1 = opts->per_directory_auth_file;
  const char *p2 = opts->hidden_file_pattern;

  /* Strip directory path from the file name */
  const char *pdir = strrchr(path, DIRSEP);
  if (pdir != NULL) {
    path = pdir + 1;
  }

  return (exclude_specials && (!strcmp(path, ".") || !strcmp(path, ".."))) ||
         (p1 != NULL &&
          mg_match_prefix(p1, strlen(p1), path) == (int) strlen(p1)) ||
         (p2 != NULL && mg_match_prefix(p2, strlen(p2), path) > 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r12d
movq %rdi, %r13
movq 0x10(%rsi), %r15
movq 0x58(%rsi), %rbx
pushq $0x2f
popq %rsi
callq 0x31f0
leaq 0x1(%rax), %r14
testq %rax, %rax
cmoveq %r13, %r14
pushq $0x1
popq %rbp
testl %r12d, %r12d
je 0x12036
cmpb $0x2e, (%r14)
jne 0x12036
cmpb $0x0, 0x1(%r14)
je 0x12086
cmpb $0x2e, 0x1(%r14)
jne 0x12036
cmpb $0x0, 0x2(%r14)
je 0x12086
testq %r15, %r15
je 0x12060
movq %r15, %rdi
callq 0x3180
movq %r15, %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0x42d8
movl %eax, %r12d
movq %r15, %rdi
callq 0x3180
cmpl %eax, %r12d
je 0x12086
testq %rbx, %rbx
je 0x12084
movq %rbx, %rdi
callq 0x3180
movq %rbx, %rdi
movl %eax, %esi
movq %r14, %rdx
callq 0x42d8
xorl %ebp, %ebp
testl %eax, %eax
setg %bpl
jmp 0x12086
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_addenv
static char *mg_addenv(struct mg_cgi_env_block *block, const char *fmt, ...) {
  int n, space;
  char *added = block->buf + block->len;
  va_list ap;

  /* Calculate how much space is left in the buffer */
  space = sizeof(block->buf) - (block->len + 2);
  if (space > 0) {
    /* Copy VARIABLE=VALUE\0 string into the free space */
    va_start(ap, fmt);
    n = vsnprintf(added, (size_t) space, fmt, ap);
    va_end(ap);

    /* Make sure we do not overflow buffer and the envp array */
    if (n > 0 && n + 1 < space &&
        block->nvars < (int) ARRAY_SIZE(block->vars) - 2) {
      /* Append a pointer to the added string into the envp array */
      block->vars[block->nvars++] = added;
      /* Bump up used length counter. Include \0 terminator */
      block->len += n + 1;
    }
  }

  return added;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0xd0, %rsp
movq %rdx, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x40(%rsp)
movq %r9, 0x48(%rsp)
testb %al, %al
je 0x1228c
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
movslq 0x2208(%rdi), %rax
leaq (%rdi,%rax), %r14
addq $0x8, %r14
movl $0x1ffe, %ebp           # imm = 0x1FFE
subl %eax, %ebp
testl %ebp, %ebp
jle 0x1230c
movq %rsi, %r10
movq %rdi, %rbx
leaq 0x20(%rsp), %rax
movq %rsp, %rcx
movq %rax, 0x10(%rcx)
leaq 0xf0(%rsp), %rax
movq %rax, 0x8(%rcx)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rcx)
movl %ebp, %esi
movq %r14, %rdi
movq %r10, %rdx
callq 0x3110
testl %eax, %eax
jle 0x1230c
incl %eax
cmpl %ebp, %eax
jae 0x1230c
movslq 0x220c(%rbx), %rcx
cmpq $0x3d, %rcx
jg 0x1230c
leal 0x1(%rcx), %edx
movl %edx, 0x220c(%rbx)
movq %r14, 0x2008(%rbx,%rcx,8)
addl %eax, 0x2208(%rbx)
movq %r14, %rax
addq $0xd0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_get_mime_type
static struct mg_str mg_get_mime_type(const char *path, const char *dflt,
                                      const struct mg_serve_http_opts *opts) {
  const char *ext, *overrides;
  size_t i, path_len;
  struct mg_str r, k, v;

  path_len = strlen(path);

  overrides = opts->custom_mime_types;
  while ((overrides = mg_next_comma_list_entry(overrides, &k, &v)) != NULL) {
    ext = path + (path_len - k.len);
    if (path_len > k.len && mg_vcasecmp(&k, ext) == 0) {
      return v;
    }
  }

  for (i = 0; mg_static_builtin_mime_types[i].extension != NULL; i++) {
    ext = path + (path_len - mg_static_builtin_mime_types[i].ext_len);
    if (path_len > mg_static_builtin_mime_types[i].ext_len && ext[-1] == '.' &&
        mg_casecmp(ext, mg_static_builtin_mime_types[i].extension) == 0) {
      r.p = mg_static_builtin_mime_types[i].mime_type;
      r.len = strlen(r.p);
      return r;
    }
  }

  r.p = dflt;
  r.len = strlen(r.p);
  return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r15
movq %rdi, %rbx
callq 0x3180
movq %rax, %r14
movq 0x70(%r15), %r13
leaq 0x18(%rsp), %r15
leaq 0x8(%rsp), %r12
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x7325
testq %rax, %rax
je 0x123bd
movq %rax, %r13
movq %r14, %rsi
subq 0x20(%rsp), %rsi
jbe 0x12382
addq %rbx, %rsi
movq %r15, %rdi
callq 0x68d7
testl %eax, %eax
jne 0x12382
movq 0x8(%rsp), %r15
movq 0x10(%rsp), %r12
jmp 0x12414
pushq $0x10
popq %r13
leaq 0xb578(%rip), %rbp      # 0x1d940
pushq $0xa
popq %r12
leaq 0x3d73(%rip), %r15      # 0x16146
cmpq $0x490, %r13            # imm = 0x490
je 0x12414
movq %r14, %rax
subq -0x8(%r13,%rbp), %rax
jbe 0x123fe
leaq (%rbx,%rax), %rdi
cmpb $0x2e, -0x1(%rdi)
jne 0x123fe
movq -0x10(%r13,%rbp), %rsi
callq 0x71a3
testl %eax, %eax
je 0x12404
addq $0x18, %r13
jmp 0x123d3
movq (%r13,%rbp), %r15
movq %r15, %rdi
callq 0x3180
movq %rax, %r12
movq %r15, %rax
movq %r12, %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_file_data
static void mg_send_file_data(struct mg_connection *nc, FILE *fp) {
  char buf[BUFSIZ];
  size_t n;
  while ((n = mg_fread(buf, 1, sizeof(buf), fp)) > 0) {
    mg_send(nc, buf, n);
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x2008, %rsp           # imm = 0x2008
movq %rsi, %rbx
movq %rdi, %r14
movq %rsp, %r15
pushq $0x1
popq %r12
movl $0x2000, %edx           # imm = 0x2000
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rcx
callq 0x3100
testq %rax, %rax
je 0x128c2
movq %r14, %rdi
movq %r15, %rsi
movl %eax, %edx
callq 0x7b89
jmp 0x1289b
addq $0x2008, %rsp           # imm = 0x2008
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/config.c
// Function: addMotion
bool addMotion(umConfig *config, char *name, char *action) {

  if (config->numMotions > MAX_CAMERAS*2)
    return false;

  config->motions[config->numMotions] = (umotion *)malloc(sizeof(umotion));

  strncpy(config->motions[config->numMotions]->name, name, LABEL_LEN);
  strncpy(config->motions[config->numMotions]->action, action, JSON_MQTT_MSG_SIZE);

  if (strlen(name) >= LABEL_LEN-1) {
    config->motions[config->numMotions]->name[LABEL_LEN-1] = 0;
    fprintf(stderr, "ERROR motion label '%s' is too long for buffer, truncated to '%s'\n", name, config->motions[config->numMotions]->name);
  }

  if (strlen(action) >= JSON_MQTT_MSG_SIZE-1) {
    config->motions[config->numMotions]->action[JSON_MQTT_MSG_SIZE-1] = 0;
    fprintf(stderr, "ERROR motion action '%s' is too long for buffer, truncated to '%s'\n", action, config->motions[config->numMotions]->action);
  }
  config->numMotions++;

  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movslq 0x1d8(%rdi), %r13
cmpq $0x28, %r13
jg 0x12c6f
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movl $0x8c, %edi
callq 0x33e0
movq %rax, %r12
movq %rax, 0x98(%rbx,%r13,8)
pushq $0x28
popq %rdx
movq %rax, %rdi
movq %r15, %rsi
callq 0x30b0
leaq 0x28(%r12), %rdi
pushq $0x64
popq %rdx
movq %r14, %rsi
callq 0x30b0
movq %r15, %rdi
callq 0x3180
movl %r13d, %ebp
cmpq $0x27, %rax
jae 0x12c85
movq %r14, %rdi
callq 0x3180
cmpq $0x63, %rax
jae 0x12cb1
incl %ebp
movl %ebp, 0x1d8(%rbx)
cmpl $0x29, %r13d
setl %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, 0x27(%r12)
movq 0xb35e(%rip), %rax      # 0x1dff0
movq (%rax), %rdi
leaq 0x3d24(%rip), %rsi      # 0x169c0
movq %r15, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x3340
movl 0x1d8(%rbx), %ebp
jmp 0x12c59
movslq %ebp, %rax
movq 0x98(%rbx,%rax,8), %rax
movb $0x0, 0x8b(%rax)
movq 0xb326(%rip), %rax      # 0x1dff0
movq (%rax), %rdi
movslq 0x1d8(%rbx), %rax
movq 0x98(%rbx,%rax,8), %rcx
addq $0x28, %rcx
leaq 0x3d1c(%rip), %rsi      # 0x16a03
movq %r14, %rdx
xorl %eax, %eax
callq 0x3340
movl 0x1d8(%rbx), %ebp
jmp 0x12c67
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/config.c
// Function: cleanwhitespace
char *cleanwhitespace(char *str)
{
  char *end;
  // Trim leading space
  while(isspace(*str)) str++;

  if(*str == 0)  // All spaces?
    return str;

  // Trim trailing space
  end = str + strlen(str) - 1;
  while(end > str && isspace(*end)) end--;

  // Write new null terminator
  *(end+1) = 0;

  return str;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x3660
movq (%rax), %r14
decq %rbx
movsbq 0x1(%rbx), %rax
incq %rbx
testb $0x20, 0x1(%r14,%rax,2)
jne 0x12d0e
testb %al, %al
je 0x12d4d
movq %rbx, %rdi
callq 0x3180
leaq (%rbx,%rax), %rcx
decq %rcx
movq %rcx, %rax
cmpq %rbx, %rcx
jbe 0x12d49
movsbq (%rax), %rdx
leaq -0x1(%rax), %rcx
testb $0x20, 0x1(%r14,%rdx,2)
jne 0x12d31
movb $0x0, 0x1(%rax)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq