// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
xorl %r14d, %r14d
movq %r14, -0x80(%rbp)
movq %r14, -0x30(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, -0x40(%rbp)
movups %xmm0, -0x50(%rbp)
cmpb $0x0, 0x8720(%rip)      # 0xe4cc
jne 0x5f51
movq %rdi, %rbx
movl $0x5, %edi
movl $0x1400, %esi           # imm = 0x1400
xorl %edx, %edx
callq 0x4580
movq 0x81bb(%rip), %rcx      # 0xdf88
movq %rax, (%rcx)
movq 0x28(%rbx), %rax
movq %rax, 0x86f5(%rip)      # 0xe4d0
movq 0x30(%rbx), %rax
movq %rax, 0x86f2(%rip)      # 0xe4d8
movq 0x38(%rbx), %rax
movq %rax, 0x86a7(%rip)      # 0xe498
movq 0x40(%rbx), %rax
movq %rax, 0x86a4(%rip)      # 0xe4a0
movq 0x48(%rbx), %rax
movq %rax, 0x86a1(%rip)      # 0xe4a8
movq 0x50(%rbx), %rax
movq %rax, 0x869e(%rip)      # 0xe4b0
movq 0x58(%rbx), %rax
movq %rax, 0x869b(%rip)      # 0xe4b8
movq 0x60(%rbx), %rax
movq %rax, 0x8698(%rip)      # 0xe4c0
movl 0x78(%rbx), %eax
movl %eax, 0x8697(%rip)      # 0xe4c8
movl $0xffffffff, 0x855d(%rip) # imm = 0xFFFFFFFF
movq (%rbx), %rax
leaq -0x88(%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 0x4554(%rip), %rax      # 0xa3c1
movq %rax, 0x28(%rdi)
leaq 0xeb(%rip), %rax        # 0x5f63
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
leaq 0x14a(%rip), %rax       # 0x5fd0
movq %rax, 0x10(%rsi)
leaq 0x1af(%rip), %rax       # 0x6040
movq %rax, 0x20(%rsi)
callq 0x4470
movl %eax, %r14d
testl %eax, %eax
jne 0x5f51
movl 0x8(%rbx), %r13d
cmpl $0x2, %r13d
jl 0x5f19
incl %r13d
leaq 0x4389(%rip), %rbx      # 0xa242
leaq 0x41d6(%rip), %r14      # 0xa096
leaq 0x41d4(%rip), %r15      # 0xa09b
leaq 0x4511(%rip), %r12      # 0xa3df
movl $0x1, %edi
callq 0x41c0
movl 0x84ba(%rip), %eax      # 0xe398
testl %eax, %eax
je 0x5f19
cmpl $0x1, %eax
je 0x5f4b
leaq 0x44ff(%rip), %rax      # 0xa3ed
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 0x5ece
movq 0x8060(%rip), %rdi      # 0xdf80
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x4680
cmpl $0x0, 0x8467(%rip)      # 0xe398
js 0x5f3c
movb $0x1, 0x8592(%rip)      # 0xe4cc
jmp 0x5f51
xorl %eax, %eax
callq 0x40f0
movl $0x186a6, %r14d         # imm = 0x186A6
jmp 0x5f51
movl $0x186a0, %r14d         # imm = 0x186A0
movl %r14d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq