// File: /workspace/github_c_makefile_star2_O2/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
andq $0x0, -0x80(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, -0x40(%rbp)
andq $0x0, -0x30(%rbp)
movups %xmm0, -0x50(%rbp)
xorl %r14d, %r14d
cmpb $0x0, 0x8793(%rip)      # 0xe50c
jne 0x5f0c
movq %rdi, %rbx
pushq $0x5
popq %rdi
movl $0x1400, %esi           # imm = 0x1400
xorl %edx, %edx
callq 0x45e0
movq 0x81f0(%rip), %rcx      # 0xdf88
movq %rax, (%rcx)
movq 0x28(%rbx), %rax
movq %rax, 0x876a(%rip)      # 0xe510
movq 0x30(%rbx), %rax
movq %rax, 0x8767(%rip)      # 0xe518
movq 0x38(%rbx), %rax
movq %rax, 0x871c(%rip)      # 0xe4d8
movq 0x40(%rbx), %rax
movq %rax, 0x8719(%rip)      # 0xe4e0
movq 0x48(%rbx), %rax
movq %rax, 0x8716(%rip)      # 0xe4e8
movq 0x50(%rbx), %rax
movq %rax, 0x8713(%rip)      # 0xe4f0
movq 0x58(%rbx), %rax
movq %rax, 0x8710(%rip)      # 0xe4f8
movq 0x60(%rbx), %rax
movq %rax, 0x870d(%rip)      # 0xe500
movl 0x78(%rbx), %eax
movl %eax, 0x870c(%rip)      # 0xe508
orl $-0x1, 0x85d5(%rip)     # 0xe3d8
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 0x458c(%rip), %rax      # 0xa3c1
movq %rax, 0x28(%rdi)
leaq 0xde(%rip), %rax        # 0x5f1e
leaq -0x58(%rbp), %rsi
movq %rax, (%rsi)
leaq 0x138(%rip), %rax       # 0x5f86
movq %rax, 0x10(%rsi)
leaq 0x199(%rip), %rax       # 0x5ff2
movq %rax, 0x20(%rsi)
callq 0x44d0
movl %eax, %r14d
testl %eax, %eax
jne 0x5f0c
movl 0x8(%rbx), %r14d
pushq $0x1
popq %rbx
leaq 0x421b(%rip), %r15      # 0xa096
leaq 0x4219(%rip), %r12      # 0xa09b
leaq 0x4556(%rip), %r13      # 0xa3df
cmpl $0x2, %r14d
jl 0x5ed4
movl %ebx, %edi
callq 0x41f0
movl 0x853c(%rip), %eax      # 0xe3d8
testl %eax, %eax
je 0x5ed4
cmpl $0x1, %eax
je 0x5ef7
leaq 0x4541(%rip), %rax      # 0xa3ed
movq %rax, (%rsp)
movl %ebx, %edi
leaq 0x4389(%rip), %rsi      # 0xa242
movq %r15, %rdx
movq %r12, %rcx
movq %r13, %r8
movl $0x388, %r9d            # imm = 0x388
xorl %eax, %eax
callq 0x4290
decl %r14d
jmp 0x5e89
movq 0x80a5(%rip), %rdi      # 0xdf80
xorl %r14d, %r14d
xorl %esi, %esi
callq 0x4700
cmpl $0x0, 0x84ec(%rip)      # 0xe3d8
js 0x5eff
movb $0x1, 0x8617(%rip)      # 0xe50c
jmp 0x5f0c
movl $0x186a0, %r14d         # imm = 0x186A0
jmp 0x5f0c
xorl %eax, %eax
callq 0x4120
movl $0x186a6, %r14d         # imm = 0x186A6
movl %r14d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq