LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/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 0xe3ad(%rip), %rsi      # 0x1623d
leaq 0xd737(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x7ec0
movq 0xc8(%rbx), %rdx
movl 0x20(%rbx), %ecx
leaq 0xe395(%rip), %rdi      # 0x1624b
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4539
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movq %rcx, %rdx
testq %rcx, %rcx
jne 0x7ed3
movq 0x18(%rbx), %rdx
movq %rax, (%rdx)
testq %rax, %rax
je 0x7edf
movq %rcx, 0x8(%rax)
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 0x7979
movq %rbx, %rdi
xorl %esi, %esi
popq %rbx
jmp 0x7b4f
// File: /workspace/github_c_makefile_star2_O3/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 %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %rcx
movq %rsi, %rdx
movq %rdi, %r14
leaq 0x10(%rsp), %r12
leaq 0x8(%rsp), %rdi
movq %r12, (%rdi)
movl $0x64, %esi
callq 0x75d7
movl %eax, %ebx
testl %eax, %eax
jle 0x7f88
movq 0x8(%rsp), %r15
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%r14)
movl 0xc8(%r14), %eax
andl $0x2, %eax
movq 0xc0(%r14), %rcx
movq 0x10(%rcx), %rcx
movl %ebx, %edx
movq %r14, %rdi
movq %r15, %rsi
callq *0x48(%rcx,%rax,4)
movq 0x8(%rsp), %rdi
cmpq %r12, %rdi
sete %al
testq %rdi, %rdi
sete %cl
orb %al, %cl
jne 0x7fa2
callq 0x3060
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq 0x18(%rdi), %rdi
movq 0x98(%rbx), %rsi
movaps 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x8158
movq %rax, %r14
testq %rax, %rax
je 0x814d
movq %rbx, 0x10(%r14)
movq 0x80(%rbx), %rax
movq %rax, 0x80(%r14)
movq 0xa0(%rbx), %rax
movq %rax, 0xa0(%r14)
movq 0x38(%rbx), %rax
movq %rax, 0x38(%r14)
movq 0xc0(%rbx), %rax
movq %rax, 0xc0(%r14)
testb $0x10, 0xc8(%rbx)
je 0x8106
orb $0x10, 0xc8(%r14)
movq 0x18(%r14), %rdi
movq %r14, %rsi
callq 0x81bd
leaq 0xd5a3(%rip), %rsi      # 0x156bc
leaq 0xd4ae(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x814d
movl 0x20(%r14), %ecx
movl 0xc8(%r14), %r8d
leaq 0xd592(%rip), %rdi      # 0x156d2
movq %rbx, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x4539
movq %r14, %rax
addq $0x48, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/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 %rbx
subq $0x20, %rsp
movaps 0x30(%rsp), %xmm0
movaps 0x40(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x87a5
testq %rax, %rax
je 0x819a
movq %rax, %rbx
movq 0xc0(%rax), %rax
movq 0x10(%rax), %rax
movq %rbx, %rdi
callq *0x60(%rax)
testl %eax, %eax
jne 0x81b4
movq %rbx, %rdi
callq 0x3060
leaq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
testq %rax, %rax
je 0x81b2
leaq 0xe0a6(%rip), %rcx      # 0x16255
movq %rcx, (%rax)
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x20, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/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 0xe0a1(%rip), %rsi      # 0x1626f
leaq 0xd3f9(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x81f7
leaq 0xe091(%rip), %rdi      # 0x1627b
movq %r14, %rsi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x4539
movq %r14, 0x18(%rbx)
movq (%r14), %rax
movq %rax, (%rbx)
movq %rbx, (%r14)
movq $0x0, 0x8(%rbx)
testq %rax, %rax
je 0x8215
movq %rbx, 0x8(%rax)
cmpl $-0x1, 0x20(%rbx)
je 0x8233
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_O3/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 %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %esi, %ebp
movq %rdi, %rbx
movl %esi, 0xc(%rsp)
leaq 0xd46f(%rip), %rsi      # 0x156de
leaq 0xd358(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x8297
leaq 0xd461(%rip), %rdi      # 0x156ec
movq %rbx, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x4539
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x82bd
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x82bd
movq 0x58(%rbx), %rdx
movq %rbx, %rdi
movl %ebp, %ecx
movl $0x4, %r8d
callq 0x82fd
testl %ebp, %ebp
js 0x82d9
leaq 0x58(%rbx), %r14
movl %ebp, %esi
movq %r14, %rdi
callq 0x6af6
movq %r14, %rdi
callq 0x6952
jmp 0x82e0
orb $0x8, 0xc9(%rbx)
leaq 0xc(%rsp), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x4, %edx
callq 0x7979
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 %r15
pushq %r14
pushq %rbx
pushq %rax
movl %ecx, %r15d
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl %edx, 0x4(%rsp)
leaq 0xdddc(%rip), %rsi      # 0x16281
leaq 0xd122(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x84d0
movl 0x48(%rbx), %ecx
leaq 0xddcc(%rip), %rdi      # 0x16290
movq %rbx, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x4539
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x84f5
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x84f5
movq %rbx, %rdi
movq %r14, %rdx
movl %ebp, %ecx
movl $0x3, %r8d
callq 0x82fd
testb $0x8, 0xc9(%rbx)
jne 0x8531
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
leaq 0x40(%rbx), %rdi
testl %r15d, %r15d
je 0x8577
cmpq $0x0, 0x48(%rbx)
je 0x8584
movslq %ebp, %rdx
movq %r14, %rsi
callq 0x6ae7
movq %r14, %rdi
callq 0x3060
jmp 0x8598
leaq 0xdd49(%rip), %rsi      # 0x16281
leaq 0xd08f(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x8560
leaq 0xdd45(%rip), %rdi      # 0x16299
movq %rbx, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x4539
testl %r15d, %r15d
je 0x85ac
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3060
movslq %ebp, %rdx
movq %r14, %rsi
callq 0x6ae7
jmp 0x8598
callq 0x6934
movq %r14, 0x40(%rbx)
movslq %ebp, %rax
movq %rax, 0x48(%rbx)
movq %rax, 0x50(%rbx)
leaq 0x4(%rsp), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x3, %edx
callq 0x7979
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 0x882d
movl $0xffffffff, 0x20(%rbx) # imm = 0xFFFFFFFF
movq %r15, 0x98(%rbx)
movq %r14, 0x18(%rbx)
callq 0x4aab
cvttsd2si %xmm0, %rax
movq %rax, 0x70(%rbx)
movq 0x18(%r12), %rax
testq %rax, %rax
jne 0x8800
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 0x8841
movq 0x10(%r12), %rax
testq %rax, %rax
je 0x8841
leaq 0xda71(%rip), %rcx      # 0x162af
movq %rcx, (%rax)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 %rbp
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movl %esi, 0x4(%rsp)
leaq 0xcf1c(%rip), %rsi      # 0x1577f
leaq 0xcd64(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x888b
leaq 0xcf11(%rip), %rdi      # 0x15790
movq %rbx, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x4539
movq 0xc8(%rbx), %rax
andq $-0x9, %rax
movq %rax, %rcx
orq $0x800, %rcx            # imm = 0x800
testl %ebp, %ebp
cmoveq %rax, %rcx
movq %rcx, 0xc8(%rbx)
leaq 0x4(%rsp), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x7979
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x8f0f
movslq 0x18(%rdi), %rax
testq %rax, %rax
jle 0x8f0f
leaq 0x620(%rdi), %rsi
cmpl $0x1, 0x10(%rsi)
je 0x8f6b
addq $0x30, %rsi
decq %rax
jne 0x8f00
cmpl $0x3, %edx
jne 0x8f31
callq 0x4aab
leaq 0x10(%rsp), %rcx
movsd %xmm0, (%rcx)
movq %rbx, %rdi
xorl %esi, %esi
movl $0x6, %edx
callq 0x7979
leaq 0xc(%rsp), %rcx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x7979
movq %rbx, %rdi
xorl %esi, %esi
movl $0x5, %edx
xorl %ecx, %ecx
callq 0x7979
movq %rbx, %rdi
movl $0x1, %esi
callq 0x7b4f
addq $0x18, %rsp
popq %rbx
popq %r14
retq
leaq 0x28(%rbx), %r14
leaq 0x2c(%rbx), %rdx
movl $0x4, %ecx
callq 0x12207
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 0x8fa2
// File: /workspace/github_c_makefile_star2_O3/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 0xd348(%rip), %rsi      # 0x16300
leaq 0xc60f(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x900f
cmpl $0x2, %ebp
leaq 0xd346(%rip), %rax      # 0x1631d
leaq 0xc88c(%rip), %r15      # 0x1586a
cmoveq %rax, %r15
movl 0x4(%r14), %edi
callq 0x3140
movzwl 0x2(%r14), %ecx
rolw $0x8, %cx
movzwl %cx, %r8d
leaq 0xd30f(%rip), %rdi      # 0x1630e
movq %rbx, %rsi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4539
orb $0x8, 0xc8(%rbx)
movq 0xc0(%rbx), %rax
movq 0x10(%rax), %rax
movq %rbx, %rdi
cmpl $0x2, %ebp
jne 0x902e
callq *0x40(%rax)
jmp 0x9034
movq %r14, %rsi
callq *0x38(%rax)
movq 0x18(%rbx), %rdi
movq %rbx, %rsi
callq 0x81bd
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 0x12fe2
testq %rax, %rax
je 0x9309
movq %rax, %r14
leaq 0x60(%rsp), %rax
movq 0x10(%rax), %rcx
movq %rcx, 0x30(%rsp)
movups (%rax), %xmm0
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 0xe6dc(%rip), %rsi      # 0x179d7
movq %rbx, %rdx
callq 0x907c
movq %rax, 0x28(%r14)
jmp 0x930b
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x9379
testq %rdx, %rdx
je 0x9379
movq %rdi, %rbx
movl 0x10(%rdi), %ebp
cmpl $-0x1, %ebp
je 0x9379
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_O3/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 $0x28, %rsp
movl %esi, %ebx
testq %rdi, %rdi
je 0x93ab
xorl %eax, %eax
cmpb $0x0, (%rdi)
setne %al
leal 0x2b(,%rax,2), %ebp
jmp 0x93b0
movl $0x2b, %ebp
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x76d5
testq %rax, %rax
je 0x9510
movq %rax, %r15
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq 0x18(%rsp), %r13
movzbl (%r13), %r12d
cmpl $0x2d, %r12d
je 0x93e8
cmpl $0x2b, %r12d
jne 0x9548
incq %r13
movl $0x20, (%rsp)
movq %r13, %rdi
leaq 0xcf25(%rip), %rsi      # 0x16321
leaq 0x10(%rsp), %rdx
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
leaq 0x4(%rsp), %r9
xorl %eax, %eax
leaq 0x14(%rsp), %r10
pushq %r10
leaq 0x8(%rsp), %r10
pushq %r10
callq 0x3420
addq $0x10, %rsp
cmpl $0x5, %eax
je 0x946b
subq $0x8, %rsp
movq %r13, %rdi
leaq 0xcef6(%rip), %rsi      # 0x16332
leaq 0x18(%rsp), %rdx
leaq 0x14(%rsp), %rcx
leaq 0x10(%rsp), %r8
leaq 0xc(%rsp), %r9
xorl %eax, %eax
leaq 0x1c(%rsp), %r10
pushq %r10
callq 0x3420
addq $0x10, %rsp
cmpl $0x4, %eax
jne 0x9548
movl 0x10(%rsp), %eax
cmpl $0xff, %eax
ja 0x9548
movl 0xc(%rsp), %esi
cmpl $0xff, %esi
ja 0x9548
movl 0x8(%rsp), %edx
cmpl $0xff, %edx
ja 0x9548
movl 0x4(%rsp), %edi
cmpl $0xff, %edi
ja 0x9548
movl (%rsp), %r8d
cmpl $0x21, %r8d
jae 0x9548
cmpl $0x0, 0x14(%rsp)
je 0x9548
movsbl %r12b, %r9d
movl %r8d, %ecx
negb %cl
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
shll %cl, %r10d
testl %r8d, %r8d
cmovel %r8d, %r10d
shll $0x10, %esi
shll $0x18, %eax
orl %esi, %eax
shll $0x8, %edx
orl %edi, %edx
orl %eax, %edx
andl %ebx, %r10d
cmpl %r10d, %edx
cmovel %r9d, %ebp
movq %r15, %rdi
leaq 0x18(%rsp), %rsi
xorl %edx, %edx
callq 0x76d5
movq %rax, %r15
testq %rax, %rax
jne 0x93ce
leaq 0xc309(%rip), %rsi      # 0x15820
leaq 0xc0b0(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x953e
leaq 0xc2fd(%rip), %rdi      # 0x15830
movl %ebx, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x4539
xorl %r14d, %r14d
cmpl $0x2b, %ebp
sete %r14b
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 0xc258(%rip), %rsi      # 0x15838
leaq 0xbfe7(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x963e
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 0xbce6(%rip), %xmm0     # 0x15308
cvttsd2si %xmm0, %r8
andq %rsi, %r8
orq %rax, %r8
leaq 0xc211(%rip), %rdi      # 0x15845
movq %rbx, %rsi
xorl %eax, %eax
callq 0x4539
movaps 0x10(%rsp), %xmm0
testb $0x4, 0xc8(%rbx)
je 0x965d
movq 0xb0(%rbx), %rax
testq %rax, %rax
je 0x965d
movsd %xmm0, 0x78(%rax)
movsd 0x8(%rsp), %xmm0
addq $0x20, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x87a5
movq %rax, %r14
testq %rax, %rax
je 0x96e1
cmpl $-0x1, %ebx
je 0x96d5
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 0x81bd
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/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:
testq %rdx, %rdx
setne %al
movl 0x20(%rdi), %ecx
movl %ecx, %r8d
testl %ecx, %ecx
setg %r10b
andb %al, %r10b
xorl %r9d, %r9d
cmpb $0x1, %r10b
jne 0x9753
movq 0x28(%rdi), %r10
xorl %eax, %eax
xorl %r9d, %r9d
cmpq %rdx, (%r10,%r9,8)
je 0x9750
incq %r9
cmpq %r9, %r8
jne 0x9741
retq
incl %r9d
cmpl %r8d, %r9d
jge 0x9774
movslq %ecx, %rcx
movq 0x28(%rdi), %rdx
movslq %r9d, %rdi
movq (%rdx,%rdi,8), %rax
cmpq %rsi, 0x10(%rax)
je 0x974f
incq %rdi
cmpq %rdi, %rcx
jne 0x9762
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O3/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 0x9858
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 0x9873
movl %r15d, 0x24(%rbx)
leaq 0xc042(%rip), %rsi      # 0x15855
leaq 0xbdb4(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0x9868
movl 0x20(%rbx), %r14d
callq 0x30a0
movl (%rax), %r8d
movl 0x24(%rbx), %r9d
leaq 0xc02f(%rip), %rdi      # 0x1586e
movq %rbx, %rsi
movl %r14d, %edx
movl %ebp, %ecx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4539
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 0x9808
cmpl $0x73, %eax
je 0x9808
xorl %r15d, %r15d
cmpl $0x4, %eax
cmovnel %eax, %r15d
jmp 0x9808
// File: /workspace/github_c_makefile_star2_O3/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 0x98e1
testb $0x40, 0xc9(%rbx)
je 0x98ee
leaq 0x4(%rsp), %rcx
movl $0x1, (%rcx)
movl %eax, %edi
movl $0x1, %esi
movl $0x6, %edx
movl $0x4, %r8d
callq 0x3120
jmp 0x98ee
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_O3/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 0x9934
cmpl $-0x1, %eax
je 0x9925
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_O3/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, 0x4(%rsp)
movl $0x1, (%rsp)
movzwl (%rdi), %edi
xorl %edx, %edx
callq 0x3670
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x999f
movl %eax, %ebp
movq %rsp, %rcx
movl %eax, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x4, %r8d
callq 0x3120
testl %eax, %eax
jne 0x9998
movl %ebp, %edi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x34c0
testl %eax, %eax
je 0x99ad
movl %ebp, %edi
callq 0x3280
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r15d
je 0x99c3
movl %ebp, %edi
movl $0x1000, %esi           # imm = 0x1000
callq 0x3440
testl %eax, %eax
jne 0x9998
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
leaq 0x4(%rsp), %rdx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3560
movl %ebp, %r14d
jmp 0x999f
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_socket_if_listen_udp
int mg_socket_if_listen_udp(struct mg_connection *nc,
                            union socket_address *sa) {
  sock_t sock = mg_open_listening_socket(sa, SOCK_DGRAM, 0);
  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 $0x2, %esi
callq 0x9934
cmpl $-0x1, %eax
je 0x9a29
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_O3/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 0x9a79
testb $0x2, 0xc8(%rbx)
je 0x9a6d
cmpq $0x0, 0x10(%rbx)
jne 0x9a72
callq 0x3280
movl $0xffffffff, 0x20(%rbx) # imm = 0xFFFFFFFF
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/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 0xb82f(%rip), %rsi      # 0x15900
leaq 0xb4f6(%rip), %rdx      # 0x155ce
movl $0x4, %edi
callq 0x4447
testl %eax, %eax
je 0xa100
leaq 0xb5ff(%rip), %rdi      # 0x156ec
movq %r14, %rsi
movl %ebx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x4539
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/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 0xa86e
callq 0x30a0
cmpl $0x4, (%rax)
je 0xa84f
movl %r15d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 0xa904
movq %rdx, %rsi
movq %rax, %rdx
callq 0x3150
jmp 0xa90f
movq %rdx, %rsi
movq %rax, %rdx
callq 0x3560
popq %rax
retq
// File: /workspace/github_c_makefile_star2_O3/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 0xa9d8
movq %rsi, %rbx
movq %rdi, %r15
movq %rsi, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x3240
testb $0x1, %bpl
jne 0xa974
testb $0x2, %bpl
je 0xa9d0
movzwl 0x2(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
leaq 0xba94(%rip), %rdx      # 0x163f9
movq %rbx, %rdi
movq %r14, %rsi
xorl %eax, %eax
callq 0x31e0
jmp 0xa9d0
leaq 0x4(%r15), %rsi
leal -0x1(%r14), %ecx
movl $0x2, %edi
movq %rbx, %rdx
callq 0x3040
testq %rax, %rax
je 0xa9e3
testb $0x2, %bpl
je 0xa9d0
movzwl 0x2(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %ebp
movq %rbx, %rdi
callq 0x3180
cltq
leaq (%rbx,%rax), %rdi
incl %eax
cltq
subq %rax, %r14
leaq 0xba0d(%rip), %rdx      # 0x163c9
leaq 0xbe2a(%rip), %rcx      # 0x167ed
movq %r14, %rsi
movl %ebp, %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 0xa9d8
// File: /workspace/github_c_makefile_star2_O3/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 0xaa02
movq 0xc8(%rdi), %rax
andl $0x2, %eax
je 0xaa02
movups 0x28(%rdi), %xmm0
movups %xmm0, (%rdx)
retq
movl 0x20(%rdi), %edi
jmp 0xa8df
// File: /workspace/github_c_makefile_star2_O3/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 $0x258, %rsp            # imm = 0x258
movq %rdx, %rbx
movq %rsi, %r14
movq 0xc0(%rdi), %rax
movq 0x8(%rax), %r15
movl 0xb8(%rdi), %ebp
leaq 0x50(%rsp), %rdx
movq %rsi, %rdi
movl %ebx, %esi
movl $0x200, %ecx            # imm = 0x200
xorl %r8d, %r8d
callq 0x10c3a
leaq 0xaf07(%rip), %rsi      # 0x1595e
leaq 0xab70(%rip), %rdx      # 0x155ce
movl $0x3, %edi
callq 0x4447
testl %eax, %eax
je 0xaa81
leaq 0xaefe(%rip), %rdi      # 0x15971
leaq 0x50(%rsp), %rdx
movl %ebp, %esi
xorl %eax, %eax
callq 0x4539
movq 0x20(%r15), %rdi
xorl %eax, %eax
leaq 0xb(%rsp), %rcx
movb %al, (%rcx)
leaq 0xa(%rsp), %rsi
movb %al, (%rsi)
bswapl %ebp
leaq 0xc(%rsp), %rax
movl %ebp, (%rax)
leaq 0x10(%rsp), %rdx
movq %rcx, (%rdx)
movl $0x1, %ecx
movq %rcx, 0x8(%rdx)
movq %rsi, 0x10(%rdx)
movq %rcx, 0x18(%rdx)
movq %rax, 0x20(%rdx)
movq $0x4, 0x28(%rdx)
movq %r14, 0x30(%rdx)
movq %rbx, 0x38(%rdx)
movl $0x2, %esi
movl $0x4, %ecx
callq 0x10575
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_tun_if_destroy_conn
void mg_tun_if_destroy_conn(struct mg_connection *nc) {
  struct mg_tun_client *client = (struct mg_tun_client *) nc->iface->data;

  if (nc->flags & MG_F_LISTENING) {
    mg_tun_destroy_client(client);
  } else if (client->disp) {
    uint32_t stream_id = (uint32_t)(uintptr_t) nc->mgr_data;
    struct mg_str msg = {NULL, 0};

    LOG(LL_DEBUG, ("closing 0x%x:", (unsigned int) stream_id));
    mg_tun_send_frame(client->disp, stream_id, MG_TUN_DATA_FRAME,
                      MG_TUN_F_END_STREAM, msg);
  }
}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x58, %rsp
movq 0xc0(%rdi), %rax
movq 0x8(%rax), %rbx
testb $0x1, 0xc8(%rdi)
jne 0xac0f
cmpq $0x0, 0x20(%rbx)
je 0xac08
movl 0xb8(%rdi), %ebp
leaq 0xae01(%rip), %rsi      # 0x1598c
leaq 0xaa3c(%rip), %rdx      # 0x155ce
movl $0x3, %edi
callq 0x4447
testl %eax, %eax
je 0xabb0
leaq 0xadfc(%rip), %rdi      # 0x159a3
movl %ebp, %esi
xorl %eax, %eax
callq 0x4539
movq 0x20(%rbx), %rdi
leaq 0xb(%rsp), %rax
movb $0x0, (%rax)
leaq 0xa(%rsp), %rcx
movb $0x1, (%rcx)
bswapl %ebp
leaq 0xc(%rsp), %rsi
movl %ebp, (%rsi)
leaq 0x10(%rsp), %rdx
movq %rax, (%rdx)
movl $0x1, %eax
movq %rax, 0x8(%rdx)
movq %rcx, 0x10(%rdx)
movq %rax, 0x18(%rdx)
movq %rsi, 0x20(%rdx)
movq $0x4, 0x28(%rdx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rdx)
movl $0x2, %esi
movl $0x4, %ecx
callq 0x10575
addq $0x58, %rsp
popq %rbx
popq %rbp
retq
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %rbp
jmp 0xac1d
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_tun_if_find_conn
struct mg_connection *mg_tun_if_find_conn(struct mg_tun_client *client,
                                          uint32_t stream_id) {
  struct mg_connection *nc = NULL;

  for (nc = client->mgr->active_connections; nc != NULL; nc = nc->next) {
    if (nc->iface != client->iface || (nc->flags & MG_F_LISTENING)) {
      continue;
    }
    if (stream_id == (uint32_t)(uintptr_t) nc->mgr_data) {
      return nc;
    }
  }

  if (stream_id > client->last_stream_id) {
    /* create a new connection */
    LOG(LL_DEBUG, ("new stream 0x%x, accepting", (unsigned int) stream_id));
    nc = mg_if_accept_new_conn(client->listener);
    nc->mgr_data = (void *) (uintptr_t) stream_id;
    client->last_stream_id = stream_id;
  } else {
    LOG(LL_DEBUG,
        ("Ignoring stream 0x%x (last_stream_id 0x%x)", (unsigned int) stream_id,
         (unsigned int) client->last_stream_id));
  }

  return nc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq (%rdi), %rax
movq (%rax), %r15
testq %r15, %r15
je 0xacc4
movq 0x8(%r14), %rax
cmpq %rax, 0xc0(%r15)
jne 0xacbc
testb $0x1, 0xc8(%r15)
jne 0xacbc
cmpl %ebx, 0xb8(%r15)
je 0xad33
movq (%r15), %r15
testq %r15, %r15
jne 0xaca0
movl 0x1c(%r14), %ebp
leaq 0xace2(%rip), %rsi      # 0x159b1
leaq 0xa8f8(%rip), %rdx      # 0x155ce
movl $0x3, %edi
callq 0x4447
cmpl %ebx, %ebp
jae 0xad13
testl %eax, %eax
je 0xacf8
leaq 0xacd6(%rip), %rdi      # 0x159c5
movl %ebx, %esi
xorl %eax, %eax
callq 0x4539
movq 0x28(%r14), %rdi
callq 0x8079
movq %rax, %r15
movl %ebx, %eax
movq %rax, 0xb8(%r15)
movl %ebx, 0x1c(%r14)
jmp 0xad33
testl %eax, %eax
je 0xad30
movl 0x1c(%r14), %edx
leaq 0xacbe(%rip), %rdi      # 0x159e0
xorl %r15d, %r15d
movl %ebx, %esi
xorl %eax, %eax
callq 0x4539
jmp 0xad33
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_normalize_uri_path
int mg_normalize_uri_path(const struct mg_str *in, struct mg_str *out) {
  const char *s = in->p, *se = s + in->len;
  char *cp = (char *) out->p, *d;

  if (in->len == 0 || *s != '/') {
    out->len = 0;
    return 0;
  }

  d = cp;

  while (s < se) {
    const char *next = s;
    struct mg_str component;
    parse_uri_component(&next, se, "/", &component);
    if (mg_vcmp(&component, ".") == 0) {
      /* Yum. */
    } else if (mg_vcmp(&component, "..") == 0) {
      /* Backtrack to previous slash. */
      if (d > cp + 1 && *(d - 1) == '/') d--;
      while (d > cp && *(d - 1) != '/') d--;
    } else {
      memmove(d, s, next - s);
      d += next - s;
    }
    s = next;
  }
  if (d == cp) *d++ = '/';

  out->p = cp;
  out->len = d - cp;
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x8(%rdi), %r14
testq %r14, %r14
je 0xb229
movq (%rdi), %rbp
cmpb $0x2f, (%rbp)
jne 0xb229
movq %rsi, 0x20(%rsp)
movq (%rsi), %r8
movq %r8, %r13
testq %r14, %r14
jle 0xb20f
addq %rbp, %r14
xorl %r12d, %r12d
leaq 0x10(%rsp), %rdi
movq %r8, %r13
movq %r8, 0x8(%rsp)
movq %rbp, %r15
movq %rbp, 0x10(%rsp)
xorl %ebp, %ebp
cmpb $0x2f, (%r15,%rbp)
je 0xb15a
leaq (%r15,%rbp), %rax
incq %rax
incq %rbp
cmpq %r14, %rax
jb 0xb13a
movq %rbp, 0x18(%rsp)
addq %r15, %rbp
jmp 0xb165
movq %rbp, 0x18(%rsp)
addq %r15, %rbp
incq %rbp
leaq 0xa8a0(%rip), %rsi      # 0x15a0c
movq %rdi, %rbx
callq 0x6b4a
testl %eax, %eax
je 0xb1a9
movq %rbx, %rdi
leaq 0xa889(%rip), %rsi      # 0x15a0b
callq 0x6b4a
testl %eax, %eax
je 0xb1b3
movq %rbp, %rbx
subq %r15, %rbx
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x3500
addq %rbx, %r12
movq 0x8(%rsp), %r8
jmp 0xb1f8
movq 0x8(%rsp), %r8
movq %rbx, %rdi
jmp 0xb1fd
cmpq $0x2, %r12
jl 0xb1cf
leaq -0x1(%r12), %rax
movq 0x8(%rsp), %r8
cmpb $0x2f, -0x1(%r8,%r12)
cmoveq %rax, %r12
jmp 0xb1d4
movq 0x8(%rsp), %r8
movq %r12, %rax
sarq $0x3f, %r12
andq %rax, %r12
testq %rax, %rax
jle 0xb1f8
leaq -0x1(%rax), %rcx
cmpb $0x2f, -0x1(%r8,%rax)
movq %rcx, %rax
jne 0xb1de
incq %rcx
movq %rcx, %r12
leaq 0x10(%rsp), %rdi
leaq (%r8,%r12), %r13
cmpq %r14, %rbp
jb 0xb130
testq %r12, %r12
jne 0xb217
movb $0x2f, (%r13)
incq %r13
movq 0x20(%rsp), %rsi
movq %r8, (%rsi)
subq %r8, %r13
movl $0x1, %eax
jmp 0xb22e
xorl %r13d, %r13d
xorl %eax, %eax
movq %r13, 0x8(%rsi)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_get_request_len
static int mg_http_get_request_len(const char *s, int buf_len) {
  const unsigned char *buf = (unsigned char *) s;
  int i;

  for (i = 0; i < buf_len; i++) {
    if (!isprint(buf[i]) && buf[i] != '\r' && buf[i] != '\n' && buf[i] < 128) {
      return -1;
    } else if (buf[i] == '\n' && i + 1 < buf_len && buf[i + 1] == '\n') {
      return i + 2;
    } else if (buf[i] == '\n' && i + 2 < buf_len && buf[i + 1] == '\r' &&
               buf[i + 2] == '\n') {
      return i + 3;
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
xorl %ebx, %ebx
testl %esi, %esi
jle 0xb6fa
movl %esi, %ebp
movq %rdi, %r14
callq 0x3660
movq (%rax), %rcx
movl %ebp, %edx
movq %rdx, %rsi
negq %rsi
movl $0x1, %eax
movzbl -0x1(%r14,%rax), %edi
cmpl $0xa, %edi
je 0xb6b0
testb %dil, %dil
js 0xb6b0
cmpb $0xd, %dil
je 0xb6b0
movzwl (%rcx,%rdi,2), %r8d
andl $0x4000, %r8d           # imm = 0x4000
je 0xb6ea
cmpb $0xa, %dil
jne 0xb6d8
cmpq %rdx, %rax
jae 0xb6c2
cmpb $0xa, (%r14,%rax)
je 0xb6f1
leal 0x1(%rax), %edi
cmpl %ebp, %edi
jge 0xb6d8
cmpb $0xd, (%r14,%rax)
jne 0xb6d8
cmpb $0xa, 0x1(%r14,%rax)
je 0xb6f5
leaq (%rsi,%rax), %rdi
incq %rdi
incq %rax
cmpq $0x1, %rdi
jne 0xb68c
jmp 0xb6fa
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0xb6fa
incl %eax
jmp 0xb6f8
addl $0x2, %eax
movl %eax, %ebx
movl %ebx, %eax
popq %rbx
popq %r14
popq %rbp
retq