LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mgr_init_opt
void mg_mgr_init_opt(struct mg_mgr *m, void *user_data,
                     struct mg_mgr_init_opts opts) {
  memset(m, 0, sizeof(*m));
#if MG_ENABLE_BROADCAST
  m->ctl[0] = m->ctl[1] = INVALID_SOCKET;
#endif
  m->user_data = user_data;

#ifdef _WIN32
  {
    WSADATA data;
    WSAStartup(MAKEWORD(2, 2), &data);
  }
#elif defined(__unix__)
  /* Ignore SIGPIPE signal, so if client cancels the request, it
   * won't kill the whole process. */
  signal(SIGPIPE, SIG_IGN);
#endif

#if MG_ENABLE_SSL
  {
    static int init_done;
    if (!init_done) {
      mg_ssl_if_init();
      init_done++;
    }
  }
#endif
  {
    int i;
    if (opts.num_ifaces == 0) {
      opts.num_ifaces = mg_num_ifaces;
      opts.ifaces = mg_ifaces;
    }
    if (opts.main_iface != NULL) {
      opts.ifaces[MG_MAIN_IFACE] = opts.main_iface;
    }
    m->num_ifaces = opts.num_ifaces;
    m->ifaces =
        (struct mg_iface **) MG_MALLOC(sizeof(*m->ifaces) * opts.num_ifaces);
    for (i = 0; i < mg_num_ifaces; i++) {
      m->ifaces[i] = mg_if_create_iface(opts.ifaces[i], m);
      m->ifaces[i]->vtable->init(m->ifaces[i]);
    }
  }
  if (opts.nameserver != NULL) {
    m->nameserver = strdup(opts.nameserver);
  }
  DBG(("=================================="));
  DBG(("init mgr=%p", m));
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
leaq 0x30(%rsp), %r14
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rdi)
movups %xmm0, 0x20(%rdi)
movups %xmm0, (%rdi)
movq $0x0, 0x30(%rdi)
movq $-0x1, 0x10(%rdi)
movq %rsi, 0x18(%rdi)
movl $0x1, %esi
movl $0xd, %edi
callq 0x3390
cmpl $0x0, 0x8(%r14)
jne 0x7d10
movl 0x16663(%rip), %eax     # 0x1e364
movl %eax, 0x8(%r14)
leaq 0x16664(%rip), %rax     # 0x1e370
movq %rax, 0x10(%r14)
movq (%r14), %rax
testq %rax, %rax
je 0x7d1f
movq 0x10(%r14), %rcx
movq %rax, (%rcx)
movslq 0x8(%r14), %rdi
movl %edi, 0x20(%rbx)
shlq $0x3, %rdi
callq 0x33e0
movq %rax, 0x28(%rbx)
cmpl $0x0, 0x1662a(%rip)     # 0x1e364
jle 0x7d8a
movq 0x10(%r14), %r15
xorl %r12d, %r12d
movq (%r15,%r12,8), %r13
movl $0x1, %edi
movl $0x18, %esi
callq 0x3300
movq %rbx, (%rax)
movq $0x0, 0x8(%rax)
movq %r13, 0x10(%rax)
movq 0x28(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x28(%rbx), %rax
movq (%rax,%r12,8), %rdi
movq 0x10(%rdi), %rax
callq *(%rax)
incq %r12
movslq 0x165df(%rip), %rax     # 0x1e364
cmpq %rax, %r12
jl 0x7d43
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0x7d9c
callq 0x35f0
movq %rax, 0x30(%rbx)
leaq 0xd883(%rip), %rsi      # 0x15626
leaq 0xd800(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x7dc6
leaq 0xd877(%rip), %rdi      # 0x15636
xorl %eax, %eax
callq 0x45a0
leaq 0xd859(%rip), %rsi      # 0x15626
leaq 0xd7d6(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x7dfc
leaq 0xd870(%rip), %rdi      # 0x15659
movq %rbx, %rsi
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x45a0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_if_create_iface
struct mg_iface *mg_if_create_iface(const struct mg_iface_vtable *vtable,
                                    struct mg_mgr *mgr) {
  struct mg_iface *iface = (struct mg_iface *) MG_CALLOC(1, sizeof(*iface));
  iface->mgr = mgr;
  iface->data = NULL;
  iface->vtable = vtable;
  return iface;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl $0x1, %edi
movl $0x18, %esi
callq 0x3300
movq %rbx, (%rax)
movq $0x0, 0x8(%rax)
movq %r14, 0x10(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mgr_free
void mg_mgr_free(struct mg_mgr *m) {
  struct mg_connection *conn, *tmp_conn;

  DBG(("%p", m));
  if (m == NULL) return;
  /* Do one last poll, see https://github.com/cesanta/mongoose/issues/286 */
  mg_mgr_poll(m, 0);

#if MG_ENABLE_BROADCAST
  if (m->ctl[0] != INVALID_SOCKET) closesocket(m->ctl[0]);
  if (m->ctl[1] != INVALID_SOCKET) closesocket(m->ctl[1]);
  m->ctl[0] = m->ctl[1] = INVALID_SOCKET;
#endif

  for (conn = m->active_connections; conn != NULL; conn = tmp_conn) {
    tmp_conn = conn->next;
    mg_close_conn(conn);
  }

  {
    int i;
    for (i = 0; i < m->num_ifaces; i++) {
      m->ifaces[i]->vtable->free(m->ifaces[i]);
      MG_FREE(m->ifaces[i]);
    }
    MG_FREE(m->ifaces);
  }

  MG_FREE((char *) m->nameserver);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0xd821(%rip), %rsi      # 0x15665
leaq 0xd75f(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x7e6a
leaq 0xe2ed(%rip), %rdi      # 0x1614d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
testq %rbx, %rbx
je 0x7f01
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7f09
movl 0x10(%rbx), %edi
cmpl $-0x1, %edi
je 0x7e8a
callq 0x3280
movl 0x14(%rbx), %edi
cmpl $-0x1, %edi
je 0x7e97
callq 0x3280
movq $-0x1, 0x10(%rbx)
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x7eb7
movq (%rdi), %r14
callq 0x7f83
movq %r14, %rdi
testq %r14, %r14
jne 0x7ea7
cmpl $0x0, 0x20(%rbx)
jle 0x7ee8
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
movq 0x10(%rdi), %rax
callq *0x8(%rax)
movq 0x28(%rbx), %rax
movq (%rax,%r14,8), %rdi
callq 0x3060
incq %r14
movslq 0x20(%rbx), %rax
cmpq %rax, %r14
jl 0x7ec0
movq 0x28(%rbx), %rdi
callq 0x3060
movq 0x30(%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x3060
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_mgr_poll
time_t mg_mgr_poll(struct mg_mgr *m, int timeout_ms) {
  int i;
  time_t now = 0; /* oh GCC, seriously ? */

  if (m->num_ifaces == 0) {
    LOG(LL_ERROR, ("cannot poll: no interfaces"));
    return 0;
  }

  for (i = 0; i < m->num_ifaces; i++) {
    now = m->ifaces[i]->vtable->poll(m->ifaces[i], timeout_ms);
  }
  return now;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
cmpl $0x0, 0x20(%rdi)
je 0x7f46
movq %rdi, %r14
cmpl $0x0, 0x20(%rdi)
jle 0x7f73
movl %esi, %ebp
xorl %r15d, %r15d
movq 0x28(%r14), %rax
movq (%rax,%r15,8), %rdi
movq 0x10(%rdi), %rax
movl %ebp, %esi
callq *0x20(%rax)
movq %rax, %rbx
incq %r15
movslq 0x20(%r14), %rax
cmpq %rax, %r15
jl 0x7f24
jmp 0x7f75
leaq 0xd724(%rip), %rsi      # 0x15671
leaq 0xd656(%rip), %rdx      # 0x155aa
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x44b4
testl %eax, %eax
je 0x7f75
leaq 0xd715(%rip), %rdi      # 0x1567d
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x45a0
jmp 0x7f75
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_close_conn
void mg_close_conn(struct mg_connection *conn) {
  DBG(("%p %lu %d", conn, conn->flags, conn->sock));
#if MG_ENABLE_SSL
  if (conn->flags & MG_F_SSL_HANDSHAKE_DONE) {
    mg_ssl_if_conn_close_notify(conn);
  }
#endif
  mg_remove_conn(conn);
  conn->iface->vtable->destroy_conn(conn);
  mg_call(conn, NULL, conn->user_data, MG_EV_CLOSE, NULL);
  mg_destroy_conn(conn, 0 /* destroy_if */);
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
leaq 0xe291(%rip), %rsi      # 0x1621f
leaq 0xd615(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x7fbe
movq 0xc8(%rbx), %rdx
movl 0x20(%rbx), %ecx
leaq 0xe279(%rip), %rdi      # 0x1622d
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
movq %rax, %rdx
testq %rax, %rax
jne 0x7fd1
movq 0x18(%rbx), %rdx
movq %rcx, (%rdx)
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x7fe0
movq %rax, 0x8(%rcx)
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
movq 0xc0(%rbx), %rax
movq 0x10(%rax), %rax
movq %rbx, %rdi
callq *0x18(%rax)
movq 0xc0(%rbx), %rax
movq 0x10(%rax), %rax
movq %rbx, %rdi
callq *0x68(%rax)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x5, %edx
xorl %ecx, %ecx
callq 0x7a51
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
jmp 0x7c27
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_vprintf
int mg_vprintf(struct mg_connection *nc, const char *fmt, va_list ap) {
  char mem[MG_VPRINTF_BUFFER_SIZE], *buf = mem;
  int len;

  if ((len = mg_avprintf(&buf, sizeof(mem), fmt, ap)) > 0) {
    mg_send(nc, buf, len);
  }
  if (buf != mem && buf != NULL) {
    MG_FREE(buf); /* LCOV_EXCL_LINE */
  }               /* LCOV_EXCL_LINE */

  return len;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x80, %rsp
movq %rdx, %rcx
movq %rsi, %rdx
movq %rdi, %r14
leaq 0x10(%rsp), %r15
leaq 0x8(%rsp), %rdi
movq %r15, (%rdi)
movl $0x64, %esi
callq 0x76a7
movl %eax, %ebx
testl %eax, %eax
jle 0x8065
movq 0x8(%rsp), %rsi
movq %r14, %rdi
movl %ebx, %edx
callq 0x808e
movq 0x8(%rsp), %rdi
cmpq %r15, %rdi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x807f
callq 0x3060
movl %ebx, %eax
addq $0x80, %rsp
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send
void mg_send(struct mg_connection *nc, const void *buf, int len) {
  nc->last_io_time = (time_t) mg_time();
  if (nc->flags & MG_F_UDP) {
    nc->iface->vtable->udp_send(nc, buf, len);
  } else {
    nc->iface->vtable->tcp_send(nc, buf, len);
  }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
callq 0x4b23
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r15)
movl 0xc8(%r15), %eax
andl $0x2, %eax
movq 0xc0(%r15), %rcx
movq 0x10(%rcx), %rcx
movslq %ebx, %rdx
movq 0x48(%rcx,%rax,4), %rax
movq %r15, %rdi
movq %r14, %rsi
popq %rbx
popq %r14
popq %r15
jmpq *%rax
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_if_accept_new_conn
struct mg_connection *mg_if_accept_new_conn(struct mg_connection *lc) {
  struct mg_add_sock_opts opts;
  struct mg_connection *nc;
  memset(&opts, 0, sizeof(opts));
  nc = mg_create_connection(lc->mgr, lc->handler, opts);
  if (nc == NULL) return NULL;
  nc->listener = lc;
  nc->proto_handler = lc->proto_handler;
  nc->user_data = lc->user_data;
  nc->recv_mbuf_limit = lc->recv_mbuf_limit;
  nc->iface = lc->iface;
  if (lc->flags & MG_F_SSL) nc->flags |= MG_F_SSL;
  mg_add_conn(nc->mgr, nc);
  DBG(("%p %p %d %d", lc, nc, nc->sock, (int) nc->flags));
  return nc;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq 0x18(%rdi), %rdi
movq 0x98(%r14), %rsi
movaps 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x8239
testq %rax, %rax
je 0x822c
movq %rax, %rbx
movq %r14, 0x10(%rax)
movq 0x80(%r14), %rax
movq %rax, 0x80(%rbx)
movq 0xa0(%r14), %rax
movq %rax, 0xa0(%rbx)
movq 0x38(%r14), %rax
movq %rax, 0x38(%rbx)
movq 0xc0(%r14), %rax
movq %rax, 0xc0(%rbx)
testb $0x10, 0xc8(%r14)
je 0x81e4
orb $0x10, 0xc8(%rbx)
movq 0x18(%rbx), %rdi
movq %rbx, %rsi
callq 0x82af
leaq 0xd4a1(%rip), %rsi      # 0x15698
leaq 0xd3ac(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x822e
movl 0x20(%rbx), %ecx
movl 0xc8(%rbx), %r8d
leaq 0xd491(%rip), %rdi      # 0x156ae
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x45a0
jmp 0x822e
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_create_connection
mg_connection *mg_create_connection(
    struct mg_mgr *mgr, mg_event_handler_t callback,
    struct mg_add_sock_opts opts) {
  struct mg_connection *conn = mg_create_connection_base(mgr, callback, opts);

  if (conn != NULL && !conn->iface->vtable->create_conn(conn)) {
    MG_FREE(conn);
    conn = NULL;
  }
  if (conn == NULL) {
    MG_SET_PTRPTR(opts.error_string, "failed to init connection");
  }

  return conn;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
leaq 0x40(%rsp), %r14
movaps (%r14), %xmm0
movaps 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x88ef
testq %rax, %rax
je 0x8281
movq %rax, %rbx
movq 0xc0(%rax), %rax
movq 0x10(%rax), %rax
movq %rbx, %rdi
callq *0x60(%rax)
testl %eax, %eax
jne 0x8283
movq %rbx, %rdi
callq 0x3060
xorl %ebx, %ebx
testq %rbx, %rbx
sete %cl
movq 0x10(%r14), %rax
testq %rax, %rax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x82a4
leaq 0xdf96(%rip), %rcx      # 0x16237
movq %rcx, (%rax)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_add_conn
MG_INTERNAL void mg_add_conn(struct mg_mgr *mgr, struct mg_connection *c) {
  DBG(("%p %p", mgr, c));
  c->mgr = mgr;
  c->next = mgr->active_connections;
  mgr->active_connections = c;
  c->prev = NULL;
  if (c->next != NULL) c->next->prev = c;
  if (c->sock != INVALID_SOCKET) {
    c->iface->vtable->add_conn(c);
  }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
leaq 0xdf91(%rip), %rsi      # 0x16251
leaq 0xd2e3(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x82e9
leaq 0xdf81(%rip), %rdi      # 0x1625d
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x45a0
movq %r14, 0x18(%rbx)
movq (%r14), %rax
movq %rax, (%rbx)
movq %rbx, (%r14)
movq $0x0, 0x8(%rbx)
testq %rax, %rax
je 0x8307
movq %rbx, 0x8(%rax)
cmpl $-0x1, 0x20(%rbx)
je 0x8325
movq 0xc0(%rbx), %rax
movq 0x10(%rax), %rax
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmpq *0x10(%rax)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_if_sent_cb
void mg_if_sent_cb(struct mg_connection *nc, int num_sent) {
  DBG(("%p %d", nc, num_sent));
#if !defined(NO_LIBC) && MG_ENABLE_HEXDUMP
  if (nc->mgr && nc->mgr->hexdump_file != NULL) {
    char *buf = nc->send_mbuf.buf;
    mg_hexdump_connection(nc, nc->mgr->hexdump_file, buf, num_sent, MG_EV_SEND);
  }
#endif
  if (num_sent < 0) {
    nc->flags |= MG_F_CLOSE_IMMEDIATELY;
  } else {
    mbuf_remove(&nc->send_mbuf, num_sent);
    mbuf_trim(&nc->send_mbuf);
  }
  mg_call(nc, NULL, nc->user_data, MG_EV_SEND, &num_sent);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl %esi, 0x4(%rsp)
leaq 0xd35f(%rip), %rsi      # 0x156ba
leaq 0xd248(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x8385
movl 0x4(%rsp), %edx
leaq 0xd34d(%rip), %rdi      # 0x156c8
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x83ad
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x83ad
movq 0x58(%rbx), %rdx
movl 0x4(%rsp), %ecx
movq %rbx, %rdi
movl $0x4, %r8d
callq 0x83f0
movslq 0x4(%rsp), %rsi
testq %rsi, %rsi
js 0x83cd
leaq 0x58(%rbx), %r14
movq %r14, %rdi
callq 0x6bb8
movq %r14, %rdi
callq 0x6a1f
jmp 0x83d4
orb $0x8, 0xc9(%rbx)
leaq 0x4(%rsp), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x7a51
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_recv_common
MG_INTERNAL void mg_recv_common(struct mg_connection *nc, void *buf, int len,
                                int own) {
  DBG(("%p %d %u", nc, len, (unsigned int) nc->recv_mbuf.len));

#if !defined(NO_LIBC) && MG_ENABLE_HEXDUMP
  if (nc->mgr && nc->mgr->hexdump_file != NULL) {
    mg_hexdump_connection(nc, nc->mgr->hexdump_file, buf, len, MG_EV_RECV);
  }
#endif

  if (nc->flags & MG_F_CLOSE_IMMEDIATELY) {
    DBG(("%p discarded %d bytes", nc, len));
    /*
     * This connection will not survive next poll. Do not deliver events,
     * send data to /dev/null without acking.
     */
    if (own) {
      MG_FREE(buf);
    }
    return;
  }
  nc->last_io_time = (time_t) mg_time();
  if (!own) {
    mbuf_append(&nc->recv_mbuf, buf, len);
  } else if (nc->recv_mbuf.len == 0) {
    /* Adopt buf as recv_mbuf's backing store. */
    mbuf_free(&nc->recv_mbuf);
    nc->recv_mbuf.buf = (char *) buf;
    nc->recv_mbuf.size = nc->recv_mbuf.len = len;
  } else {
    mbuf_append(&nc->recv_mbuf, buf, len);
    MG_FREE(buf);
  }
  mg_call(nc, NULL, nc->user_data, MG_EV_RECV, &len);
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %ecx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl %edx, 0xc(%rsp)
leaq 0xdc84(%rip), %rsi      # 0x16263
leaq 0xcfc4(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x860c
movl 0xc(%rsp), %edx
movl 0x48(%rbx), %ecx
leaq 0xdc70(%rip), %rdi      # 0x16272
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x8633
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x8633
movl 0xc(%rsp), %ecx
movq %rbx, %rdi
movq %r14, %rdx
movl $0x3, %r8d
callq 0x83f0
testb $0x8, 0xc9(%rbx)
jne 0x8670
callq 0x4b23
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
leaq 0x40(%rbx), %rdi
testl %ebp, %ebp
je 0x86b5
cmpq $0x0, 0x48(%rbx)
je 0x86c4
movslq 0xc(%rsp), %rdx
movq %r14, %rsi
callq 0x6ba9
movq %r14, %rdi
callq 0x3060
jmp 0x86da
leaq 0xdbec(%rip), %rsi      # 0x16263
leaq 0xcf2c(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x86a1
movl 0xc(%rsp), %edx
leaq 0xdbe4(%rip), %rdi      # 0x1627b
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
testl %ebp, %ebp
je 0x86ee
movq %r14, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
jmp 0x3060
movslq 0xc(%rsp), %rdx
movq %r14, %rsi
callq 0x6ba9
jmp 0x86da
callq 0x6a01
movq %r14, 0x40(%rbx)
movslq 0xc(%rsp), %rax
movq %rax, 0x48(%rbx)
movq %rax, 0x50(%rbx)
leaq 0xc(%rsp), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x7a51
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_create_connection_base
mg_connection *mg_create_connection_base(
    struct mg_mgr *mgr, mg_event_handler_t callback,
    struct mg_add_sock_opts opts) {
  struct mg_connection *conn;

  if ((conn = (struct mg_connection *) MG_CALLOC(1, sizeof(*conn))) != NULL) {
    conn->sock = INVALID_SOCKET;
    conn->handler = callback;
    conn->mgr = mgr;
    conn->last_io_time = (time_t) mg_time();
    conn->iface =
        (opts.iface != NULL ? opts.iface : mgr->ifaces[MG_MAIN_IFACE]);
    conn->flags = opts.flags & _MG_ALLOWED_CONNECT_FLAGS_MASK;
    conn->user_data = opts.user_data;
    /*
     * SIZE_MAX is defined as a long long constant in
     * system headers on some platforms and so it
     * doesn't compile with pedantic ansi flags.
     */
    conn->recv_mbuf_limit = ~0;
  } else {
    MG_SET_PTRPTR(opts.error_string, "failed to create connection");
  }

  return conn;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %r14
leaq 0x30(%rsp), %r12
movl $0x1, %edi
movl $0xd0, %esi
callq 0x3300
movq %rax, %rbx
testq %rax, %rax
je 0x8977
movl $0xffffffff, 0x20(%rbx) # imm = 0xFFFFFFFF
movq %r15, 0x98(%rbx)
movq %r14, 0x18(%rbx)
callq 0x4b23
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movq 0x18(%r12), %rax
testq %rax, %rax
jne 0x894a
movq 0x28(%r14), %rax
movq (%rax), %rax
movq %rax, 0xc0(%rbx)
movl 0x8(%r12), %eax
andl $0x3f05000, %eax        # imm = 0x3F05000
movq %rax, 0xc8(%rbx)
movq (%r12), %rax
movq %rax, 0xa0(%rbx)
movq $-0x1, 0x38(%rbx)
jmp 0x898b
movq 0x10(%r12), %rax
testq %rax, %rax
je 0x898b
leaq 0xd909(%rip), %rcx      # 0x16291
movq %rcx, (%rax)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_if_connect_cb
void mg_if_connect_cb(struct mg_connection *nc, int err) {
  DBG(("%p connect, err=%d", nc, err));
  nc->flags &= ~MG_F_CONNECTING;
  if (err != 0) {
    nc->flags |= MG_F_CLOSE_IMMEDIATELY;
  }
  mg_call(nc, NULL, nc->user_data, MG_EV_CONNECT, &err);
}

// Assembly:
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movl %esi, 0xc(%rsp)
leaq 0xcdae(%rip), %rsi      # 0x1575b
leaq 0xcbf6(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x89d7
movl 0xc(%rsp), %edx
leaq 0xcd9f(%rip), %rdi      # 0x1576c
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
movq 0xc8(%rbx), %rax
andq $-0x9, %rax
movq %rax, 0xc8(%rbx)
cmpl $0x0, 0xc(%rsp)
je 0x89fd
orq $0x800, %rax            # imm = 0x800
movq %rax, 0xc8(%rbx)
leaq 0xc(%rsp), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x7a51
addq $0x10, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: resolve_cb
static void resolve_cb(struct mg_dns_message *msg, void *data,
                       enum mg_resolve_err e) {
  struct mg_connection *nc = (struct mg_connection *) data;
  int i;
  int failure = -1;

  nc->flags &= ~MG_F_RESOLVING;
  if (msg != NULL) {
    /*
     * Take the first DNS A answer and run...
     */
    for (i = 0; i < msg->num_answers; i++) {
      if (msg->answers[i].rtype == MG_DNS_A_RECORD) {
        /*
         * Async resolver guarantees that there is at least one answer.
         * TODO(lsm): handle IPv6 answers too
         */
        mg_dns_parse_record_data(msg, &msg->answers[i], &nc->sa.sin.sin_addr,
                                 4);
        mg_do_connect(nc, nc->flags & MG_F_UDP ? SOCK_DGRAM : SOCK_STREAM,
                      &nc->sa);
        return;
      }
    }
  }

  if (e == MG_RESOLVE_TIMEOUT) {
    double now = mg_time();
    mg_call(nc, NULL, nc->user_data, MG_EV_TIMER, &now);
  }

  /*
   * If we get there was no MG_DNS_A_RECORD in the answer
   */
  mg_call(nc, NULL, nc->user_data, MG_EV_CONNECT, &failure);
  mg_call(nc, NULL, nc->user_data, MG_EV_CLOSE, NULL);
  mg_destroy_conn(nc, 1 /* destroy_if */);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
andb $-0x5, 0xc8(%rsi)
testq %rdi, %rdi
je 0x9050
movslq 0x18(%rdi), %rax
testq %rax, %rax
jle 0x9050
leaq 0x620(%rdi), %rsi
cmpl $0x1, 0x10(%rsi)
je 0x90ac
addq $0x30, %rsi
decq %rax
jne 0x9041
cmpl $0x3, %edx
jne 0x9072
callq 0x4b23
leaq 0x10(%rsp), %rcx
movsd %xmm0, (%rcx)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x6, %edx
callq 0x7a51
leaq 0xc(%rsp), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x7a51
movq %rbx, %rdi
xorl %esi, %esi
movl $0x5, %edx
xorl %ecx, %ecx
callq 0x7a51
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7c27
addq $0x18, %rsp
popq %rbx
popq %r14
retq
leaq 0x28(%rbx), %r14
leaq 0x2c(%rbx), %rdx
movl $0x4, %ecx
callq 0x11d1a
movq 0xc8(%rbx), %rax
andl $0x2, %eax
cmpq $0x1, %rax
movl $0x2, %esi
sbbl $0x0, %esi
movq %rbx, %rdi
movq %r14, %rdx
addq $0x18, %rsp
popq %rbx
popq %r14
jmp 0x90e3
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_do_connect
mg_connection *mg_do_connect(struct mg_connection *nc,
                                                int proto,
                                                union socket_address *sa) {
  DBG(("%p %s://%s:%hu", nc, proto == SOCK_DGRAM ? "udp" : "tcp",
       inet_ntoa(sa->sin.sin_addr), ntohs(sa->sin.sin_port)));

  nc->flags |= MG_F_CONNECTING;
  if (proto == SOCK_DGRAM) {
    nc->iface->vtable->connect_udp(nc);
  } else {
    nc->iface->vtable->connect_tcp(nc, sa);
  }
  mg_add_conn(nc->mgr, nc);
  return nc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
leaq 0xd1e9(%rip), %rsi      # 0x162e2
leaq 0xc4aa(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9150
cmpl $0x2, %ebp
leaq 0xd1e7(%rip), %rax      # 0x162ff
leaq 0xc727(%rip), %r15      # 0x15846
cmoveq %rax, %r15
movl 0x4(%r14), %edi
callq 0x3140
movzwl 0x2(%r14), %ecx
rolw $0x8, %cx
movzwl %cx, %r8d
leaq 0xd1b0(%rip), %rdi      # 0x162f0
movq %rbx, %rsi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x45a0
orb $0x8, 0xc8(%rbx)
movq 0xc0(%rbx), %rax
movq 0x10(%rax), %rax
movq %rbx, %rdi
cmpl $0x2, %ebp
jne 0x916f
callq *0x40(%rax)
jmp 0x9175
movq %r14, %rsi
callq *0x38(%rax)
movq 0x18(%rbx), %rdi
movq %rbx, %rsi
callq 0x82af
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_tun_bind_opt
struct mg_connection *mg_tun_bind_opt(struct mg_mgr *mgr,
                                      const char *dispatcher,
                                      MG_CB(mg_event_handler_t handler,
                                            void *user_data),
                                      struct mg_bind_opts opts) {
#if MG_ENABLE_SSL
  struct mg_tun_ssl_opts ssl = {opts.ssl_cert, opts.ssl_key, opts.ssl_ca_cert};
#else
  struct mg_tun_ssl_opts ssl = {0};
#endif
  struct mg_tun_client *client = mg_tun_create_client(mgr, dispatcher, ssl);
  if (client == NULL) {
    return NULL;
  }
#if MG_ENABLE_SSL
  /* these options don't make sense in the local mouth of the tunnel */
  opts.ssl_cert = NULL;
  opts.ssl_key = NULL;
  opts.ssl_ca_cert = NULL;
#endif
  return mg_tun_do_bind(client, MG_CB(handler, user_data), opts);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x48, %rsp
movq %rdx, %rbx
callq 0x12afb
testq %rax, %rax
je 0x944d
movq %rax, %r14
leaq 0x60(%rsp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq 0x8(%r14), %rax
movq %rax, 0x38(%rsp)
movq (%r14), %rdi
movaps 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0xe57a(%rip), %rsi      # 0x179b9
movq %rbx, %rdx
callq 0x91bd
movq %rax, 0x28(%r14)
jmp 0x944f
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_broadcast
void mg_broadcast(struct mg_mgr *mgr, mg_event_handler_t cb, void *data,
                  size_t len) {
  struct ctl_msg ctl_msg;

  /*
   * Mongoose manager has a socketpair, `struct mg_mgr::ctl`,
   * where `mg_broadcast()` pushes the message.
   * `mg_mgr_poll()` wakes up, reads a message from the socket pair, and calls
   * specified callback for each connection. Thus the callback function executes
   * in event manager thread.
   */
  if (mgr->ctl[0] != INVALID_SOCKET && data != NULL &&
      len < sizeof(ctl_msg.message)) {
    size_t dummy;

    ctl_msg.callback = cb;
    memcpy(ctl_msg.message, data, len);
    dummy = MG_SEND_FUNC(mgr->ctl[0], (char *) &ctl_msg,
                         offsetof(struct ctl_msg, message) + len, 0);
    dummy = MG_RECV_FUNC(mgr->ctl[0], (char *) &len, 1, 0);
    (void) dummy; /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25509 */
  }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x2010, %rsp           # imm = 0x2010
movq %rcx, (%rsp)
cmpq $0x1fff, %rcx           # imm = 0x1FFF
ja 0x94bd
testq %rdx, %rdx
je 0x94bd
movq %rdi, %rbx
movl 0x10(%rdi), %ebp
cmpl $-0x1, %ebp
je 0x94bd
movq %rcx, %r14
leaq 0x10(%rsp), %rdi
movq %rsi, -0x8(%rdi)
movq %rdx, %rsi
movq %rcx, %rdx
callq 0x3380
addq $0x8, %r14
leaq 0x8(%rsp), %rsi
movl %ebp, %edi
movq %r14, %rdx
xorl %ecx, %ecx
callq 0x31c0
movl 0x10(%rbx), %edi
movq %rsp, %rsi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x3070
addq $0x2010, %rsp           # imm = 0x2010
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_check_ip_acl
int mg_check_ip_acl(const char *acl, uint32_t remote_ip) {
  int allowed, flag;
  uint32_t net, mask;
  struct mg_str vec;

  /* If any ACL is set, deny by default */
  allowed = (acl == NULL || *acl == '\0') ? '+' : '-';

  while ((acl = mg_next_comma_list_entry(acl, &vec, NULL)) != NULL) {
    flag = vec.p[0];
    if ((flag != '+' && flag != '-') ||
        parse_net(&vec.p[1], &net, &mask) == 0) {
      return -1;
    }

    if (net == (remote_ip & mask)) {
      allowed = flag;
    }
  }

  DBG(("%08x %c", (unsigned int) remote_ip, allowed));
  return allowed == '+';
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, 0xc(%rsp)
testq %rdi, %rdi
je 0x94f1
xorl %eax, %eax
cmpb $0x0, (%rdi)
setne %al
leal 0x2b(,%rax,2), %ebp
jmp 0x94f6
movl $0x2b, %ebp
leaq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x77ad
testq %rax, %rax
je 0x964d
movq %rax, %r15
movq 0x28(%rsp), %r14
movzbl (%r14), %ebx
cmpl $0x2d, %ebx
je 0x9525
cmpl $0x2b, %ebx
jne 0x9687
incq %r14
movl $0x20, 0x10(%rsp)
movq %r14, %rdi
leaq 0xcdc9(%rip), %rsi      # 0x16303
leaq 0x20(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
leaq 0x18(%rsp), %r8
leaq 0x14(%rsp), %r9
xorl %eax, %eax
leaq 0x24(%rsp), %r10
pushq %r10
leaq 0x18(%rsp), %r10
pushq %r10
callq 0x3420
addq $0x10, %rsp
cmpl $0x5, %eax
je 0x95a7
subq $0x8, %rsp
movq %r14, %rdi
leaq 0xcd9a(%rip), %rsi      # 0x16314
leaq 0x28(%rsp), %rdx
leaq 0x24(%rsp), %rcx
leaq 0x20(%rsp), %r8
leaq 0x1c(%rsp), %r9
xorl %eax, %eax
leaq 0x2c(%rsp), %r10
pushq %r10
callq 0x3420
addq $0x10, %rsp
movb $0x1, %cl
cmpl $0x4, %eax
jne 0x961e
movl 0x20(%rsp), %edi
movb $0x1, %cl
cmpl $0xff, %edi
ja 0x961e
movl 0x1c(%rsp), %edx
cmpl $0xff, %edx
ja 0x961e
movl 0x18(%rsp), %eax
cmpl $0xff, %eax
ja 0x961e
movl 0x14(%rsp), %r8d
cmpl $0x100, %r8d            # imm = 0x100
setb %r9b
movl 0x10(%rsp), %esi
cmpl $0x21, %esi
setb %r10b
andb %r9b, %r10b
cmpb $0x1, %r10b
jne 0x961e
shll $0x18, %edi
shll $0x10, %edx
orl %edi, %edx
shll $0x8, %eax
orl %r8d, %eax
movl %esi, %ecx
negb %cl
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
shll %cl, %r12d
orl %edx, %eax
testl %esi, %esi
cmovel %esi, %r12d
cmpl $0x0, 0x24(%rsp)
sete %cl
movl %eax, %r13d
testb %cl, %cl
jne 0x9687
movsbl %bl, %eax
movl %r12d, %ecx
andl 0xc(%rsp), %ecx
cmpl %ecx, %r13d
cmovel %eax, %ebp
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x77ad
movq %rax, %r15
testq %rax, %rax
jne 0x950e
leaq 0xc1a8(%rip), %rsi      # 0x157fc
leaq 0xbf4f(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x967d
leaq 0xc19c(%rip), %rdi      # 0x1580c
movl 0xc(%rsp), %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x45a0
xorl %eax, %eax
cmpl $0x2b, %ebp
sete %al
jmp 0x968c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_set_timer
double mg_set_timer(struct mg_connection *c, double timestamp) {
  double result = c->ev_timer_time;
  c->ev_timer_time = timestamp;
  /*
   * If this connection is resolving, it's not in the list of active
   * connections, so not processed yet. It has a DNS resolver connection
   * linked to it. Set up a timer for the DNS connection.
   */
  DBG(("%p %p %d -> %lu", c, c->priv_2, (c->flags & MG_F_RESOLVING ? 1 : 0),
       (unsigned long) timestamp));
  if ((c->flags & MG_F_RESOLVING) && c->priv_2 != NULL) {
    ((struct mg_connection *) c->priv_2)->ev_timer_time = timestamp;
  }
  return result;
}

// Assembly:
pushq %rbx
subq $0x20, %rsp
movaps %xmm0, %xmm1
movq %rdi, %rbx
movsd 0x78(%rdi), %xmm0
movsd %xmm0, 0x8(%rsp)
movaps %xmm1, 0x10(%rsp)
movsd %xmm1, 0x78(%rdi)
leaq 0xc122(%rip), %rsi      # 0x15814
leaq 0xbeb1(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9750
movq 0xb0(%rbx), %rdx
movl 0xc8(%rbx), %ecx
shrl $0x2, %ecx
andl $0x1, %ecx
movapd 0x10(%rsp), %xmm0
cvttsd2si %xmm0, %rax
movq %rax, %rsi
sarq $0x3f, %rsi
subsd 0xbbd4(%rip), %xmm0     # 0x15308
cvttsd2si %xmm0, %r8
andq %rsi, %r8
orq %rax, %r8
leaq 0xc0db(%rip), %rdi      # 0x15821
movq %rbx, %rsi
xorl %eax, %eax
callq 0x45a0
movaps 0x10(%rsp), %xmm0
testb $0x4, 0xc8(%rbx)
je 0x976f
movq 0xb0(%rbx), %rax
testq %rax, %rax
je 0x976f
movsd %xmm0, 0x78(%rax)
movsd 0x8(%rsp), %xmm0
addq $0x20, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_add_sock_opt
struct mg_connection *mg_add_sock_opt(struct mg_mgr *s, sock_t sock,
                                      MG_CB(mg_event_handler_t callback,
                                            void *user_data),
                                      struct mg_add_sock_opts opts) {
#if MG_ENABLE_CALLBACK_USERDATA
  opts.user_data = user_data;
#endif

  struct mg_connection *nc = mg_create_connection_base(s, callback, opts);
  if (nc != NULL) {
    mg_sock_set(nc, sock);
    mg_add_conn(nc->mgr, nc);
  }
  return nc;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
movl %esi, %ebx
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rdx, %rsi
callq 0x88ef
movq %rax, %r14
testq %rax, %rax
je 0x97f3
cmpl $-0x1, %ebx
je 0x97e7
movq 0xc0(%r14), %rax
movq 0x10(%rax), %rax
movq %r14, %rdi
movl %ebx, %esi
callq *0x70(%rax)
movq 0x18(%r14), %rdi
movq %r14, %rsi
callq 0x82af
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_find_iface
struct mg_iface *mg_find_iface(struct mg_mgr *mgr,
                               const struct mg_iface_vtable *vtable,
                               struct mg_iface *from) {
  int i = 0;
  if (from != NULL) {
    for (i = 0; i < mgr->num_ifaces; i++) {
      if (mgr->ifaces[i] == from) {
        i++;
        break;
      }
    }
  }

  for (; i < mgr->num_ifaces; i++) {
    if (mgr->ifaces[i]->vtable == vtable) {
      return mgr->ifaces[i];
    }
  }
  return NULL;
}

// Assembly:
xorl %eax, %eax
testq %rdx, %rdx
je 0x9854
movl 0x20(%rdi), %ecx
testl %ecx, %ecx
jle 0x9854
movq 0x28(%rdi), %r8
xorl %eax, %eax
cmpq %rdx, (%r8,%rax,8)
je 0x9852
incq %rax
cmpq %rax, %rcx
jne 0x9840
movl %ecx, %eax
jmp 0x9854
incl %eax
movslq 0x20(%rdi), %rcx
cmpl %ecx, %eax
jge 0x9875
movq 0x28(%rdi), %rdx
movslq %eax, %rdi
movq (%rdx,%rdi,8), %rax
cmpq %rsi, 0x10(%rax)
je 0x9877
incq %rdi
cmpq %rdi, %rcx
jne 0x9863
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_socket_if_connect_tcp
void mg_socket_if_connect_tcp(struct mg_connection *nc,
                              const union socket_address *sa) {
  int rc, proto = 0;
  nc->sock = socket(AF_INET, SOCK_STREAM, proto);
  if (nc->sock == INVALID_SOCKET) {
    nc->err = mg_get_errno() ? mg_get_errno() : 1;
    return;
  }
#if !defined(MG_ESP8266)
  mg_set_non_blocking_mode(nc->sock);
#endif
  rc = connect(nc->sock, &sa->sa, sizeof(sa->sin));
  nc->err = rc < 0 && mg_is_error() ? mg_get_errno() : 0;
  DBG(("%p sock %d rc %d errno %d err %d", nc, nc->sock, rc, mg_get_errno(),
       nc->err));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
xorl %r15d, %r15d
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x3670
movl %eax, 0x20(%rbx)
cmpl $-0x1, %eax
je 0x9959
movl %eax, %ebp
movl %eax, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x34f0
orl $0x800, %eax            # imm = 0x800
movl %ebp, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x34f0
movl 0x20(%rbx), %edi
movq %r14, %rsi
movl $0x10, %edx
callq 0x35c0
movl %eax, %ebp
testl %eax, %eax
js 0x9974
movl %r15d, 0x24(%rbx)
leaq 0xbf1d(%rip), %rsi      # 0x15831
leaq 0xbc8f(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0x9969
movl 0x20(%rbx), %r14d
callq 0x30a0
movl (%rax), %r8d
movl 0x24(%rbx), %r9d
leaq 0xbf0a(%rip), %rdi      # 0x1584a
movq %rbx, %rsi
movl %r14d, %edx
movl %ebp, %ecx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x45a0
callq 0x30a0
movl (%rax), %eax
cmpl $0x1, %eax
adcl $0x0, %eax
movl %eax, 0x24(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x30a0
movl (%rax), %eax
cmpl $0xb, %eax
je 0x9909
cmpl $0x73, %eax
je 0x9909
xorl %r15d, %r15d
cmpl $0x4, %eax
cmovnel %eax, %r15d
jmp 0x9909
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_socket_if_connect_udp
void mg_socket_if_connect_udp(struct mg_connection *nc) {
  nc->sock = socket(AF_INET, SOCK_DGRAM, 0);
  if (nc->sock == INVALID_SOCKET) {
    nc->err = mg_get_errno() ? mg_get_errno() : 1;
    return;
  }
  if (nc->flags & MG_F_ENABLE_BROADCAST) {
    int optval = 1;
    setsockopt(nc->sock, SOL_SOCKET, SO_BROADCAST, (const char *) &optval,
               sizeof(optval));
  }
  nc->err = 0;
}

// Assembly:
pushq %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %ebp, %ebp
movl $0x2, %edi
movl $0x2, %esi
xorl %edx, %edx
callq 0x3670
movl %eax, 0x20(%rbx)
cmpl $-0x1, %eax
je 0x99e2
testb $0x40, 0xc9(%rbx)
je 0x99ef
leaq 0x4(%rsp), %rcx
movl $0x1, (%rcx)
movl %eax, %edi
movl $0x1, %esi
movl $0x6, %edx
movl $0x4, %r8d
callq 0x3120
jmp 0x99ef
callq 0x30a0
movl (%rax), %ebp
cmpl $0x1, %ebp
adcl $0x0, %ebp
movl %ebp, 0x24(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_socket_if_listen_tcp
int mg_socket_if_listen_tcp(struct mg_connection *nc,
                            union socket_address *sa) {
  int proto = 0;
  sock_t sock = mg_open_listening_socket(sa, SOCK_STREAM, proto);
  if (sock == INVALID_SOCKET) {
    return (mg_get_errno() ? mg_get_errno() : 1);
  }
  mg_sock_set(nc, sock);
  return 0;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq %rsi, %rdi
movl $0x1, %esi
callq 0x9a35
cmpl $-0x1, %eax
je 0x9a26
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq %rbx, %rdi
movl %eax, %esi
callq *0x70(%rcx)
xorl %eax, %eax
popq %rbx
retq
callq 0x30a0
movl (%rax), %eax
cmpl $0x1, %eax
adcl $0x0, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_open_listening_socket
static sock_t mg_open_listening_socket(struct mg_connection *nc,
                                       union socket_address *sa, int type,
                                       int proto) {
  int r;
  socklen_t sa_len =
      (sa->sa.sa_family == AF_INET) ? sizeof(sa->sin) : sizeof(sa->sin6);
  sock_t sock = sl_Socket(sa->sa.sa_family, type, proto);
  if (sock < 0) return sock;
  if ((r = sl_Bind(sock, &sa->sa, sa_len)) < 0) goto clean;
  if (type != SOCK_DGRAM) {
#if MG_ENABLE_SSL
    if ((r = sl_set_ssl_opts(sock, nc)) < 0) goto clean;
#endif
    if ((r = sl_Listen(sock, SOMAXCONN)) < 0) goto clean;
  }
  mg_set_non_blocking_mode(sock);
clean:
  if (r < 0) {
    sl_Close(sock);
    sock = r;
  }
  return sock;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %r15d
movq %rdi, %rbx
movl $0x10, (%rsp)
movl $0x1, 0x4(%rsp)
movzwl (%rdi), %edi
xorl %edx, %edx
callq 0x3670
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x9aa0
movl %eax, %ebp
leaq 0x4(%rsp), %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x3120
testl %eax, %eax
jne 0x9a99
movl (%rsp), %edx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x34c0
testl %eax, %eax
je 0x9aae
movl %ebp, %edi
callq 0x3280
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r15d
je 0x9ac4
movl %ebp, %edi
movl $0x1000, %esi           # imm = 0x1000
callq 0x3440
testl %eax, %eax
jne 0x9a99
movl %ebp, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x34f0
orl $0x800, %eax            # imm = 0x800
movl %ebp, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x34f0
movq %rsp, %rdx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3560
movl %ebp, %r14d
jmp 0x9aa0
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_socket_if_destroy_conn
void mg_socket_if_destroy_conn(struct mg_connection *nc) {
  if (nc->sock == INVALID_SOCKET) return;
  if (!(nc->flags & MG_F_UDP)) {
    closesocket(nc->sock);
  } else {
    /* Only close outgoing UDP sockets or listeners. */
    if (nc->listener == NULL) closesocket(nc->sock);
  }
  nc->sock = INVALID_SOCKET;
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movl 0x20(%rdi), %edi
cmpl $-0x1, %edi
je 0x9b78
testb $0x2, 0xc8(%rbx)
je 0x9b6c
cmpq $0x0, 0x10(%rbx)
jne 0x9b71
callq 0x3280
movl $0xffffffff, 0x20(%rbx) # imm = 0xFFFFFFFF
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_socket_if_sock_set
void mg_socket_if_sock_set(struct mg_connection *nc, sock_t sock) {
  mg_set_non_blocking_mode(sock);
  mg_set_close_on_exec(sock);
  nc->sock = sock;
  DBG(("%p %d", nc, sock));
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movl %esi, %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x34f0
orl $0x800, %eax            # imm = 0x800
movl %ebx, %edi
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x34f0
movl %ebx, %edi
movl $0x2, %esi
movl $0x1, %edx
xorl %eax, %eax
callq 0x34f0
movl %ebx, 0x20(%r14)
leaq 0xb75b(%rip), %rsi      # 0x158dc
leaq 0xb422(%rip), %rdx      # 0x155aa
movl $0x4, %edi
callq 0x44b4
testl %eax, %eax
je 0xa1b0
leaq 0xb52b(%rip), %rdi      # 0x156c8
movq %r14, %rsi
movl %ebx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x45a0
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_add_to_set
void mg_add_to_set(sock_t sock, fd_set *set, sock_t *max_fd) {
  if (sock != INVALID_SOCKET
#ifdef __unix__
      && sock < (sock_t) FD_SETSIZE
#endif
      ) {
    FD_SET(sock, set);
    if (*max_fd == INVALID_SOCKET || sock > *max_fd) {
      *max_fd = sock;
    }
  }
}

// Assembly:
cmpl $-0x1, %edi
sete %al
cmpl $0x400, %edi            # imm = 0x400
setge %cl
orb %al, %cl
jne 0xa417
leal 0x3f(%rdi), %eax
testl %edi, %edi
cmovnsl %edi, %eax
movl %eax, %r8d
andl $-0x40, %r8d
movl %edi, %ecx
subl %r8d, %ecx
movl $0x1, %r8d
shlq %cl, %r8
sarl $0x6, %eax
cltq
orq %r8, (%rsi,%rax,8)
movl (%rdx), %eax
cmpl $-0x1, %eax
setne %cl
cmpl %edi, %eax
setge %al
testb %al, %cl
jne 0xa417
movl %edi, (%rdx)
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_socketpair_accept
MG_INTERNAL sock_t
mg_socketpair_accept(sock_t sock, union socket_address *sa, socklen_t sa_len) {
  sock_t rc;
  while (1) {
    if ((rc = accept(sock, &sa->sa, &sa_len)) == INVALID_SOCKET &&
        errno == EINTR)
      continue;
    break;
  }
  return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x4(%rsp), %r14
movl %edx, (%r14)
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3550
movl %eax, %r15d
cmpl $-0x1, %eax
jne 0xa9b3
callq 0x30a0
cmpl $0x4, (%rax)
je 0xa994
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_sock_get_addr
static void mg_sock_get_addr(sock_t sock, int remote,
                             union socket_address *sa) {
  socklen_t slen = sizeof(*sa);
  memset(sa, 0, slen);
  if (remote) {
    getpeername(sock, &sa->sa, &slen);
  } else {
    getsockname(sock, &sa->sa, &slen);
  }
}

// Assembly:
pushq %rax
movl $0x10, 0x4(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdx)
leaq 0x4(%rsp), %rax
testl %esi, %esi
je 0xaa49
movq %rdx, %rsi
movq %rax, %rdx
callq 0x3150
jmp 0xaa54
movq %rdx, %rsi
movq %rax, %rdx
callq 0x3560
popq %rax
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_sock_addr_to_str
int mg_sock_addr_to_str(const union socket_address *sa, char *buf, size_t len,
                        int flags) {
  int is_v6;
  if (buf == NULL || len <= 0) return 0;
  memset(buf, 0, len);
#if MG_ENABLE_IPV6
  is_v6 = sa->sa.sa_family == AF_INET6;
#else
  is_v6 = 0;
#endif
  if (flags & MG_SOCK_STRINGIFY_IP) {
#if MG_ENABLE_IPV6
    const void *addr = NULL;
    char *start = buf;
    socklen_t capacity = len;
    if (!is_v6) {
      addr = &sa->sin.sin_addr;
    } else {
      addr = (void *) &sa->sin6.sin6_addr;
      if (flags & MG_SOCK_STRINGIFY_PORT) {
        *buf = '[';
        start++;
        capacity--;
      }
    }
    if (inet_ntop(sa->sa.sa_family, addr, start, capacity) == NULL) {
      goto cleanup;
    }
#elif defined(_WIN32) || MG_LWIP || (MG_NET_IF == MG_NET_IF_PIC32)
    /* Only Windoze Vista (and newer) have inet_ntop() */
    char *addr_str = inet_ntoa(sa->sin.sin_addr);
    if (addr_str != NULL) {
      strncpy(buf, inet_ntoa(sa->sin.sin_addr), len - 1);
    } else {
      goto cleanup;
    }
#else
    if (inet_ntop(AF_INET, (void *) &sa->sin.sin_addr, buf, len - 1) == NULL) {
      goto cleanup;
    }
#endif
  }
  if (flags & MG_SOCK_STRINGIFY_PORT) {
    int port = ntohs(sa->sin.sin_port);
    if (flags & MG_SOCK_STRINGIFY_IP) {
      int buf_len = strlen(buf);
      snprintf(buf + buf_len, len - (buf_len + 1), "%s:%d", (is_v6 ? "]" : ""),
               port);
    } else {
      snprintf(buf, len, "%d", port);
    }
  }

  return strlen(buf);

cleanup:
  *buf = '\0';
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %ebp
movq %rdx, %r14
testq %rsi, %rsi
sete %cl
testq %rdx, %rdx
sete %dl
xorl %eax, %eax
orb %cl, %dl
jne 0xab15
movq %rsi, %rbx
movq %rdi, %r15
movq %rsi, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x3240
testb $0x1, %bpl
je 0xaaab
leaq 0x4(%r15), %rsi
leal -0x1(%r14), %ecx
movl $0x2, %edi
movq %rbx, %rdx
callq 0x3040
testq %rax, %rax
je 0xab20
testb $0x2, %bpl
je 0xab0d
movzwl 0x2(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %r15d
testb $0x1, %bpl
jne 0xaadd
leaq 0xb910(%rip), %rdx      # 0x163db
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x31e0
jmp 0xab0d
movq %rbx, %rdi
callq 0x3180
cltq
leaq (%rbx,%rax), %rdi
incl %eax
cltq
subq %rax, %r14
leaq 0xb8b2(%rip), %rdx      # 0x163ab
leaq 0xbccf(%rip), %rcx      # 0x167cf
movq %r14, %rsi
movl %r15d, %r8d
xorl %eax, %eax
callq 0x31e0
movq %rbx, %rdi
callq 0x3180
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movb $0x0, (%rbx)
xorl %eax, %eax
jmp 0xab15
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_socket_if_get_conn_addr
void mg_socket_if_get_conn_addr(struct mg_connection *nc, int remote,
                                union socket_address *sa) {
  if ((nc->flags & MG_F_UDP) && remote) {
    memcpy(sa, &nc->sa, sizeof(*sa));
    return;
  }
  mg_sock_get_addr(nc->sock, remote, sa);
}

// Assembly:
testl %esi, %esi
je 0xab3f
movq 0xc8(%rdi), %rax
andl $0x2, %eax
je 0xab3f
movups 0x28(%rdi), %xmm0
movups %xmm0, (%rdx)
retq
movl 0x20(%rdi), %edi
jmp 0xaa24
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_tun_if_tcp_send
void mg_tun_if_tcp_send(struct mg_connection *nc, const void *buf, size_t len) {
  struct mg_tun_client *client = (struct mg_tun_client *) nc->iface->data;
  uint32_t stream_id = (uint32_t)(uintptr_t) nc->mgr_data;
  struct mg_str msg = {(char *) buf, len};
#if MG_ENABLE_HEXDUMP
  char hex[512];
  mg_hexdump(buf, len, hex, sizeof(hex));
  LOG(LL_DEBUG, ("sending to stream 0x%x:\n%s", (unsigned int) stream_id, hex));
#endif

  mg_tun_send_frame(client->disp, stream_id, MG_TUN_DATA_FRAME, 0, msg);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdx, %rbx
movq %rsi, %r14
movq 0xc0(%rdi), %rax
movq 0x8(%rax), %r15
movl 0xb8(%rdi), %ebp
movq %rsp, %rdx
movq %rsi, %rdi
movl %ebx, %esi
movl $0x200, %ecx            # imm = 0x200
xorl %r8d, %r8d
callq 0x10c5e
leaq 0xada8(%rip), %rsi      # 0x1593a
leaq 0xaa11(%rip), %rdx      # 0x155aa
movl $0x3, %edi
callq 0x44b4
testl %eax, %eax
je 0xabba
leaq 0xad9f(%rip), %rdi      # 0x1594d
movq %rsp, %rdx
movl %ebp, %esi
xorl %eax, %eax
callq 0x45a0
movq 0x20(%r15), %rdi
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r14, %r8
movq %rbx, %r9
callq 0xabe5
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O1/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_tun_send_frame
void mg_tun_send_frame(struct mg_connection *ws, uint32_t stream_id,
                       uint8_t type, uint8_t flags, struct mg_str msg) {
  stream_id = htonl(stream_id);
  {
    struct mg_str parts[] = {
        {(char *) &type, sizeof(type)},
        {(char *) &flags, sizeof(flags)},
        {(char *) &stream_id, sizeof(stream_id)},
        {msg.p, msg.len} /* vc6 doesn't like just `msg` here */};
    mg_send_websocket_framev(ws, WEBSOCKET_OP_BINARY, parts,
                             sizeof(parts) / sizeof(parts[0]));
  }
}

// Assembly:
subq $0x58, %rsp
leaq 0xb(%rsp), %rax
movb %dl, (%rax)
leaq 0xa(%rsp), %r10
movb %cl, (%r10)
bswapl %esi
leaq 0xc(%rsp), %rcx
movl %esi, (%rcx)
leaq 0x10(%rsp), %rdx
movq %rax, (%rdx)
movl $0x1, %eax
movq %rax, 0x8(%rdx)
movq %r10, 0x10(%rdx)
movq %rax, 0x18(%rdx)
movq %rcx, 0x20(%rdx)
movq $0x4, 0x28(%rdx)
movq %r8, 0x30(%rdx)
movq %r9, 0x38(%rdx)
movl $0x2, %esi
movl $0x4, %ecx
callq 0x105d4
addq $0x58, %rsp
retq