// File: /workspace/github_c_makefile_star2_O2/back1127[P]linkedge-thing-access-websocket_client_sdk/sdk/ali_ws/ws_client_network.c
// Function: thread_wsc_network
void *thread_wsc_network(void *arg)
{
    struct lws_context_creation_info info;
    struct lws_client_connect_info i;
    p_wsc_param_conn param = (p_wsc_param_conn)arg;
    char interface_name[128] = "";
    unsigned int oldms = 0;
    int uid = -1, gid = -1;
    int use_ssl = 0;
    int opts = 0;
    int n = 0;
    int debug_level = 0xffff;
    const char *prot, *p;
    wsc_recv_tmpInfo * pTmp = (wsc_recv_tmpInfo *)(protocols[0].user);

    if (!param) {
        exit(0);
    }

    memset(&info, 0, sizeof info);
    lws_set_log_level(debug_level, alog_print);

    memset(&i, 0, sizeof(i));
    char *url = os_strdup(param->url);
    if (lws_parse_uri(url, &prot, &i.address, &i.port, &p)) {
        lwsl_notice("url is not correct\n"); 
        exit(0);
    }
    if (strcmp(prot, "wss") == 0) {
        use_ssl = LCCSCF_USE_SSL |
                  LCCSCF_ALLOW_SELFSIGNED |
                  LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK;
    }
    info.port = CONTEXT_PORT_NO_LISTEN;
    pTmp->appendBuffer = NULL;
    pTmp->totalLen = 0;
    info.protocols = protocols;
    if (use_ssl) {
        info.client_ssl_cert_filepath = param->cert_path;
        info.client_ssl_private_key_filepath = param->key_path;
        if (param->ca_path[0]) {
            info.client_ssl_ca_filepath = param->ca_path;
        }
    }
    info.gid = gid;
    info.uid = uid;
    info.extensions = exts;
    info.timeout_secs = (param->timeout > 1) ? (param->timeout - 1) : 1;
    info.ws_ping_pong_interval = (param->timeout >= 1) ? param->timeout : 1;

#if defined(LWS_OPENSSL_SUPPORT)
    info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
#endif
    context = lws_create_context(&info);
    if (context == NULL) {
        lwsl_err("libwebsocket init failed\n");
        free(url);
        if(pTmp->appendBuffer != NULL){
                free(pTmp->appendBuffer);
                pTmp->appendBuffer = NULL;
        } 
        exit(0);
    }

    i.context = context;
    i.ssl_connection = use_ssl;
    i.host = i.address;
    i.origin = i.address;
    i.path = "//";
    i.protocol = !param->protocol ? DEFAULT_LWS_PROTOCOL : param->protocol;
    i.ietf_version_or_minus_one = -1;
    n = 0;
    while (n >= 0 && !force_exit) {
        if (!g_wsi) {
            lwsl_notice("connecting to server....\n");
            i.pwsi = &g_wsi;
            lws_client_connect_via_info(&i);
            lwsl_notice("connecting to server done, %p.\n", g_wsi);
			os_sleep(1);
            continue;
        }

        n = lws_service(context, 100);
    }
    
    lws_context_destroy(context);
    context = NULL;
    g_wsi = NULL;
    lwsl_notice("libwebsockets-test-client exited cleanly\n");

    if(pTmp->appendBuffer != NULL){
            free(pTmp->appendBuffer);
            pTmp->appendBuffer = NULL;
    } 

    free(url);
#ifndef _WIN32
    closelog();
#endif
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
testq %rdi, %rdi
je 0x6882
movq %rdi, %r14
movq 0x7e07(%rip), %r15      # 0xe408
leaq -0x2b0(%rbp), %rdi
xorl %ebx, %ebx
movl $0x1c0, %edx            # imm = 0x1C0
xorl %esi, %esi
callq 0x42e0
movq 0x797b(%rip), %rsi      # 0xdf98
movl $0xffff, %edi           # imm = 0xFFFF
callq 0x4590
leaq -0xf0(%rbp), %rdi
movl $0xa8, %edx
xorl %esi, %esi
callq 0x42e0
movq (%r14), %rdi
callq 0x45a0
movq %rax, %r12
leaq -0xe8(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
leaq -0x40(%rbp), %rsi
leaq -0x48(%rbp), %r8
movq %rax, %rdi
callq 0x4350
testl %eax, %eax
jne 0x683c
movq -0x40(%rbp), %rdi
leaq 0x3eea(%rip), %rsi      # 0xa560
callq 0x43b0
orl $-0x1, -0x2b0(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
leaq 0x7d50(%rip), %rcx      # 0xe3e0
movq %rcx, -0x2a0(%rbp)
pushq $0x7
popq %rcx
testl %eax, %eax
cmovel %ecx, %ebx
jne 0x66c7
movq 0x18(%r14), %rax
movq %rax, -0x198(%rbp)
movq 0x20(%r14), %rax
movq %rax, -0x190(%rbp)
movq 0x10(%r14), %rax
cmpb $0x0, (%rax)
je 0x66c7
movq %rax, -0x188(%rbp)
movq %r12, -0x38(%rbp)
movq %r15, -0x30(%rbp)
leaq -0x2b0(%rbp), %rdi
orq $-0x1, 0x5c(%rdi)
leaq 0x764e(%rip), %rax      # 0xdd30
movq %rax, 0x18(%rdi)
movl 0x8(%r14), %eax
leal -0x1(%rax), %ecx
cmpl $0x2, %eax
pushq $0x1
popq %rdx
cmovll %edx, %ecx
movl %ecx, 0x94(%rdi)
testl %eax, %eax
cmovgl %eax, %edx
movw %dx, 0xf0(%rdi)
movl $0x1000, 0x64(%rdi)     # imm = 0x1000
callq 0x46d0
movq 0x78ad(%rip), %rcx      # 0xdfc8
movq %rax, (%rcx)
testq %rax, %rax
je 0x684f
leaq -0xf0(%rbp), %r15
movq %rax, (%r15)
movl %ebx, 0x14(%r15)
movq 0x8(%r15), %rax
movq %rax, 0x20(%r15)
movq %rax, 0x28(%r15)
leaq 0x3e36(%rip), %rax      # 0xa57e
movq %rax, 0x18(%r15)
movq 0x28(%r14), %rax
testq %rax, %rax
leaq 0x3c67(%rip), %rcx      # 0xa3c1
cmovneq %rax, %rcx
movq %rcx, 0x30(%r15)
orl $-0x1, 0x38(%r15)
movq 0x7882(%rip), %r13      # 0xdff0
movq 0x77f3(%rip), %r14      # 0xdf68
pushq $0x4
popq %r12
pushq $0x1
popq %rbx
xorl %eax, %eax
testl %eax, %eax
js 0x67dd
cmpl $0x0, (%r13)
jne 0x67dd
cmpq $0x0, (%r14)
jne 0x67c9
movl %r12d, %edi
leaq 0x3de8(%rip), %rsi      # 0xa581
xorl %eax, %eax
callq 0x4260
movq %r14, -0x78(%rbp)
movq %r15, %rdi
callq 0x4160
movq (%r14), %rdx
movl %r12d, %edi
leaq 0x3de2(%rip), %rsi      # 0xa59b
xorl %eax, %eax
callq 0x4260
movl %ebx, %edi
callq 0x41f0
jmp 0x6782
movq 0x77f8(%rip), %rax      # 0xdfc8
movq (%rax), %rdi
pushq $0x64
popq %rsi
callq 0x4570
jmp 0x677e
movq 0x77e4(%rip), %rbx      # 0xdfc8
movq (%rbx), %rdi
callq 0x46e0
andq $0x0, (%rbx)
andq $0x0, (%r14)
leaq 0x3dc0(%rip), %rsi      # 0xa5bb
pushq $0x4
popq %rdi
xorl %eax, %eax
callq 0x4260
movq -0x30(%rbp), %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x681a
callq 0x4750
andq $0x0, (%rbx)
movq -0x38(%rbp), %rdi
callq 0x4750
callq 0x4070
xorl %eax, %eax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3d09(%rip), %rsi      # 0xa54c
pushq $0x4
popq %rdi
xorl %eax, %eax
callq 0x4260
jmp 0x6882
leaq 0x3d0e(%rip), %rsi      # 0xa564
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x4260
movq -0x38(%rbp), %rdi
callq 0x4750
movq -0x30(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6882
callq 0x4750
movq -0x30(%rbp), %rax
andq $0x0, (%rax)
xorl %edi, %edi
callq 0x4630
nopl (%rax)