// File: /workspace/github_c_makefile_star2_O0/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
subq $0x360, %rsp            # imm = 0x360
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x278(%rbp)
leaq -0x300(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x4300
movl $0x0, -0x304(%rbp)
movl $0xffffffff, -0x308(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x30c(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x310(%rbp)
movl $0x0, -0x314(%rbp)
movl $0x0, -0x318(%rbp)
movl $0xffff, -0x31c(%rbp)   # imm = 0xFFFF
movq 0xb18e(%rip), %rax      # 0x12488
movq %rax, -0x338(%rbp)
cmpq $0x0, -0x278(%rbp)
jne 0x7312
xorl %edi, %edi
callq 0x4670
leaq -0x1c8(%rbp), %rdi
xorl %esi, %esi
movl $0x1c0, %edx            # imm = 0x1C0
callq 0x4300
movl -0x31c(%rbp), %edi
movq 0xac66(%rip), %rsi      # 0x11f98
callq 0x45c0
leaq -0x270(%rbp), %rdi
xorl %esi, %esi
movl $0xa8, %edx
callq 0x4300
movq -0x278(%rbp), %rax
movq (%rax), %rdi
callq 0x45d0
movq %rax, -0x340(%rbp)
movq -0x340(%rbp), %rdi
leaq -0x270(%rbp), %rdx
addq $0x8, %rdx
leaq -0x270(%rbp), %rcx
addq $0x10, %rcx
leaq -0x328(%rbp), %rsi
leaq -0x330(%rbp), %r8
callq 0x4370
cmpl $0x0, %eax
je 0x73af
movl $0x4, %edi
leaq 0x71b3(%rip), %rsi      # 0xe554
movb $0x0, %al
callq 0x4280
xorl %edi, %edi
callq 0x4670
movq -0x328(%rbp), %rdi
leaq 0x70e4(%rip), %rsi      # 0xe4a1
callq 0x43c0
cmpl $0x0, %eax
jne 0x73d1
movl $0x7, -0x310(%rbp)
movl $0xffffffff, -0x1c8(%rbp) # imm = 0xFFFFFFFF
movq -0x338(%rbp), %rax
movq $0x0, (%rax)
movq -0x338(%rbp), %rax
movq $0x0, 0x8(%rax)
leaq 0xb061(%rip), %rax      # 0x12460
movq %rax, -0x1b8(%rbp)
cmpl $0x0, -0x310(%rbp)
je 0x7457
movq -0x278(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0xb0(%rbp)
movq -0x278(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x278(%rbp), %rax
movq 0x10(%rax), %rax
cmpb $0x0, (%rax)
je 0x7455
movq -0x278(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xa0(%rbp)
jmp 0x7457
movl -0x30c(%rbp), %eax
movl %eax, -0x16c(%rbp)
movl -0x308(%rbp), %eax
movl %eax, -0x168(%rbp)
leaq 0xa8ea(%rip), %rax      # 0x11d60
movq %rax, -0x1b0(%rbp)
movq -0x278(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jle 0x749f
movq -0x278(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x344(%rbp)
jmp 0x74ac
movl $0x1, %eax
movl %eax, -0x344(%rbp)
jmp 0x74ac
movl -0x344(%rbp), %eax
movl %eax, -0x134(%rbp)
movq -0x278(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jl 0x74d7
movq -0x278(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x348(%rbp)
jmp 0x74e4
movl $0x1, %eax
movl %eax, -0x348(%rbp)
jmp 0x74e4
movl -0x348(%rbp), %eax
movw %ax, -0xd8(%rbp)
movl -0x164(%rbp), %eax
orl $0x1000, %eax           # imm = 0x1000
movl %eax, -0x164(%rbp)
leaq -0x1c8(%rbp), %rdi
callq 0x4720
movq %rax, %rcx
movq 0xaab0(%rip), %rax      # 0x11fc8
movq %rcx, (%rax)
movq 0xaaa6(%rip), %rax      # 0x11fc8
cmpq $0x0, (%rax)
jne 0x7578
movl $0x1, %edi
leaq 0x7034(%rip), %rsi      # 0xe568
movb $0x0, %al
callq 0x4280
movq -0x340(%rbp), %rdi
callq 0x4790
movq -0x338(%rbp), %rax
cmpq $0x0, (%rax)
je 0x7571
movq -0x338(%rbp), %rax
movq (%rax), %rdi
callq 0x4790
movq -0x338(%rbp), %rax
movq $0x0, (%rax)
xorl %edi, %edi
callq 0x4670
movq 0xaa49(%rip), %rax      # 0x11fc8
movq (%rax), %rax
movq %rax, -0x270(%rbp)
movl -0x310(%rbp), %eax
movl %eax, -0x25c(%rbp)
movq -0x268(%rbp), %rax
movq %rax, -0x250(%rbp)
movq -0x268(%rbp), %rax
movq %rax, -0x248(%rbp)
leaq 0x6fca(%rip), %rax      # 0xe582
movq %rax, -0x258(%rbp)
movq -0x278(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x75dd
leaq 0x6ded(%rip), %rax      # 0xe3c1
movq %rax, -0x350(%rbp)
jmp 0x75ef
movq -0x278(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x350(%rbp)
movq -0x350(%rbp), %rax
movq %rax, -0x240(%rbp)
movl $0xffffffff, -0x238(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x318(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x318(%rbp)
movb %al, -0x351(%rbp)
jl 0x7639
movq 0xa9c7(%rip), %rax      # 0x11ff0
movl (%rax), %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
movb %al, -0x351(%rbp)
movb -0x351(%rbp), %al
testb $0x1, %al
jne 0x7648
jmp 0x76cd
movq 0xa919(%rip), %rax      # 0x11f68
cmpq $0x0, (%rax)
jne 0x76ae
movl $0x4, %edi
leaq 0x6f24(%rip), %rsi      # 0xe585
movb $0x0, %al
callq 0x4280
movq 0xa8f9(%rip), %rax      # 0x11f68
movq %rax, -0x1f8(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x4170
movq 0xa8df(%rip), %rax      # 0x11f68
movq (%rax), %rdx
movl $0x4, %edi
leaq 0x6f07(%rip), %rsi      # 0xe59f
movb $0x0, %al
callq 0x4280
movl $0x1, %edi
callq 0x4200
jmp 0x7611
movq 0xa913(%rip), %rax      # 0x11fc8
movq (%rax), %rdi
movl $0x64, %esi
callq 0x45a0
movl %eax, -0x318(%rbp)
jmp 0x7611
movq 0xa8f4(%rip), %rax      # 0x11fc8
movq (%rax), %rdi
callq 0x4730
movq 0xa8e5(%rip), %rax      # 0x11fc8
movq $0x0, (%rax)
movq 0xa877(%rip), %rax      # 0x11f68
movq $0x0, (%rax)
movl $0x4, %edi
leaq 0x6ebb(%rip), %rsi      # 0xe5bf
movb $0x0, %al
callq 0x4280
movq -0x338(%rbp), %rax
cmpq $0x0, (%rax)
je 0x7735
movq -0x338(%rbp), %rax
movq (%rax), %rdi
callq 0x4790
movq -0x338(%rbp), %rax
movq $0x0, (%rax)
movq -0x340(%rbp), %rdi
callq 0x4790
callq 0x4070
xorl %eax, %eax
addq $0x360, %rsp            # imm = 0x360
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)