// File: /workspace/github_c_makefile_star2_O1/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 0x6914
movq %rdi, %r14
movq 0x8d4b(%rip), %rbx      # 0xf3b8
leaq -0x2b0(%rbp), %rdi
xorl %r12d, %r12d
movl $0x1c0, %edx            # imm = 0x1C0
xorl %esi, %esi
callq 0x42b0
movq 0x890e(%rip), %rsi      # 0xef98
movl $0xffff, %edi           # imm = 0xFFFF
callq 0x4500
leaq -0xf0(%rbp), %rdi
movl $0xa8, %edx
xorl %esi, %esi
callq 0x42b0
movq (%r14), %rdi
callq 0x4510
movq %rax, %r15
leaq -0xe8(%rbp), %rdx
leaq -0xe0(%rbp), %rcx
leaq -0x40(%rbp), %rsi
leaq -0x48(%rbp), %r8
movq %rax, %rdi
callq 0x4310
testl %eax, %eax
jne 0x68c7
movq -0x40(%rbp), %rdi
leaq 0x4d92(%rip), %rsi      # 0xb475
callq 0x4360
movl $0xffffffff, -0x2b0(%rbp) # imm = 0xFFFFFFFF
xorps %xmm0, %xmm0
movups %xmm0, (%rbx)
leaq 0x8c91(%rip), %rcx      # 0xf390
movq %rcx, -0x2a0(%rbp)
movl $0x7, %ecx
testl %eax, %eax
cmovel %ecx, %r12d
jne 0x6739
movq 0x18(%r14), %rax
movq %rax, -0x198(%rbp)
movq 0x20(%r14), %rax
movq %rax, -0x190(%rbp)
movq 0x10(%r14), %rax
cmpb $0x0, (%rax)
je 0x6739
movq %rax, -0x188(%rbp)
movq %r15, -0x38(%rbp)
movq %rbx, -0x30(%rbp)
leaq -0x2b0(%rbp), %rdi
movq $-0x1, 0x5c(%rdi)
leaq 0x85d9(%rip), %rax      # 0xed30
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)
orb $0x10, 0x65(%rdi)
callq 0x4630
movq 0x8839(%rip), %rcx      # 0xefc8
movq %rax, (%rcx)
testq %rax, %rax
je 0x68dc
leaq -0xf0(%rbp), %r15
movq %rax, (%r15)
movl %r12d, 0x14(%r15)
movq 0x8(%r15), %rax
movq %rax, 0x20(%r15)
movq %rax, 0x28(%r15)
leaq 0x4dc2(%rip), %rax      # 0xb57e
movq %rax, 0x18(%r15)
movq 0x28(%r14), %rax
testq %rax, %rax
leaq 0x4bf3(%rip), %rcx      # 0xb3c1
cmovneq %rax, %rcx
movq %rcx, 0x30(%r15)
movl $0xffffffff, 0x38(%r15) # imm = 0xFFFFFFFF
movb $0x1, %r14b
movq 0x8808(%rip), %rbx      # 0xeff0
movq 0x8779(%rip), %r13      # 0xef68
leaq 0x4da5(%rip), %r12      # 0xb59b
cmpl $0x0, (%rbx)
jne 0x6862
cmpq $0x0, (%r13)
jne 0x6846
movl $0x4, %edi
leaq 0x4d73(%rip), %rsi      # 0xb581
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
testb $0x1, %r14b
jne 0x67f6
jmp 0x6862
movq 0x877b(%rip), %rax      # 0xefc8
movq (%rax), %rdi
movl $0x64, %esi
callq 0x44e0
testl %eax, %eax
setns %r14b
jns 0x67f6
movq 0x875f(%rip), %rbx      # 0xefc8
movq (%rbx), %rdi
callq 0x4640
xorl %eax, %eax
movq %rax, (%rbx)
movq %rax, (%r13)
leaq 0x4d3a(%rip), %rsi      # 0xb5bb
movl $0x4, %edi
xorl %eax, %eax
callq 0x4230
movq -0x30(%rbp), %rbx
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x68a5
callq 0x46b0
movq $0x0, (%rbx)
movq -0x38(%rbp), %rdi
callq 0x46b0
callq 0x4060
xorl %eax, %eax
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4c82(%rip), %rsi      # 0xb550
movl $0x4, %edi
xorl %eax, %eax
callq 0x4230
jmp 0x6914
leaq 0x4c81(%rip), %rsi      # 0xb564
movl $0x1, %edi
xorl %eax, %eax
callq 0x4230
movq -0x38(%rbp), %rdi
callq 0x46b0
movq -0x30(%rbp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6914
callq 0x46b0
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
xorl %edi, %edi
callq 0x45a0
nop