// File: /workspace/github_c_makefile_star2_O0/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
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x4300
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x4300
cmpl $0x1, 0xbf7b(%rip)      # 0x125d8
jne 0x666b
movl $0x0, -0x4(%rbp)
jmp 0x6854
movl $0x5, %edi
movl $0x1400, %esi           # imm = 0x1400
xorl %edx, %edx
callq 0x4620
movq %rax, %rcx
movq 0xb902(%rip), %rax      # 0x11f88
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, 0xbf48(%rip)      # 0x125e0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, 0xbf41(%rip)      # 0x125e8
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, 0xbeda(%rip)      # 0x12590
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
movq %rax, 0xbed3(%rip)      # 0x12598
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, 0xbecc(%rip)      # 0x125a0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, 0xbec5(%rip)      # 0x125a8
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movq %rax, 0xbebe(%rip)      # 0x125b0
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, 0xbeb7(%rip)      # 0x125b8
movq -0x10(%rbp), %rax
movl 0x78(%rax), %eax
movl %eax, 0xbec2(%rip)      # 0x125d0
movl $0xffffffff, 0xbd38(%rip) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
leaq 0x7c69(%rip), %rax      # 0xe3c1
movq %rax, -0x20(%rbp)
leaq 0xfd(%rip), %rax        # 0x6860
movq %rax, -0x78(%rbp)
leaq 0x172(%rip), %rax       # 0x68e0
movq %rax, -0x68(%rbp)
leaq 0x1e7(%rip), %rax       # 0x6960
movq %rax, -0x58(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x4500
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x679e
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6854
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x18(%rbp)
cmpl $0x0, %eax
jle 0x681a
movl $0x1, %edi
callq 0x4200
cmpl $0x0, 0xbc89(%rip)      # 0x12450
jne 0x67cb
jmp 0x681a
cmpl $0x1, 0xbc7e(%rip)      # 0x12450
jne 0x67dd
movl $0x186a0, -0x4(%rbp)    # imm = 0x186A0
jmp 0x6854
movl $0x1, %edi
leaq 0x7a59(%rip), %rsi      # 0xe242
leaq 0x78a6(%rip), %rdx      # 0xe096
leaq 0x78a4(%rip), %rcx      # 0xe09b
leaq 0x7be1(%rip), %r8       # 0xe3df
movl $0x388, %r9d            # imm = 0x388
leaq 0x7be2(%rip), %rax      # 0xe3ed
movq %rax, (%rsp)
movb $0x0, %al
callq 0x42b0
jmp 0x6818
jmp 0x67a8
movq 0xb75f(%rip), %rdi      # 0x11f80
xorl %eax, %eax
movl %eax, %esi
callq 0x4750
cmpl $0x0, 0xbc1f(%rip)      # 0x12450
jge 0x6843
movb $0x0, %al
callq 0x4130
movl $0x186a6, -0x4(%rbp)    # imm = 0x186A6
jmp 0x6854
movl $0x1, 0xbd8b(%rip)      # 0x125d8
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq