// File: /workspace/github_c_makefile_star2_O3/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 0x6921
movq %rdi, %r14
movq 0x7d47(%rip), %rbx      # 0xe3c8
leaq -0x2b0(%rbp), %rdi
xorl %r12d, %r12d
movl $0x1c0, %edx            # imm = 0x1C0
xorl %esi, %esi
callq 0x42b0
movq 0x78fa(%rip), %rsi      # 0xdf98
movl $0xffff, %edi           # imm = 0xFFFF
callq 0x4530
leaq -0xf0(%rbp), %rdi
movl $0xa8, %edx
xorl %esi, %esi
callq 0x42b0
movq (%r14), %rdi
callq 0x4540
movq %rax, %r15
leaq -0xe8(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
leaq -0x40(%rbp), %rsi
leaq -0x48(%rbp), %r8
movq %rax, %rdi
callq 0x4320
testl %eax, %eax
jne 0x68d4
movq -0x40(%rbp), %rdi
leaq 0x3e69(%rip), %rsi      # 0xa560
callq 0x4380
movl $0xffffffff, -0x2b0(%rbp) # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
leaq 0x7c8d(%rip), %rcx      # 0xe3a0
movq %rcx, -0x2a0(%rbp)
movl $0x7, %ecx
testl %eax, %eax
cmovel %ecx, %r12d
jne 0x674d
movq 0x18(%r14), %rax
movq %rax, -0x198(%rbp)
movq 0x20(%r14), %rax
movq %rax, -0x190(%rbp)
movq 0x10(%r14), %rax
cmpb $0x0, (%rax)
je 0x674d
movq %rax, -0x188(%rbp)
movq %r15, -0x38(%rbp)
movq %rbx, -0x30(%rbp)
leaq -0x2b0(%rbp), %rdi
movq $-0x1, 0x5c(%rdi)
leaq 0x75c5(%rip), %rax      # 0xdd30
movq %rax, 0x18(%rdi)
movl 0x8(%r14), %eax
leal -0x1(%rax), %ecx
cmpl $0x2, %eax
movl $0x1, %edx
cmovll %edx, %ecx
movl %ecx, 0x94(%rdi)
testl %eax, %eax
cmovgl %eax, %edx
movw %dx, 0xf0(%rdi)
movl $0x1000, 0x64(%rdi)     # imm = 0x1000
callq 0x4650
movq 0x7822(%rip), %rcx      # 0xdfc8
movq %rax, (%rcx)
testq %rax, %rax
je 0x68e9
leaq -0xf0(%rbp), %r15
movq %rax, (%r15)
movl %r12d, 0x14(%r15)
movq 0x8(%r15), %rax
movq %rax, 0x20(%r15)
movq %rax, 0x28(%r15)
leaq 0x3dab(%rip), %rax      # 0xa57e
movq %rax, 0x18(%r15)
movq 0x28(%r14), %rax
testq %rax, %rax
leaq 0x3bdc(%rip), %rcx      # 0xa3c1
cmovneq %rax, %rcx
movq %rcx, 0x30(%r15)
movl $0xffffffff, 0x38(%r15) # imm = 0xFFFFFFFF
movq 0x77f4(%rip), %rbx      # 0xdff0
movq 0x7765(%rip), %r13      # 0xdf68
leaq 0x3d77(%rip), %r14      # 0xa581
leaq 0x3d8a(%rip), %r12      # 0xa59b
cmpl $0x0, (%rbx)
jne 0x686f
cmpq $0x0, (%r13)
jne 0x6857
movl $0x4, %edi
movq %r14, %rsi
xorl %eax, %eax
callq 0x4230
movq %r13, -0x78(%rbp)
movq %r15, %rdi
callq 0x4130
movq (%r13), %rdx
movl $0x4, %edi
movq %r12, %rsi
xorl %eax, %eax
callq 0x4230
movl $0x1, %edi
callq 0x41c0
jmp 0x6811
movq 0x776a(%rip), %rax      # 0xdfc8
movq (%rax), %rdi
movl $0x64, %esi
callq 0x4510
testl %eax, %eax
jns 0x6811
movq 0x7752(%rip), %rbx      # 0xdfc8
movq (%rbx), %rdi
callq 0x4660
xorl %eax, %eax
movq %rax, (%rbx)
movq %rax, (%r13)
leaq 0x3d2d(%rip), %rsi      # 0xa5bb
movl $0x4, %edi
xorl %eax, %eax
callq 0x4230
movq -0x30(%rbp), %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x68b2
callq 0x46d0
movq $0x0, (%rbx)
movq -0x38(%rbp), %rdi
callq 0x46d0
callq 0x4060
xorl %eax, %eax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3c71(%rip), %rsi      # 0xa54c
movl $0x4, %edi
xorl %eax, %eax
callq 0x4230
jmp 0x6921
leaq 0x3c74(%rip), %rsi      # 0xa564
movl $0x1, %edi
xorl %eax, %eax
callq 0x4230
movq -0x38(%rbp), %rdi
callq 0x46d0
movq -0x30(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6921
callq 0x46d0
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
xorl %edi, %edi
callq 0x45d0