// File: /workspace/github_c_makefile_star2_O3/sfeakes[P]unifi-motion/mongoose.c
// Function: mg_connect_http_base
struct mg_connection *mg_connect_http_base(
    struct mg_mgr *mgr, MG_CB(mg_event_handler_t ev_handler, void *user_data),
    struct mg_connect_opts opts, const char *scheme1, const char *scheme2,
    const char *scheme_ssl1, const char *scheme_ssl2, const char *url,
    struct mg_str *path, struct mg_str *user_info, struct mg_str *host) {
  struct mg_connection *nc = NULL;
  unsigned int port_i = 0;
  int use_ssl = 0;
  struct mg_str scheme, query, fragment;
  char conn_addr_buf[2];
  char *conn_addr = conn_addr_buf;

  if (mg_parse_uri(mg_mk_str(url), &scheme, user_info, host, &port_i, path,
                   &query, &fragment) != 0) {
    MG_SET_PTRPTR(opts.error_string, "cannot parse url");
    goto out;
  }

  /* If query is present, do not strip it. Pass to the caller. */
  if (query.len > 0) path->len += query.len + 1;

  if (scheme.len == 0 || mg_vcmp(&scheme, scheme1) == 0 ||
      (scheme2 != NULL && mg_vcmp(&scheme, scheme2) == 0)) {
    use_ssl = 0;
    if (port_i == 0) port_i = 80;
  } else if (mg_vcmp(&scheme, scheme_ssl1) == 0 ||
             (scheme2 != NULL && mg_vcmp(&scheme, scheme_ssl2) == 0)) {
    use_ssl = 1;
    if (port_i == 0) port_i = 443;
  } else {
    goto out;
  }

  mg_asprintf(&conn_addr, sizeof(conn_addr_buf), "tcp://%.*s:%u",
              (int) host->len, host->p, port_i);
  if (conn_addr == NULL) goto out;

  LOG(LL_DEBUG, ("%s use_ssl? %d %s", url, use_ssl, conn_addr));
  if (use_ssl) {
#if MG_ENABLE_SSL
    /*
     * Schema requires SSL, but no SSL parameters were provided in opts.
     * In order to maintain backward compatibility, use a faux-SSL with no
     * verification.
     */
    if (opts.ssl_ca_cert == NULL) {
      opts.ssl_ca_cert = "*";
    }
#else
    MG_SET_PTRPTR(opts.error_string, "ssl is disabled");
    goto out;
#endif
  }

  if ((nc = mg_connect_opt(mgr, conn_addr, MG_CB(ev_handler, user_data),
                           opts)) != NULL) {
    mg_set_protocol_http_websocket(nc);
  }

out:
  if (conn_addr != NULL && conn_addr != conn_addr_buf) MG_FREE(conn_addr);
  return nc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %r9, 0x70(%rsp)
movq %r8, 0x68(%rsp)
movq %rcx, 0x60(%rsp)
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %rbx
movq 0x110(%rsp), %r15
movq 0x100(%rsp), %r13
movq 0xf8(%rsp), %rdi
leaq 0x30(%rsp), %r12
movl $0x0, (%r12)
leaq 0x36(%rsp), %rax
movq %rax, 0x38(%rsp)
callq 0x6b26
leaq 0x88(%rsp), %rcx
movq %rcx, 0x10(%rsp)
leaq 0x78(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movq %r13, (%rsp)
leaq 0x40(%rsp), %rcx
movq %rax, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq 0x108(%rsp), %rcx
movq %r15, %r8
movq %r12, %r9
callq 0xad41
testl %eax, %eax
je 0xe675
leaq 0xd0(%rsp), %rax
movq 0x10(%rax), %rax
testq %rax, %rax
je 0xe63f
leaq 0x7946(%rip), %rcx      # 0x15f82
movq %rcx, (%rax)
xorl %ebx, %ebx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
sete %al
leaq 0x36(%rsp), %rcx
cmpq %rcx, %rdi
sete %cl
orb %al, %cl
jne 0xe660
callq 0x3060
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x100(%rsp), %rcx
movq %r14, %rsi
movq 0x60(%rsp), %r12
movq 0x68(%rsp), %r15
movq 0x70(%rsp), %rdx
movq 0x110(%rsp), %r13
movq 0xf8(%rsp), %r14
movq %rbx, 0x58(%rsp)
movq %rbp, 0x50(%rsp)
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0xe6c7
movq %rcx, %rdi
movq 0x8(%rcx), %rcx
addq %rcx, %rax
incq %rax
movq %rax, 0x8(%rdi)
cmpq $0x0, 0x48(%rsp)
je 0xe711
movq %rdx, %rbx
leaq 0x40(%rsp), %rdi
callq 0x6b4a
testl %eax, %eax
je 0xe711
testq %r12, %r12
je 0xe733
movq %r12, %rsi
leaq 0x40(%rsp), %rdi
callq 0x6b4a
testl %eax, %eax
je 0xe711
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x6b4a
testl %eax, %eax
je 0xe748
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
jmp 0xe73b
movl 0x30(%rsp), %r9d
xorl %ebp, %ebp
movb $0x1, %r15b
movq %r14, %r12
testl %r9d, %r9d
jne 0xe76b
movl $0x50, 0x30(%rsp)
movl $0x50, %r9d
jmp 0xe76b
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x6b4a
testl %eax, %eax
jne 0xe63f
movl 0x30(%rsp), %r9d
movl $0x1, %ebp
movq %r14, %r12
testl %r9d, %r9d
jne 0xe768
movl $0x1bb, 0x30(%rsp)      # imm = 0x1BB
movl $0x1bb, %r9d            # imm = 0x1BB
xorl %r15d, %r15d
movl 0x8(%r13), %ecx
movq (%r13), %r8
leaq 0x7819(%rip), %rdx      # 0x15f93
xorl %ebx, %ebx
leaq 0x38(%rsp), %r14
movl $0x2, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x7557
cmpq $0x0, (%r14)
je 0xe641
leaq 0x7800(%rip), %rsi      # 0x15fa1
leaq 0x6e26(%rip), %rdx      # 0x155ce
movl $0x3, %edi
callq 0x4447
testl %eax, %eax
je 0xe7ce
movq 0x38(%rsp), %rcx
leaq 0x77f4(%rip), %rdi      # 0x15fb6
movq %r12, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x4539
testb %r15b, %r15b
movq 0x50(%rsp), %rdx
movq 0x58(%rsp), %rdi
leaq 0xd0(%rsp), %rcx
je 0xe827
movq 0x38(%rsp), %rsi
movq 0x20(%rcx), %rax
movq %rax, 0x20(%rsp)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x8909
testq %rax, %rax
je 0xe63f
movq %rax, %rbx
leaq -0x2e81(%rip), %rax     # 0xb99a
movq %rax, 0x80(%rbx)
jmp 0xe641
movq 0x10(%rcx), %rax
testq %rax, %rax
je 0xe63f
leaq 0x778d(%rip), %rcx      # 0x15fc8
jmp 0xe63c