// File: /workspace/github_c_makefile_star2_O0/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_bind_opt
struct mg_connection *mg_bind_opt(struct mg_mgr *mgr, const char *address,
                                  MG_CB(mg_event_handler_t callback,
                                        void *user_data),
                                  struct mg_bind_opts opts) {
  union socket_address sa;
  struct mg_connection *nc = NULL;
  int proto, rc;
  struct mg_add_sock_opts add_sock_opts;
  char host[MG_MAX_HOST_LEN];

#if MG_ENABLE_CALLBACK_USERDATA
  opts.user_data = user_data;
#endif

  MG_COPY_COMMON_CONNECTION_OPTIONS(&add_sock_opts, &opts);

#if MG_ENABLE_TUN
  if (mg_strncmp(mg_mk_str(address), mg_mk_str("ws://"), 5) == 0 ||
      mg_strncmp(mg_mk_str(address), mg_mk_str("wss://"), 6) == 0) {
    return mg_tun_bind_opt(mgr, address, MG_CB(callback, user_data), opts);
  }
#endif

  if (mg_parse_address(address, &sa, &proto, host, sizeof(host)) <= 0) {
    MG_SET_PTRPTR(opts.error_string, "cannot parse address");
    return NULL;
  }

  nc = mg_create_connection(mgr, callback, add_sock_opts);
  if (nc == NULL) {
    return NULL;
  }

  nc->sa = sa;
  nc->flags |= MG_F_LISTENING;
  if (proto == SOCK_DGRAM) nc->flags |= MG_F_UDP;

#if MG_ENABLE_SSL
  DBG(("%p %s %s,%s,%s", nc, address, (opts.ssl_cert ? opts.ssl_cert : "-"),
       (opts.ssl_key ? opts.ssl_key : "-"),
       (opts.ssl_ca_cert ? opts.ssl_ca_cert : "-")));

  if (opts.ssl_cert != NULL || opts.ssl_ca_cert != NULL) {
    const char *err_msg = NULL;
    struct mg_ssl_if_conn_params params;
    if (nc->flags & MG_F_UDP) {
      MG_SET_PTRPTR(opts.error_string, "SSL for UDP is not supported");
      mg_destroy_conn(nc, 1 /* destroy_if */);
      return NULL;
    }
    memset(&params, 0, sizeof(params));
    params.cert = opts.ssl_cert;
    params.key = opts.ssl_key;
    params.ca_cert = opts.ssl_ca_cert;
    params.cipher_suites = opts.ssl_cipher_suites;
    if (mg_ssl_if_conn_init(nc, &params, &err_msg) != MG_SSL_OK) {
      MG_SET_PTRPTR(opts.error_string, err_msg);
      mg_destroy_conn(nc, 1 /* destroy_if */);
      return NULL;
    }
    nc->flags |= MG_F_SSL;
  }
#endif /* MG_ENABLE_SSL */

  if (nc->flags & MG_F_UDP) {
    rc = nc->iface->vtable->listen_udp(nc, &nc->sa);
  } else {
    rc = nc->iface->vtable->listen_tcp(nc, &nc->sa);
  }
  if (rc != 0) {
    DBG(("Failed to open listener: %d", rc));
    MG_SET_PTRPTR(opts.error_string, "failed to open listener");
    mg_destroy_conn(nc, 1 /* destroy_if */);
    return NULL;
  }
  mg_add_conn(nc->mgr, nc);

  return nc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
leaq 0x10(%rbp), %rax
movq %rax, -0x178(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x38(%rbp)
movq (%rax), %rcx
movq %rcx, -0x60(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rdi
callq 0x8a60
movq %rax, -0x140(%rbp)
movq %rdx, -0x138(%rbp)
leaq 0x12bb8(%rip), %rdi     # 0x1f74f
callq 0x8a60
movq %rax, -0x150(%rbp)
movq %rdx, -0x148(%rbp)
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rsi
movq -0x150(%rbp), %rdx
movq -0x148(%rbp), %rcx
movl $0x5, %r8d
callq 0x8ee0
cmpl $0x0, %eax
je 0xcc33
movq -0x18(%rbp), %rdi
callq 0x8a60
movq %rax, -0x160(%rbp)
movq %rdx, -0x158(%rbp)
leaq 0x12b61(%rip), %rdi     # 0x1f755
callq 0x8a60
movq %rax, -0x170(%rbp)
movq %rdx, -0x168(%rbp)
movq -0x160(%rbp), %rdi
movq -0x158(%rbp), %rsi
movq -0x170(%rbp), %rdx
movq -0x168(%rbp), %rcx
movl $0x6, %r8d
callq 0x8ee0
cmpl $0x0, %eax
jne 0xcc76
movq -0x178(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
callq 0xce60
movq %rax, -0x8(%rbp)
jmp 0xce4d
movq -0x18(%rbp), %rdi
leaq -0x130(%rbp), %rcx
leaq -0x30(%rbp), %rsi
leaq -0x3c(%rbp), %rdx
movl $0xc8, %r8d
callq 0xc390
cmpl $0x0, %eax
jg 0xcccd
jmp 0xcc9b
movq -0x178(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0xccbe
movq -0x178(%rbp), %rax
movq 0x10(%rax), %rax
leaq 0x12a64(%rip), %rcx     # 0x1f71f
movq %rcx, (%rax)
jmp 0xccc0
movq $0x0, -0x8(%rbp)
jmp 0xce4d
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq -0x60(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
callq 0xb500
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0xcd18
movq $0x0, -0x8(%rbp)
jmp 0xce4d
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rcx
movq %rcx, 0x30(%rax)
movq -0x38(%rbp), %rax
movq 0xc8(%rax), %rcx
orq $0x1, %rcx
movq %rcx, 0xc8(%rax)
cmpl $0x2, -0x3c(%rbp)
jne 0xcd5e
movq -0x38(%rbp), %rax
movq 0xc8(%rax), %rcx
orq $0x2, %rcx
movq %rcx, 0xc8(%rax)
movq -0x38(%rbp), %rax
movq 0xc8(%rax), %rax
andq $0x2, %rax
cmpq $0x0, %rax
je 0xcd99
movq -0x38(%rbp), %rax
movq 0xc0(%rax), %rax
movq 0x10(%rax), %rax
movq 0x30(%rax), %rax
movq -0x38(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x28, %rsi
callq *%rax
movl %eax, -0x40(%rbp)
jmp 0xcdbd
movq -0x38(%rbp), %rax
movq 0xc0(%rax), %rax
movq 0x10(%rax), %rax
movq 0x28(%rax), %rax
movq -0x38(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x28, %rsi
callq *%rax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0xce34
jmp 0xcdc5
movl $0x4, %edi
leaq 0x1298b(%rip), %rsi     # 0x1f75c
leaq 0x12772(%rip), %rdx     # 0x1f54a
callq 0x4650
cmpl $0x0, %eax
je 0xcdf3
movl -0x40(%rbp), %esi
leaq 0x1297c(%rip), %rdi     # 0x1f768
movb $0x0, %al
callq 0x47a0
jmp 0xcdf5
jmp 0xcdf7
movq -0x178(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0xce1a
movq -0x178(%rbp), %rax
movq 0x10(%rax), %rax
leaq 0x1296d(%rip), %rcx     # 0x1f784
movq %rcx, (%rax)
jmp 0xce1c
movq -0x38(%rbp), %rdi
movl $0x1, %esi
callq 0xabf0
movq $0x0, -0x8(%rbp)
jmp 0xce4d
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0xb5c0
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopw (%rax,%rax)