// File: /workspace/github_c_makefile_star2_O1/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 $0x88, %rsp
movq %r9, 0x60(%rsp)
movq %r8, 0x58(%rsp)
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %rbp
movq 0xf0(%rsp), %r15
movq 0xe8(%rsp), %rdi
leaq 0x30(%rsp), %r12
movl $0x0, (%r12)
leaq 0x36(%rsp), %rax
movq %rax, 0x38(%rsp)
callq 0x6be8
leaq 0x78(%rsp), %rcx
movq %rcx, 0x10(%rsp)
leaq 0x68(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movq %r15, (%rsp)
leaq 0x40(%rsp), %rcx
movq %rax, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq 0xf8(%rsp), %rcx
movq 0x100(%rsp), %r8
movq %r12, %r9
callq 0xadf1
testl %eax, %eax
je 0xe741
leaq 0xc0(%rsp), %rax
movq 0x10(%rax), %rax
testq %rax, %rax
je 0xe70a
leaq 0x785a(%rip), %rcx      # 0x15f61
movq %rcx, (%rax)
xorl %r12d, %r12d
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
sete %al
leaq 0x36(%rsp), %rcx
cmpq %rcx, %rdi
sete %cl
orb %al, %cl
jne 0xe72c
callq 0x3060
movq %r12, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf0(%rsp), %rcx
movq %r13, %rsi
movq 0x58(%rsp), %r12
movq %r14, %rdx
movq 0x60(%rsp), %r13
movq 0xe8(%rsp), %r14
movq %rbp, 0x50(%rsp)
movq %rbx, %r15
movq 0x70(%rsp), %rax
testq %rax, %rax
je 0xe784
movq %rcx, %rdi
movq 0x8(%rcx), %rcx
addq %rcx, %rax
incq %rax
movq %rax, 0x8(%rdi)
cmpq $0x0, 0x48(%rsp)
je 0xe800
movq %r13, %rbx
movq %rdx, %rbp
leaq 0x40(%rsp), %rdi
callq 0x6c0c
testl %eax, %eax
je 0xe800
testq %rbp, %rbp
je 0xe7b6
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x6c0c
testl %eax, %eax
je 0xe800
leaq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x6c0c
testl %eax, %eax
movq %r14, %r13
je 0xe7e8
testq %rbp, %rbp
je 0xe70a
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x6c0c
testl %eax, %eax
jne 0xe70a
movl $0x1, %ebx
cmpl $0x0, 0x30(%rsp)
jne 0xe7fc
movl $0x1bb, 0x30(%rsp)      # imm = 0x1BB
xorl %ebp, %ebp
jmp 0xe817
xorl %ebx, %ebx
movb $0x1, %bpl
cmpl $0x0, 0x30(%rsp)
movq %r14, %r13
jne 0xe817
movl $0x50, 0x30(%rsp)
movq 0x100(%rsp), %r12
movl 0x8(%r12), %ecx
movq (%r12), %r8
movl 0x30(%rsp), %r9d
leaq 0x773e(%rip), %rdx      # 0x15f72
xorl %r12d, %r12d
leaq 0x38(%rsp), %r14
movl $0x2, %esi
movq %r14, %rdi
xorl %eax, %eax
callq 0x7627
cmpq $0x0, (%r14)
je 0xe70d
leaq 0x7724(%rip), %rsi      # 0x15f80
leaq 0x6d47(%rip), %rdx      # 0x155aa
movl $0x3, %edi
callq 0x44b4
testl %eax, %eax
je 0xe889
movq 0x38(%rsp), %rcx
leaq 0x7718(%rip), %rdi      # 0x15f95
movq %r13, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x45a0
testb %bpl, %bpl
movq 0x50(%rsp), %rdi
leaq 0xc0(%rsp), %rcx
je 0xe8e1
movq %r15, %rdx
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 0x8a58
testq %rax, %rax
je 0xe70a
movq %rax, %r12
leaq -0x2d0b(%rip), %rax     # 0xbbc9
movq %rax, 0x80(%r12)
jmp 0xe70d
movq 0x10(%rcx), %rax
testq %rax, %rax
je 0xe70a
leaq 0x76b2(%rip), %rcx      # 0x15fa7
jmp 0xe707