// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0xc(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
xorl %eax, %eax
cmpq -0x18(%rbp), %rax
je 0x2f64
xorl %eax, %eax
cmpq -0x20(%rbp), %rax
jne 0x2f94
xorl %edi, %edi
leaq 0x8097(%rip), %rsi      # 0xb004
leaq 0x80cc(%rip), %rdx      # 0xb040
movl $0x5d, %ecx
leaq 0x8129(%rip), %r8       # 0xb0a9
movb $0x0, %al
callq 0x4f90
movq $0x0, -0x8(%rbp)
jmp 0x31ff
callq 0x24d0
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x22d0
movq -0x40(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x2370
movq -0x40(%rbp), %rdi
callq 0x2580
cmpl $0x0, %eax
je 0x2ff3
xorl %edi, %edi
leaq 0x8038(%rip), %rsi      # 0xb004
leaq 0x806d(%rip), %rdx      # 0xb040
movl $0x68, %ecx
leaq 0x80e0(%rip), %r8       # 0xb0bf
movb $0x0, %al
callq 0x4f90
movq $0x0, -0x8(%rbp)
jmp 0x31ff
movl $0x1, %eax
cmpl -0x2c(%rbp), %eax
jne 0x311c
callq 0x24e0
movq %rax, -0x50(%rbp)
xorl %eax, %eax
cmpq -0x38(%rbp), %rax
jne 0x3042
xorl %edi, %edi
leaq 0x7fe9(%rip), %rsi      # 0xb004
leaq 0x801e(%rip), %rdx      # 0xb040
movl $0x71, %ecx
leaq 0x80cd(%rip), %r8       # 0xb0fb
movb $0x0, %al
callq 0x4f90
movq -0x50(%rbp), %rdi
xorl %esi, %esi
callq 0x2250
jmp 0x3059
movq -0x50(%rbp), %rdi
movq -0x38(%rbp), %r8
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rsi
movq %rcx, %rdx
callq 0x21e0
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %r9
xorl %eax, %eax
movl %eax, %r8d
movq $0x0, (%rsp)
movq $0x0, 0x8(%rsp)
callq 0x2470
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2310
cmpl $0x0, %eax
jne 0x30d3
xorl %edi, %edi
leaq 0x7f61(%rip), %rsi      # 0xb004
leaq 0x7f96(%rip), %rdx      # 0xb040
movl $0x79, %ecx
leaq 0x805c(%rip), %r8       # 0xb112
movb $0x0, %al
callq 0x4f90
movq -0x40(%rbp), %rdi
callq 0x25d0
movq $0x0, -0x8(%rbp)
jmp 0x31ff
movq -0x48(%rbp), %rdi
callq 0x2190
cmpl $0x0, %eax
jne 0x311a
xorl %edi, %edi
leaq 0x7f1a(%rip), %rsi      # 0xb004
leaq 0x7f4f(%rip), %rdx      # 0xb040
movl $0x7f, %ecx
leaq 0x8061(%rip), %r8       # 0xb15e
movb $0x0, %al
callq 0x4f90
movq -0x40(%rbp), %rdi
callq 0x25d0
movq $0x0, -0x8(%rbp)
jmp 0x31ff
jmp 0x318b
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rcx
movq $0x0, (%rsp)
callq 0x2050
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2310
cmpl $0x0, %eax
jne 0x3189
xorl %edi, %edi
leaq 0x7ea8(%rip), %rsi      # 0xb004
leaq 0x7edd(%rip), %rdx      # 0xb040
movl $0x86, %ecx
leaq 0x7fa3(%rip), %r8       # 0xb112
movb $0x0, %al
callq 0x4f90
movq -0x40(%rbp), %rdi
callq 0x25d0
movq $0x0, -0x8(%rbp)
jmp 0x31ff
jmp 0x318b
jmp 0x318d
movq -0x48(%rbp), %rdi
callq 0x23d0
cmpl $0x0, %eax
je 0x319d
jmp 0x31f7
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
cmpl $0x64, -0x58(%rbp)
jle 0x31eb
xorl %edi, %edi
leaq 0x7e4f(%rip), %rsi      # 0xb004
leaq 0x7e84(%rip), %rdx      # 0xb040
movl $0x93, %ecx
leaq 0x7fe2(%rip), %r8       # 0xb1aa
movb $0x0, %al
callq 0x4f90
movq -0x48(%rbp), %rdi
callq 0x2060
movq -0x40(%rbp), %rdi
callq 0x25d0
movq $0x0, -0x8(%rbp)
jmp 0x31ff
movl $0x186a0, %edi          # imm = 0x186A0
callq 0x25a0
jmp 0x318d
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)