LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O2/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
orl $-0x1, 0xc(%rsp)
andb $-0x5, 0xc8(%rsi)
testq %rdi, %rdi
je 0x8a1a
movl 0x18(%rdi), %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovgl %ecx, %eax
incq %rax
leaq 0x5f0(%rdi), %rcx
decq %rax
je 0x8a1a
leaq 0x30(%rcx), %rsi
cmpl $0x1, 0x40(%rcx)
movq %rsi, %rcx
jne 0x89d5
leaq 0x28(%rbx), %r14
leaq 0x2c(%rbx), %rdx
pushq $0x4
popq %rcx
callq 0x11065
movq 0xc8(%rbx), %rax
andl $0x2, %eax
cmpq $0x1, %rax
pushq $0x2
popq %rsi
sbbl $0x0, %esi
movq %rbx, %rdi
movq %r14, %rdx
addq $0x18, %rsp
popq %rbx
popq %r14
jmp 0x8a6e
cmpl $0x3, %edx
jne 0x8a3a
callq 0x483c
leaq 0x10(%rsp), %rcx
movsd %xmm0, (%rcx)
pushq $0x6
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x75bd
pushq $0x2
popq %rdx
leaq 0xc(%rsp), %rcx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x75bd
pushq $0x5
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x75bd
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x778b
addq $0x18, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/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 0xc85f(%rip), %rsi      # 0x152e3
leaq 0xbb23(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x8ad9
cmpl $0x2, %ebp
leaq 0xc85f(%rip), %rax      # 0x15300
leaq 0xbda2(%rip), %r15      # 0x1484a
cmoveq %rax, %r15
movl 0x4(%r14), %edi
callq 0x3140
movzwl 0x2(%r14), %ecx
rolw $0x8, %cx
movzwl %cx, %r8d
leaq 0xc828(%rip), %rdi      # 0x152f1
movq %rbx, %rsi
movq %r15, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x430a
orb $0x8, 0xc8(%rbx)
movq 0xc0(%rbx), %rax
movq 0x10(%rax), %rax
movq %rbx, %rdi
cmpl $0x2, %ebp
jne 0x8af8
callq *0x40(%rax)
jmp 0x8afe
movq %r14, %rsi
callq *0x38(%rax)
movq 0x18(%rbx), %rdi
movq %rbx, %rsi
callq 0x7da5
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r12
leaq 0x14aed(%rip), %rsi     # 0x1d840
xorl %edx, %edx
callq 0x91da
testq %rax, %rax
je 0x8de6
movq %rax, %r13
leaq 0x80(%rsp), %rbp
pushq $0x38
popq %rdi
callq 0x33e0
movq %rax, %r14
movq %r12, (%rax)
movq %r13, 0x8(%rax)
movq %r15, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x18(%rax)
movups %xmm0, 0x28(%rax)
movq %rax, 0x8(%r13)
movq %rax, %rdi
xorl %esi, %esi
callq 0x11cb9
movq 0x10(%rbp), %rax
movq %rax, 0x30(%rsp)
movups (%rbp), %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 0xdbe5(%rip), %rsi      # 0x169ba
movq %rbx, %rdx
callq 0x8b46
movq %rax, %rbx
movq %rax, 0x28(%r14)
jmp 0x8e11
leaq 0xdb73(%rip), %rsi      # 0x16960
leaq 0xb7ba(%rip), %rdx      # 0x145ae
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x4227
testl %eax, %eax
je 0x8e11
leaq 0xdb6d(%rip), %rdi      # 0x16975
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x430a
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 0x8e87
testq %rdx, %rdx
je 0x8e87
movq %rdi, %rbx
movl 0x10(%rdi), %ebp
cmpl $-0x1, %ebp
je 0x8e87
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
pushq $0x1
popq %rdx
xorl %ecx, %ecx
callq 0x3070
addq $0x2010, %rsp           # imm = 0x2010
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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)
movq %rdi, %r15
testq %rdi, %rdi
je 0x8ebf
xorl %eax, %eax
cmpb $0x0, (%r15)
setne %al
leal 0x2b(,%rax,2), %ebp
jmp 0x8ec2
pushq $0x2b
popq %rbp
pushq $-0x1
popq %r14
leaq 0x24(%rsp), %r13
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
xorl %edx, %edx
callq 0x7325
testq %rax, %rax
je 0x9001
movq %rax, %r15
movq 0x28(%rsp), %r12
movzbl (%r12), %ebx
cmpl $0x2d, %ebx
je 0x8efe
cmpl $0x2b, %ebx
jne 0x9039
incq %r12
movl $0x20, 0x10(%rsp)
movq %r12, %rdi
leaq 0xc3f1(%rip), %rsi      # 0x15304
leaq 0x1c(%rsp), %rdx
leaq 0x18(%rsp), %rcx
leaq 0x14(%rsp), %r8
movq %r13, %r9
xorl %eax, %eax
leaq 0x20(%rsp), %r10
pushq %r10
leaq 0x18(%rsp), %r10
pushq %r10
callq 0x3420
popq %rcx
popq %rdx
cmpl $0x5, %eax
je 0x8f7a
subq $0x8, %rsp
movq %r12, %rdi
leaq 0xc3c6(%rip), %rsi      # 0x15315
leaq 0x24(%rsp), %rdx
leaq 0x20(%rsp), %rcx
leaq 0x1c(%rsp), %r8
movq %r13, %r9
xorl %eax, %eax
leaq 0x28(%rsp), %r10
pushq %r10
callq 0x3420
popq %rcx
popq %rdx
cmpl $0x4, %eax
jne 0x9039
movl 0x1c(%rsp), %eax
cmpl $0xff, %eax
ja 0x9039
movl 0x18(%rsp), %esi
cmpl $0xff, %esi
ja 0x9039
movl 0x14(%rsp), %edx
cmpl $0xff, %edx
ja 0x9039
movl 0x24(%rsp), %edi
cmpl $0xff, %edi
ja 0x9039
movl 0x10(%rsp), %r8d
cmpl $0x21, %r8d
jae 0x9039
cmpl $0x0, 0x20(%rsp)
je 0x9039
movsbl %bl, %r9d
movl %r8d, %ecx
negb %cl
movl %r14d, %r10d
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 0xc(%rsp), %r10d
cmpl %r10d, %edx
cmovel %r9d, %ebp
jmp 0x8ecb
leaq 0xb7f8(%rip), %rsi      # 0x14800
leaq 0xb59f(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x902f
leaq 0xb7ee(%rip), %rdi      # 0x14810
movl 0xc(%rsp), %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x430a
xorl %r14d, %r14d
cmpl $0x2b, %ebp
sete %r14b
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 0xb776(%rip), %rsi      # 0x14818
leaq 0xb505(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x90fe
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 0xb226(%rip), %xmm0     # 0x14308
cvttsd2si %xmm0, %r8
andq %rsi, %r8
orq %rax, %r8
leaq 0xb731(%rip), %rdi      # 0x14825
movq %rbx, %rsi
xorl %eax, %eax
callq 0x430a
movaps 0x10(%rsp), %xmm0
testb $0x4, 0xc8(%rbx)
je 0x911d
movq 0xb0(%rbx), %rax
testq %rax, %rax
je 0x911d
movsd %xmm0, 0x78(%rax)
movsd 0x8(%rsp), %xmm0
addq $0x20, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x8316
movq %rax, %r14
testq %rax, %rax
je 0x91a1
cmpl $-0x1, %ebx
je 0x9195
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 0x7da5
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/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:
movslq 0x20(%rdi), %rcx
testq %rdx, %rdx
je 0x9204
xorl %r8d, %r8d
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
cmpq %r8, %rax
je 0x920e
movq 0x28(%rdi), %r9
cmpq %rdx, (%r9,%r8,8)
je 0x9208
incq %r8
jmp 0x91f0
xorl %eax, %eax
jmp 0x920e
incl %r8d
movl %r8d, %eax
movslq %eax, %rdx
cmpq %rcx, %rdx
jge 0x9228
movq 0x28(%rdi), %rax
movq (%rax,%rdx,8), %rax
incq %rdx
cmpq %rsi, 0x10(%rax)
jne 0x9211
retq
xorl %eax, %eax
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_set_non_blocking_mode
void mg_set_non_blocking_mode(sock_t sock) {
#ifdef _WIN32
  unsigned long on = 1;
  ioctlsocket(sock, FIONBIO, &on);
#else
  int flags = fcntl(sock, F_GETFL, 0);
  fcntl(sock, F_SETFL, flags | O_NONBLOCK);
#endif
}

// Assembly:
pushq %rbx
movl %edi, %ebx
pushq $0x3
popq %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x34f0
orl $0x800, %eax            # imm = 0x800
pushq $0x4
popq %rsi
movl %ebx, %edi
movl %eax, %edx
xorl %eax, %eax
popq %rbx
jmp 0x34f0
// File: /workspace/github_c_makefile_star2_O2/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, %r15
movq %rdi, %rbx
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %r14d, %r14d
xorl %edx, %edx
callq 0x3670
movl %eax, 0x20(%rbx)
cmpl $-0x1, %eax
je 0x92ed
movl %eax, %edi
callq 0x922b
movl 0x20(%rbx), %edi
pushq $0x10
popq %rdx
movq %r15, %rsi
callq 0x35c0
movl %eax, %ebp
testl %eax, %eax
jns 0x929f
callq 0x9310
testl %eax, %eax
je 0x929f
callq 0x9306
movl %eax, %r14d
movl %r14d, 0x24(%rbx)
leaq 0xb58b(%rip), %rsi      # 0x14835
leaq 0xb2fd(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x92fb
movl 0x20(%rbx), %r14d
callq 0x9306
movl 0x24(%rbx), %r9d
leaq 0xb57d(%rip), %rdi      # 0x1484e
movq %rbx, %rsi
movl %r14d, %edx
movl %ebp, %ecx
movl %eax, %r8d
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x430a
callq 0x9306
cmpl $0x1, %eax
adcl $0x0, %eax
movl %eax, 0x24(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_is_error
static int mg_is_error(void) {
  int err = mg_get_errno();
  return err != EINPROGRESS && err != EWOULDBLOCK
#ifndef WINCE
         && err != EAGAIN && err != EINTR
#endif
#ifdef _WIN32
         && WSAGetLastError() != WSAEINTR && WSAGetLastError() != WSAEWOULDBLOCK
#endif
      ;
}

// Assembly:
pushq %rbx
xorl %ebx, %ebx
callq 0x9306
cmpl $0xb, %eax
je 0x932a
cmpl $0x73, %eax
je 0x932a
xorl %ebx, %ebx
cmpl $0x4, %eax
setne %bl
movl %ebx, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x2
popq %rdi
xorl %ebp, %ebp
movl %edi, %esi
xorl %edx, %edx
callq 0x3670
movl %eax, 0x20(%rbx)
cmpl $-0x1, %eax
je 0x9371
testb $0x40, 0xc9(%rbx)
je 0x937e
leaq 0x4(%rsp), %rcx
movl $0x1, (%rcx)
pushq $0x1
popq %rsi
pushq $0x6
popq %rdx
pushq $0x4
popq %r8
movl %eax, %edi
callq 0x3120
jmp 0x937e
callq 0x9306
movl %eax, %ebp
cmpl $0x1, %eax
adcl $0x0, %ebp
movl %ebp, 0x24(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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 %rsi, %rax
movq %rdi, %rbx
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x93c3
cmpl $-0x1, %eax
je 0x93b6
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq %rbx, %rdi
movl %eax, %esi
callq *0x70(%rcx)
xorl %eax, %eax
popq %rbx
retq
callq 0x9306
cmpl $0x1, %eax
adcl $0x0, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq $-0x1
popq %r14
cmpl $-0x1, %eax
je 0x9424
movl %eax, %ebp
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
movq %rsp, %rcx
pushq $0x4
popq %r8
movl %eax, %edi
callq 0x3120
testl %eax, %eax
jne 0x941d
pushq $0x10
popq %rdx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x34c0
testl %eax, %eax
je 0x9432
movl %ebp, %edi
callq 0x3280
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x2, %r15d
je 0x9448
movl %ebp, %edi
movl $0x1000, %esi           # imm = 0x1000
callq 0x3440
testl %eax, %eax
jne 0x941d
movl %ebp, %edi
callq 0x922b
leaq 0x4(%rsp), %rdx
movl %ebp, %edi
movq %rbx, %rsi
callq 0x3560
movl %ebp, %r14d
jmp 0x9424
// File: /workspace/github_c_makefile_star2_O2/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 %rsi, %rax
movq %rdi, %rbx
pushq $0x2
popq %rsi
movq %rax, %rdi
callq 0x93c3
cmpl $-0x1, %eax
je 0x9491
movq 0xc0(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq %rbx, %rdi
movl %eax, %esi
callq *0x70(%rcx)
xorl %eax, %eax
popq %rbx
retq
callq 0x9306
cmpl $0x1, %eax
adcl $0x0, %eax
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x94da
testb $0x2, 0xc8(%rbx)
je 0x94d1
cmpq $0x0, 0x10(%rbx)
jne 0x94d6
callq 0x3280
orl $-0x1, 0x20(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/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
callq 0x922b
movl %ebx, %edi
callq 0x9abd
movl %ebx, 0x20(%r14)
leaq 0xae58(%rip), %rsi      # 0x148e0
leaq 0xab1f(%rip), %rdx      # 0x145ae
pushq $0x4
popq %rdi
callq 0x4227
testl %eax, %eax
je 0x9ab5
leaq 0xac2a(%rip), %rdi      # 0x146cc
movq %r14, %rsi
movl %ebx, %edx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x430a
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/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 0x9cd8
movq %rdx, %r8
pushq $0x40
popq %rcx
movl %edi, %eax
cltd
idivl %ecx
movslq %eax, %rdx
shll $0x6, %eax
movl %edi, %ecx
subl %eax, %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
orq %rax, (%rsi,%rdx,8)
movl (%r8), %eax
cmpl $-0x1, %eax
setne %cl
cmpl %edi, %eax
setge %al
testb %al, %cl
jne 0x9cd8
movl %edi, (%r8)
retq
// File: /workspace/github_c_makefile_star2_O2/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 0xa130
movq %rdx, %rsi
movq %rax, %rdx
callq 0x3150
jmp 0xa13b
movq %rdx, %rsi
movq %rax, %rdx
callq 0x3560
popq %rax
retq
// File: /workspace/github_c_makefile_star2_O2/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 0xa1fa
movq %rsi, %rbx
movq %rdi, %r15
movq %rsi, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x3240
testb $0x1, %bpl
je 0xa190
leaq 0x4(%r15), %rsi
leal -0x1(%r14), %ecx
pushq $0x2
popq %rdi
movq %rbx, %rdx
callq 0x3040
testq %rax, %rax
je 0xa205
testb $0x2, %bpl
je 0xa1f2
movzwl 0x2(%r15), %eax
rolw $0x8, %ax
movzwl %ax, %r15d
testb $0x1, %bpl
jne 0xa1c2
leaq 0xb22c(%rip), %rdx      # 0x153dc
movq %rbx, %rdi
movq %r14, %rsi
movl %r15d, %ecx
xorl %eax, %eax
callq 0x31e0
jmp 0xa1f2
movq %rbx, %rdi
callq 0x3180
cltq
leaq (%rbx,%rax), %rdi
incl %eax
cltq
subq %rax, %r14
leaq 0xb1ce(%rip), %rdx      # 0x153ac
leaq 0xb5eb(%rip), %rcx      # 0x157d0
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 0xa1fa
// File: /workspace/github_c_makefile_star2_O2/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 0xa224
movq 0xc8(%rdi), %rax
andl $0x2, %eax
je 0xa224
movups 0x28(%rdi), %xmm0
movups %xmm0, (%rdx)
retq
movl 0x20(%rdi), %edi
jmp 0xa10b
// File: /workspace/github_c_makefile_star2_O2/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
callq 0xa2bb
leaq 0xa6cc(%rip), %rsi      # 0x1493e
leaq 0xa335(%rip), %rdx      # 0x145ae
pushq $0x3
popq %rdi
callq 0x4227
testl %eax, %eax
je 0xa298
leaq 0xa6c5(%rip), %rdi      # 0x14951
movq %rsp, %rdx
movl %ebp, %esi
xorl %eax, %eax
callq 0x430a
movq 0x20(%r15), %rdi
movl %ebp, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r14, %r8
movq %rbx, %r9
callq 0xa2c3
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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)
pushq $0x1
popq %rax
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)
pushq $0x2
popq %rsi
pushq $0x4
popq %rcx
callq 0xfaa3
addq $0x58, %rsp
retq
// File: /workspace/github_c_makefile_star2_O2/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
pushq %rax
movq 0xc0(%rdi), %rax
movq 0x8(%rax), %rbx
testb $0x1, 0xc8(%rdi)
jne 0xa38a
cmpq $0x0, 0x20(%rbx)
je 0xa398
movl 0xb8(%rdi), %ebp
leaq 0xa621(%rip), %rsi      # 0x1496c
leaq 0xa25c(%rip), %rdx      # 0x145ae
pushq $0x3
popq %rdi
callq 0x4227
testl %eax, %eax
je 0xa36e
leaq 0xa61e(%rip), %rdi      # 0x14983
movl %ebp, %esi
xorl %eax, %eax
callq 0x430a
movq 0x20(%rbx), %rdi
pushq $0x1
popq %rcx
movl %ebp, %esi
xorl %edx, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xa2c3
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xa39f
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/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), %r15
movq (%r15), %r15
testq %r15, %r15
je 0xa437
movq 0xc0(%r15), %rax
cmpq 0x8(%r14), %rax
jne 0xa40d
testb $0x1, 0xc8(%r15)
jne 0xa40d
cmpl %ebx, 0xb8(%r15)
jne 0xa40d
jmp 0xa4a4
movl 0x1c(%r14), %ebp
leaq 0xa54f(%rip), %rsi      # 0x14991
leaq 0xa165(%rip), %rdx      # 0x145ae
pushq $0x3
popq %rdi
callq 0x4227
cmpl %ebx, %ebp
jae 0xa484
testl %eax, %eax
je 0xa469
leaq 0xa545(%rip), %rdi      # 0x149a5
movl %ebx, %esi
xorl %eax, %eax
callq 0x430a
movq 0x28(%r14), %rdi
callq 0x7c52
movq %rax, %r15
movl %ebx, %eax
movq %rax, 0xb8(%r15)
movl %ebx, 0x1c(%r14)
jmp 0xa4a4
testl %eax, %eax
je 0xa4a1
movl 0x1c(%r14), %edx
leaq 0xa52d(%rip), %rdi      # 0x149c0
xorl %r15d, %r15d
movl %ebx, %esi
xorl %eax, %eax
callq 0x430a
jmp 0xa4a4
xorl %r15d, %r15d
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: parse_uri_component
static void parse_uri_component(const char **p, const char *end,
                                const char *seps, struct mg_str *res) {
  const char *q;
  res->p = *p;
  for (; *p < end; (*p)++) {
    for (q = seps; *q != '\0'; q++) {
      if (**p == *q) break;
    }
    if (*q != '\0') break;
  }
  res->len = (*p) - res->p;
  if (*p < end) (*p)++;
}

// Assembly:
movq (%rdi), %rax
movq %rax, (%rcx)
movq %rdx, %r8
cmpq %rsi, %rax
jae 0xa8e9
movb (%r8), %r9b
testb %r9b, %r9b
je 0xa8d0
incq %r8
cmpb %r9b, (%rax)
jne 0xa8be
jmp 0xa8d8
incq %rax
movq %rax, (%rdi)
jmp 0xa8b6
movq %rax, %rdx
subq (%rcx), %rdx
movq %rdx, 0x8(%rcx)
incq %rax
movq %rax, (%rdi)
retq
subq (%rcx), %rax
movq %rax, 0x8(%rcx)
retq
// File: /workspace/github_c_makefile_star2_O2/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 0xa9e3
movq (%rdi), %r15
cmpb $0x2f, (%r15)
jne 0xa9e3
addq %r15, %r14
movq %rsi, 0x8(%rsp)
movq (%rsi), %rbp
xorl %r13d, %r13d
leaq 0x18(%rsp), %r12
movq %r14, 0x10(%rsp)
movq %rbp, %rbx
addq %r13, %rbx
cmpq %r14, %r15
jae 0xa9e9
movq %r15, (%rsp)
movq %rsp, %rdi
movq %r14, %rsi
leaq 0xa7a8(%rip), %rdx      # 0x150f9
movq %r12, %rcx
callq 0xa8b0
movq %r12, %rdi
leaq 0xa08c(%rip), %rsi      # 0x149ef
callq 0x6899
testl %eax, %eax
je 0xa9da
movq %r12, %rdi
leaq 0xa078(%rip), %rsi      # 0x149ee
callq 0x6899
testl %eax, %eax
je 0xa99e
movq (%rsp), %r12
subq %r15, %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3500
addq %r12, %r13
movq 0x10(%rsp), %r14
jmp 0xa9d5
cmpq $0x2, %r13
jl 0xa9b2
leaq -0x1(%r13), %rax
cmpb $0x2f, -0x1(%rbp,%r13)
cmoveq %rax, %r13
movq %r13, %rax
sarq $0x3f, %r13
andq %rax, %r13
testq %rax, %rax
jle 0xa9d5
leaq -0x1(%rax), %rcx
cmpb $0x2f, -0x1(%rbp,%rax)
movq %rcx, %rax
jne 0xa9bc
incq %rcx
movq %rcx, %r13
leaq 0x18(%rsp), %r12
movq (%rsp), %r15
jmp 0xa931
xorl %ebx, %ebx
xorl %eax, %eax
jmp 0xaa02
testq %r13, %r13
jne 0xa9f4
movb $0x2f, (%rbx)
incq %rbx
movq 0x8(%rsp), %rsi
movq %rbp, (%rsi)
subq %rbp, %rbx
pushq $0x1
popq %rax
movq %rbx, 0x8(%rsi)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %r14
xorl %ebx, %ebx
testl %esi, %esi
movl $0x0, %r12d
cmovgl %esi, %r12d
negq %r12
pushq $0x2
popq %r15
pushq $0x1
popq %r13
leaq (%r12,%r15), %rax
cmpq $0x2, %rax
je 0xaeb3
callq 0x3660
movzbl -0x2(%r14,%r15), %ecx
cmpl $0xa, %ecx
je 0xae7a
testb %cl, %cl
js 0xae7a
cmpb $0xd, %cl
je 0xae7a
movq (%rax), %rax
movzwl (%rax,%rcx,2), %eax
andl $0x4000, %eax           # imm = 0x4000
je 0xaea8
cmpb $0xa, %cl
jne 0xaea0
cmpl %ebp, %r13d
jge 0xae8c
cmpb $0xa, -0x1(%r14,%r15)
je 0xaeb0
cmpl %ebp, %r15d
jge 0xaea0
cmpb $0xd, -0x1(%r14,%r15)
jne 0xaea0
cmpb $0xa, (%r14,%r15)
je 0xaead
incq %r15
incl %r13d
jmp 0xae49
pushq $-0x1
popq %rbx
jmp 0xaeb3
incl %r15d
movl %r15d, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_skip
const char *mg_skip(const char *s, const char *end, const char *delims,
                    struct mg_str *v) {
  v->p = s;
  while (s < end && strchr(delims, *(unsigned char *) s) == NULL) s++;
  v->len = s - v->p;
  while (s < end && strchr(delims, *(unsigned char *) s) != NULL) s++;
  return s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r12
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r13
movq %rdi, (%rcx)
xorl %ebp, %ebp
movq %r13, %r15
addq %rbp, %r15
cmpq %r14, %r15
jae 0xaf01
movzbl (%r15), %esi
movq %rbx, %rdi
callq 0x31d0
testq %rax, %rax
jne 0xaf01
incq %rbp
jmp 0xaee0
movq %rbp, 0x8(%r12)
cmpq %r14, %r15
jae 0xaf21
movzbl (%r15), %esi
movq %rbx, %rdi
callq 0x31d0
testq %rax, %rax
je 0xaf21
incq %r15
jmp 0xaf06
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_parse_headers
static const char *mg_http_parse_headers(const char *s, const char *end,
                                         int len, struct http_message *req) {
  int i = 0;
  while (i < (int) ARRAY_SIZE(req->header_names) - 1) {
    struct mg_str *k = &req->header_names[i], *v = &req->header_values[i];

    s = mg_skip(s, end, ": ", k);
    s = mg_skip(s, end, "\r\n", v);

    while (v->len > 0 && v->p[v->len - 1] == ' ') {
      v->len--; /* Trim trailing spaces in header value */
    }

    /*
     * If header value is empty - skip it and go to next (if any).
     * NOTE: Do not add it to headers_values because such addition changes API
     * behaviour
     */
    if (k->len != 0 && v->len == 0) {
      continue;
    }

    if (k->len == 0 || v->len == 0) {
      k->p = v->p = NULL;
      k->len = v->len = 0;
      break;
    }

    if (!mg_ncasecmp(k->p, "Content-Length", 14)) {
      req->body.len = (size_t) to64(v->p);
      req->message.len = len + req->body.len;
    }

    i++;
  }

  return s;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %r13
leaq 0x78(%rcx), %rax
movq %rax, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
leaq 0x2f8(%rcx), %r12
movslq %edx, %rax
movq %rax, (%rsp)
xorl %r15d, %r15d
movl %r15d, %ebp
shlq $0x4, %rbp
movq 0x10(%rsp), %rax
leaq (%rax,%rbp), %rbx
addq %r12, %rbp
cmpl $0x26, %r15d
ja 0xb02d
movq %r13, %rdi
movq %r14, %rsi
leaq 0xa4b6(%rip), %rdx      # 0x15446
movq %rbx, %rcx
callq 0xaec4
movq %rax, %rdi
movq %r14, %rsi
leaq 0xa829(%rip), %rdx      # 0x157ce
movq %rbp, %rcx
callq 0xaec4
movq %rax, %r13
movq 0x8(%rbp), %rax
decq %rax
cmpq $-0x1, %rax
je 0xafcd
movq (%rbp), %rcx
cmpb $0x20, (%rcx,%rax)
jne 0xafd6
movq %rax, 0x8(%rbp)
jmp 0xafb4
cmpq $0x0, 0x8(%rbx)
jne 0xaf79
jmp 0xb01a
cmpq $0x0, 0x8(%rbx)
je 0xb01a
movq (%rbx), %rdi
leaq 0xa462(%rip), %rsi      # 0x15449
pushq $0xe
popq %rdx
callq 0x6915
testl %eax, %eax
jne 0xb012
movq (%rbp), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x3330
movq 0x8(%rsp), %rcx
movq %rax, 0x18(%rcx)
addq (%rsp), %rax
movq %rax, 0x8(%rcx)
incl %r15d
jmp 0xaf66
andq $0x0, (%rbp)
andq $0x0, (%rbx)
andq $0x0, 0x8(%rbp)
andq $0x0, 0x8(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_get_http_header
struct mg_str *mg_get_http_header(struct http_message *hm, const char *name) {
  size_t i, len = strlen(name);

  for (i = 0; hm->header_names[i].len > 0; i++) {
    struct mg_str *h = &hm->header_names[i], *v = &hm->header_values[i];
    if (h->p != NULL && h->len == len && !mg_ncasecmp(h->p, name, len))
      return v;
  }

  return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x3180
movq %rax, %r15
addq $0x2f8, %rbx            # imm = 0x2F8
movq -0x278(%rbx), %rax
testq %rax, %rax
je 0xb093
movq -0x280(%rbx), %rdi
testq %rdi, %rdi
setne %cl
cmpq %r15, %rax
sete %al
andb %cl, %al
cmpb $0x1, %al
jne 0xb08d
movq %r14, %rsi
movq %r15, %rdx
callq 0x6915
testl %eax, %eax
je 0xb095
addq $0x10, %rbx
jmp 0xb059
xorl %ebx, %ebx
movq %rbx, %rax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_get_endpoint_handler
struct mg_http_endpoint *mg_http_get_endpoint_handler(struct mg_connection *nc,
                                                      struct mg_str *uri_path) {
  struct mg_http_proto_data *pd;
  struct mg_http_endpoint *ret = NULL;
  int matched, matched_max = 0;
  struct mg_http_endpoint *ep;

  if (nc == NULL) {
    return NULL;
  }

  pd = mg_http_get_proto_data(nc);

  ep = pd->endpoints;
  while (ep != NULL) {
    if ((matched = mg_match_prefix_n(ep->uri_pattern, *uri_path)) != -1) {
      if (matched > matched_max) {
        /* Looking for the longest suitable handler */
        ret = ep;
        matched_max = matched;
      }
    }

    ep = ep->next;
  }

  return ret;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
xorl %r12d, %r12d
testq %rdi, %rdi
je 0xb0f4
movq %rsi, %rbx
callq 0xb106
movq %rax, %r15
addq $0x38, %r15
xorl %r14d, %r14d
movq (%r15), %r15
testq %r15, %r15
je 0xb0f7
movq 0x8(%r15), %rdi
movq 0x10(%r15), %rsi
movq (%rbx), %rdx
movq 0x8(%rbx), %rcx
callq 0x740c
cmpl $-0x1, %eax
setne %cl
cmpl %r12d, %eax
setg %dl
testb %dl, %cl
cmovneq %r15, %r14
cmovnel %eax, %r12d
jmp 0xb0c0
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_get_proto_data
static struct mg_http_proto_data *mg_http_get_proto_data(
    struct mg_connection *c) {
  if (c->proto_data == NULL) {
    c->proto_data = MG_CALLOC(1, sizeof(struct mg_http_proto_data));
    c->proto_data_destructor = mg_http_conn_destructor;
  }

  return (struct mg_http_proto_data *) c->proto_data;
}

// Assembly:
movq 0x88(%rdi), %rax
testq %rax, %rax
je 0xb113
retq
pushq %rbx
movq %rdi, %rbx
pushq $0x1
popq %rdi
pushq $0x58
popq %rsi
callq 0x3300
movq %rax, 0x88(%rbx)
leaq 0x6c48(%rip), %rcx      # 0x11d78
movq %rcx, 0x90(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: deliver_chunk
static void deliver_chunk(struct mg_connection *c, struct http_message *hm,
                          int req_len) {
  /* Incomplete message received. Send MG_EV_HTTP_CHUNK event */
  hm->body.len = c->recv_mbuf.len - req_len;
  c->flags &= ~MG_F_DELETE_CHUNK;
  mg_call(c, c->handler, c->user_data, MG_EV_HTTP_CHUNK, hm);
  /* Delete processed data if user set MG_F_DELETE_CHUNK flag */
  if (c->flags & MG_F_DELETE_CHUNK) c->recv_mbuf.len = req_len;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rcx
movq %rdi, %rbx
movq 0x48(%rdi), %rax
movl %edx, %r14d
subq %r14, %rax
movq %rax, 0x18(%rsi)
andb $-0x21, 0xc9(%rdi)
movq 0x98(%rdi), %rsi
pushq $0x66
popq %rdx
callq 0x75bd
testb $0x20, 0xc9(%rbx)
je 0xb8c5
movq %r14, 0x48(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_http_call_endpoint_handler
static void mg_http_call_endpoint_handler(struct mg_connection *nc, int ev,
                                          struct http_message *hm) {
  struct mg_http_proto_data *pd = mg_http_get_proto_data(nc);
  void *user_data = nc->user_data;

  if (ev == MG_EV_HTTP_REQUEST
#if MG_ENABLE_HTTP_STREAMING_MULTIPART
      || ev == MG_EV_HTTP_MULTIPART_REQUEST
#endif
      ) {
    struct mg_http_endpoint *ep =
        mg_http_get_endpoint_handler(nc->listener, &hm->uri);
    if (ep != NULL) {
#if MG_ENABLE_FILESYSTEM && !MG_DISABLE_HTTP_DIGEST_AUTH
      if (!mg_http_is_authorized(hm, hm->uri, 0 /* is_directory */,
                                 ep->auth_domain, ep->auth_file,
                                 1 /* is_global_pass_file */)) {
        mg_http_send_digest_auth_request(nc, ep->auth_domain);
        return;
      }
#endif
      pd->endpoint_handler = ep->handler;
#if MG_ENABLE_CALLBACK_USERDATA
      user_data = ep->user_data;
#endif
    }
  }
  mg_call(nc, pd->endpoint_handler ? pd->endpoint_handler : nc->handler,
          user_data, ev, hm);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
callq 0xb106
movq %rax, %r15
cmpl $0x64, %ebp
jne 0xb931
movq 0x10(%r14), %rdi
leaq 0x30(%rbx), %rsi
callq 0xb09e
testq %rax, %rax
je 0xb931
movq %rax, %r12
movq 0x18(%rax), %r8
movq 0x20(%rax), %r9
movq 0x30(%rbx), %rsi
movq 0x38(%rbx), %rdx
movl $0x1, (%rsp)
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x11e35
testl %eax, %eax
je 0xb95a
movq 0x28(%r12), %rax
movq %rax, 0x40(%r15)
movq 0x40(%r15), %rsi
testq %rsi, %rsi
jne 0xb941
movq 0x98(%r14), %rsi
movq %r14, %rdi
movl %ebp, %edx
movq %rbx, %rcx
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x75bd
movq 0x18(%r12), %rsi
movq %r14, %rdi
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x11f9e
// File: /workspace/github_c_makefile_star2_O2/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_send_response_line_s
void mg_send_response_line_s(struct mg_connection *nc, int status_code,
                             const struct mg_str extra_headers) {
  mg_printf(nc, "HTTP/1.1 %d %s\r\nServer: %s\r\n", status_code,
            mg_status_message(status_code), mg_version_header);
  if (extra_headers.len > 0) {
    mg_printf(nc, "%.*s\r\n", (int) extra_headers.len, extra_headers.p);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rcx, %r14
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r15
movl %esi, %edi
callq 0xbdb1
leaq 0x8c78(%rip), %rsi      # 0x14b18
leaq 0x9667(%rip), %r8       # 0x1550e
movq %r15, %rdi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x7bce
testq %r14, %r14
je 0xbedc
leaq 0x9b6a(%rip), %rsi      # 0x15a2c
movq %r15, %rdi
movl %r14d, %edx
movq %rbx, %rcx
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x7bce
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq