// File: /workspace/github_c_makefile_star2_O1/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 0x2c90
leaq 0x638e(%rip), %rsi      # 0x9004
leaq 0x63c3(%rip), %rdx      # 0x9040
leaq 0x6425(%rip), %r8       # 0x90a9
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x5d, %ecx
jmp 0x2cea
movq %r9, %r13
movl %r8d, %ebp
movq %rsi, %r12
movl %edi, %r14d
movq %rcx, 0x10(%rsp)
callq 0x24d0
movq %rax, %rbx
movq %rax, %rdi
movl %r14d, %esi
callq 0x22e0
movq %rbx, %rdi
movl %r14d, %esi
callq 0x2390
movq %rbx, %rdi
callq 0x2580
testl %eax, %eax
je 0x2d03
leaq 0x6332(%rip), %rsi      # 0x9004
leaq 0x6367(%rip), %rdx      # 0x9040
leaq 0x63df(%rip), %r8       # 0x90bf
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x68, %ecx
xorl %eax, %eax
callq 0x4371
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1, %ebp
jne 0x2d2b
callq 0x24e0
movq %rax, %rbp
testq %r13, %r13
je 0x2d82
movq %rbp, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r13, %r8
callq 0x21f0
jmp 0x2daf
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 0x2dea
leaq 0x629f(%rip), %rsi      # 0x9004
leaq 0x62d4(%rip), %rdx      # 0x9040
leaq 0x639f(%rip), %r8       # 0x9112
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x86, %ecx
jmp 0x2e61
leaq 0x627b(%rip), %rsi      # 0x9004
leaq 0x62b0(%rip), %rdx      # 0x9040
leaq 0x6364(%rip), %r8       # 0x90fb
xorl %edi, %edi
movl $0x71, %ecx
xorl %eax, %eax
callq 0x4371
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 0x2e21
movq %r14, %rdi
callq 0x21a0
testl %eax, %eax
je 0x2e42
movq %r14, %rdi
callq 0x23f0
testl %eax, %eax
jne 0x2cf1
movq %rbx, %r15
movl $0x65, %ebx
decl %ebx
je 0x2e75
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x25a0
movq %r14, %rdi
callq 0x23f0
testl %eax, %eax
je 0x2e02
jmp 0x2cf1
leaq 0x61dc(%rip), %rsi      # 0x9004
leaq 0x6211(%rip), %rdx      # 0x9040
leaq 0x62dc(%rip), %r8       # 0x9112
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x79, %ecx
jmp 0x2e61
leaq 0x61bb(%rip), %rsi      # 0x9004
leaq 0x61f0(%rip), %rdx      # 0x9040
leaq 0x6307(%rip), %r8       # 0x915e
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x7f, %ecx
xorl %eax, %eax
callq 0x4371
movq %rbx, %rdi
callq 0x25d0
jmp 0x2cf1
leaq 0x6188(%rip), %rsi      # 0x9004
leaq 0x61bd(%rip), %rdx      # 0x9040
leaq 0x6320(%rip), %r8       # 0x91aa
xorl %edi, %edi
movl $0x93, %ecx
xorl %eax, %eax
callq 0x4371
movq %r14, %rdi
callq 0x2060
movq %r15, %rdi
callq 0x25d0
xorl %r14d, %r14d
jmp 0x2cf1