// File: /workspace/github_c_makefile_star2_O2/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, %r13
movq %rsi, %rbx
movq %rdi, %rbp
movq 0x100(%rsp), %r14
movq 0xf8(%rsp), %rdi
leaq 0x30(%rsp), %r15
andl $0x0, (%r15)
movq 0x108(%rsp), %r12
leaq 0x36(%rsp), %rax
movq %rax, 0x38(%rsp)
callq 0x6875
leaq 0x88(%rsp), %rcx
movq %rcx, 0x10(%rsp)
leaq 0x78(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movq %r14, (%rsp)
leaq 0x40(%rsp), %rcx
movq %rax, %rdi
movq %rdx, %rsi
movq %rcx, %rdx
movq %r12, %rcx
movq 0x110(%rsp), %r12
movq %r12, %r8
movq %r15, %r9
callq 0xa4b2
testl %eax, %eax
je 0xd891
leaq 0xd0(%rsp), %rax
movq 0x10(%rax), %rax
testq %rax, %rax
je 0xd85a
leaq 0x770e(%rip), %rcx      # 0x14f65
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 0xd87c
callq 0x3060
movq %r12, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x100(%rsp), %rcx
movq %r13, %rsi
movq 0x68(%rsp), %r15
movq 0x60(%rsp), %rdx
movq 0x70(%rsp), %r13
movq 0xf8(%rsp), %r14
movq %rbp, 0x58(%rsp)
movq %rbx, 0x50(%rsp)
movq 0x80(%rsp), %rax
testq %rax, %rax
je 0xd8db
movq %rcx, %rdi
movq 0x8(%rcx), %rcx
addq %rcx, %rax
incq %rax
movq %rax, 0x8(%rdi)
cmpq $0x0, 0x48(%rsp)
je 0xd95e
movq %r13, %rbx
movq %rdx, %rbp
leaq 0x40(%rsp), %rdi
callq 0x6899
testl %eax, %eax
je 0xd95e
testq %rbp, %rbp
je 0xd90d
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x6899
testl %eax, %eax
je 0xd95e
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x6899
testl %eax, %eax
movq %r14, %r13
je 0xd93f
testq %rbp, %rbp
je 0xd85a
leaq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x6899
testl %eax, %eax
jne 0xd85a
movl 0x30(%rsp), %r9d
pushq $0x1
popq %rbx
testl %r9d, %r9d
jne 0xd95a
movl $0x1bb, 0x30(%rsp)      # imm = 0x1BB
movl $0x1bb, %r9d            # imm = 0x1BB
xorl %ebp, %ebp
jmp 0xd97c
movl 0x30(%rsp), %r9d
xorl %ebx, %ebx
movb $0x1, %bpl
testl %r9d, %r9d
movq %r14, %r13
jne 0xd97c
movl $0x50, 0x30(%rsp)
pushq $0x50
popq %r9
movl 0x8(%r12), %ecx
movq (%r12), %r8
leaq 0x75ea(%rip), %rdx      # 0x14f76
xorl %r12d, %r12d
leaq 0x38(%rsp), %r14
pushq $0x2
popq %rsi
movq %r14, %rdi
xorl %eax, %eax
callq 0x71ab
cmpq $0x0, (%r14)
je 0xd85d
leaq 0x75d2(%rip), %rsi      # 0x14f84
leaq 0x6bf5(%rip), %rdx      # 0x145ae
pushq $0x3
popq %rdi
callq 0x4227
testl %eax, %eax
je 0xd9dd
movq 0x38(%rsp), %rcx
leaq 0x75c8(%rip), %rdi      # 0x14f99
movq %r13, %rsi
movl %ebx, %edx
xorl %eax, %eax
callq 0x430a
testb %bpl, %bpl
movq 0x50(%rsp), %rdx
movq 0x58(%rsp), %rdi
leaq 0xd0(%rsp), %rcx
je 0xda37
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 0x846b
testq %rax, %rax
je 0xd85a
movq %rax, %r12
leaq -0x28f1(%rip), %rax     # 0xb139
movq %rax, 0x80(%r12)
jmp 0xd85d
movq 0x10(%rcx), %rax
testq %rax, %rax
je 0xd85a
leaq 0x7560(%rip), %rcx      # 0x14fab
jmp 0xd857