// File: /workspace/github_c_makefile_star2_O1/back1127[P]linkedge-thing-access-websocket_client_sdk/sdk/leda.c
// Function: leda_wsc_init
int leda_wsc_init(const leda_conn_info_t *info)
{
    int ret = 0;
    int timeout;
    wsc_param_conn param_conn = {0};
    wsc_param_cb   param_cbs = {0};

    if (g_is_init == 1) {
        return 0;
    }

    g_threadpool_recv_proc = threadpool_create(5, 5*1024, 0);

    g_conn_cb.conn_state_change_cb = info->ws_conn_cb.conn_state_change_cb;
    g_conn_cb.usr_data = info->ws_conn_cb.usr_data;
    g_devs_cb.get_properties_cb = info->conn_devices_cb.get_properties_cb;
    g_devs_cb.usr_data_get_property = info->conn_devices_cb.usr_data_get_property;
    g_devs_cb.set_properties_cb = info->conn_devices_cb.set_properties_cb;
    g_devs_cb.usr_data_set_property = info->conn_devices_cb.usr_data_set_property;
    g_devs_cb.call_service_cb = info->conn_devices_cb.call_service_cb;
    g_devs_cb.usr_data_call_service = info->conn_devices_cb.usr_data_call_service;
    g_devs_cb.service_output_max_count = info->conn_devices_cb.service_output_max_count;
    
    g_conn_state = -1;
    param_conn.url = info->url;
    param_conn.ca_path = info->ca_path;
    param_conn.cert_path = info->cert_path;
    param_conn.key_path = info->key_path;

    param_conn.timeout = info->timeout;
    param_conn.protocol = CONN_PROTOCOL;

    param_cbs.p_cb_establish = cb_ws_estab;
    param_cbs.p_cb_close = cb_ws_close;
    param_cbs.p_cb_recv = cb_ws_recv;

    ret = wsc_init(&param_conn, &param_cbs);

    if (ret != 0) {
        return ret;
    }
    timeout = info->timeout;
    while (--timeout > 0) {
        os_sleep(1);
        if (g_conn_state == LEDA_WS_CONNECTED) {
            break;
        } else if (g_conn_state == LEDA_WS_DISCONNECTED) {
            return LE_ERROR_UNKNOWN;
        } else {
            log_i(LOG_TAG, "connecting to remote server\n");
        }
    }

    pthread_mutex_init(&wsa_replay_lock, NULL);

    if (g_conn_state < 0) {
        ws_client_destroy();
        return LE_ERROR_TIMEOUT;
    }
    
    g_is_init = 1;
    return LE_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
xorps %xmm0, %xmm0
movaps %xmm0, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
xorl %r14d, %r14d
cmpb $0x0, 0x9737(%rip)      # 0xf4bc
jne 0x5f2a
movq %rdi, %rbx
movl $0x5, %edi
movl $0x1400, %esi           # imm = 0x1400
xorl %edx, %edx
callq 0x4550
movq 0x91e2(%rip), %rcx      # 0xef88
movq %rax, (%rcx)
movq 0x28(%rbx), %rax
movq %rax, 0x970c(%rip)      # 0xf4c0
movq 0x30(%rbx), %rax
movq %rax, 0x9709(%rip)      # 0xf4c8
movq 0x38(%rbx), %rax
movq %rax, 0x96be(%rip)      # 0xf488
movq 0x40(%rbx), %rax
movq %rax, 0x96bb(%rip)      # 0xf490
movq 0x48(%rbx), %rax
movq %rax, 0x96b8(%rip)      # 0xf498
movq 0x50(%rbx), %rax
movq %rax, 0x96b5(%rip)      # 0xf4a0
movq 0x58(%rbx), %rax
movq %rax, 0x96b2(%rip)      # 0xf4a8
movq 0x60(%rbx), %rax
movq %rax, 0x96af(%rip)      # 0xf4b0
movl 0x78(%rbx), %eax
movl %eax, 0x96ae(%rip)      # 0xf4b8
movl $0xffffffff, 0x9574(%rip) # imm = 0xFFFFFFFF
movq (%rbx), %rax
leaq -0x90(%rbp), %rdi
movq %rax, (%rdi)
movq 0x10(%rbx), %rax
movq %rax, 0x10(%rdi)
movq 0x18(%rbx), %rax
movq %rax, 0x18(%rdi)
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rdi)
movl 0x8(%rbx), %eax
movl %eax, 0x8(%rdi)
leaq 0x557b(%rip), %rax      # 0xb3c1
movq %rax, 0x28(%rdi)
leaq 0xeb(%rip), %rax        # 0x5f3c
leaq -0x60(%rbp), %rsi
movq %rax, (%rsi)
leaq 0x14a(%rip), %rax       # 0x5fa9
movq %rax, 0x10(%rsi)
leaq 0x1af(%rip), %rax       # 0x6019
movq %rax, 0x20(%rsi)
callq 0x4440
movl %eax, %r14d
testl %eax, %eax
jne 0x5f2a
movl 0x8(%rbx), %r13d
cmpl $0x2, %r13d
jl 0x5ef2
incl %r13d
leaq 0x53b0(%rip), %rbx      # 0xb242
leaq 0x51fd(%rip), %r14      # 0xb096
leaq 0x51fb(%rip), %r15      # 0xb09b
leaq 0x5538(%rip), %r12      # 0xb3df
movl $0x1, %edi
callq 0x41c0
movl 0x94d1(%rip), %eax      # 0xf388
testl %eax, %eax
je 0x5ef2
cmpl $0x1, %eax
je 0x5f24
leaq 0x5526(%rip), %rax      # 0xb3ed
movq %rax, (%rsp)
movl $0x1, %edi
movq %rbx, %rsi
movq %r14, %rdx
movq %r15, %rcx
movq %r12, %r8
movl $0x388, %r9d            # imm = 0x388
xorl %eax, %eax
callq 0x4260
decl %r13d
cmpl $0x2, %r13d
jg 0x5ea7
movq 0x9087(%rip), %rdi      # 0xef80
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x4660
cmpl $0x0, 0x947e(%rip)      # 0xf388
js 0x5f15
movb $0x1, 0x95a9(%rip)      # 0xf4bc
jmp 0x5f2a
xorl %eax, %eax
callq 0x40f0
movl $0x186a6, %r14d         # imm = 0x186A6
jmp 0x5f2a
movl $0x186a0, %r14d         # imm = 0x186A0
movl %r14d, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq