// File: /workspace/github_c_makefile_star2_O3/xiaowenhuyuehu[P]remote_access/src/connectivity/ws_nopoll.c
// Function: ws_nopoll_connect
noPollConn *ws_nopoll_connect(const int debug_on, const char *host, const char *port, const char *get_url, const int tls_on, const char *ca_crt)
{
    noPollCtx  *ctx = NULL;
    noPollConn *conn = NULL;
	noPollConnOpts *opts = NULL;
    nopoll_bool debug = (nopoll_bool)debug_on;
    int i = 0;

    if (NULL == host || NULL == port) {
        log_debug("host or port is NULL ");
        return NULL;
    }

    /* create context */
    ctx = nopoll_ctx_new ();
    nopoll_log_enable (ctx, debug);
    nopoll_log_color_enable (ctx, debug);

    /* check connections registered */
    if (nopoll_ctx_conns(ctx) != 0) {
        log_debug("ERROR: expected to find 0 registered connections but found ");
        return NULL;
    }

    /* call to create a connection */
    if (1 == tls_on) {
    	opts = nopoll_conn_opts_new ();
    	if (NULL == ca_crt) {
            /* disable verification */
            log_debug("set peer verify false ");
            nopoll_conn_opts_ssl_peer_verify (opts, nopoll_false);
    	} else {
            nopoll_conn_opts_set_ssl_certs (opts, NULL, NULL, NULL, ca_crt);
    	}

        conn = nopoll_conn_tls_new (ctx, opts, host, port, NULL, get_url, NULL, NULL);
        if (!nopoll_conn_is_ok (conn)) {
            log_debug("ERROR: Expected to find proper client connection status, but found error.. ");
            nopoll_ctx_unref(ctx);
            return NULL;
        }

        if (!nopoll_conn_is_tls_on (conn)) {
            log_debug("ERROR: expected to find TLS enabled on the connection but found it isn't.. ");
            nopoll_ctx_unref(ctx);
            return NULL;
        }    
    } else {
        conn = nopoll_conn_new (ctx, host, port, NULL, get_url, NULL, NULL);
        if (!nopoll_conn_is_ok (conn)) {
            log_debug("ERROR: Expected to find proper client connection status, but found error.. ");
            nopoll_ctx_unref(ctx);
            return NULL;
        }
    }

    /* wait for ready */
    while (nopoll_true) {
        if (nopoll_conn_is_ready(conn)) {
            break;
        }
        i++;
        if (i > 100) {
            log_debug("ERROR: connection not ready ");
            nopoll_conn_close(conn);
            nopoll_ctx_unref(ctx);
            return NULL;
        }
        nopoll_sleep (100000);
    }

    return conn;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
testq %rsi, %rsi
setne %al
testq %rdx, %rdx
setne %dl
testb %dl, %al
jne 0x2c9c
leaq 0x6382(%rip), %rsi      # 0x9004
leaq 0x63b7(%rip), %rdx      # 0x9040
leaq 0x6419(%rip), %r8       # 0x90a9
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x5d, %ecx
jmp 0x2cf6
movq %r9, %r13
movl %r8d, %ebp
movq %rsi, %r12
movl %edi, %r14d
movq %rcx, 0x10(%rsp)
callq 0x24e0
movq %rax, %rbx
movq %rax, %rdi
movl %r14d, %esi
callq 0x22e0
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2390
movq %rbx, %rdi
callq 0x2590
testl %eax, %eax
je 0x2d0f
leaq 0x6326(%rip), %rsi      # 0x9004
leaq 0x635b(%rip), %rdx      # 0x9040
leaq 0x63d3(%rip), %r8       # 0x90bf
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x68, %ecx
xorl %eax, %eax
callq 0x42c5
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1, %ebp
jne 0x2d37
callq 0x24f0
movq %rax, %rbp
testq %r13, %r13
je 0x2d8e
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r13, %r8
callq 0x21f0
jmp 0x2dbb
movq $0x0, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
movq 0x10(%rsp), %r8
xorl %r9d, %r9d
callq 0x2050
movq %rax, %r14
movq %rax, %rdi
callq 0x2320
testl %eax, %eax
jne 0x2df6
leaq 0x6293(%rip), %rsi      # 0x9004
leaq 0x62c8(%rip), %rdx      # 0x9040
leaq 0x6393(%rip), %r8       # 0x9112
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x86, %ecx
jmp 0x2e6d
leaq 0x626f(%rip), %rsi      # 0x9004
leaq 0x62a4(%rip), %rdx      # 0x9040
leaq 0x6358(%rip), %r8       # 0x90fb
xorl %edi, %edi
movl $0x71, %ecx
xorl %eax, %eax
callq 0x42c5
movq %rbp, %rdi
xorl %esi, %esi
callq 0x2260
xorps %xmm0, %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
movq 0x10(%rsp), %r9
callq 0x2480
movq %rax, %r14
movq %rax, %rdi
callq 0x2320
testl %eax, %eax
je 0x2e2d
movq %r14, %rdi
callq 0x21a0
testl %eax, %eax
je 0x2e4e
movq %r14, %rdi
callq 0x23f0
testl %eax, %eax
jne 0x2cfd
movq %rbx, %r15
movl $0x65, %ebx
decl %ebx
je 0x2e81
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x25b0
movq %r14, %rdi
callq 0x23f0
testl %eax, %eax
je 0x2e0e
jmp 0x2cfd
leaq 0x61d0(%rip), %rsi      # 0x9004
leaq 0x6205(%rip), %rdx      # 0x9040
leaq 0x62d0(%rip), %r8       # 0x9112
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x79, %ecx
jmp 0x2e6d
leaq 0x61af(%rip), %rsi      # 0x9004
leaq 0x61e4(%rip), %rdx      # 0x9040
leaq 0x62fb(%rip), %r8       # 0x915e
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x7f, %ecx
xorl %eax, %eax
callq 0x42c5
movq %rbx, %rdi
callq 0x25e0
jmp 0x2cfd
leaq 0x617c(%rip), %rsi      # 0x9004
leaq 0x61b1(%rip), %rdx      # 0x9040
leaq 0x6314(%rip), %r8       # 0x91aa
xorl %edi, %edi
movl $0x93, %ecx
xorl %eax, %eax
callq 0x42c5
movq %r14, %rdi
callq 0x2060
movq %r15, %rdi
callq 0x25e0
xorl %r14d, %r14d
jmp 0x2cfd