// File: /workspace/github_c_makefile_star2_O0/back1127[P]linkedge-thing-access-websocket_client_sdk/sdk/ali_ws/ws_client.c
// Function: wsc_init
int wsc_init(p_wsc_param_conn pc, p_wsc_param_cb cb)
{
    int ret = 0;
    if (!pc || !cb || !pc->url) {
        printf("wsc init failed, param should not be NULL.\n");
        return LE_ERROR_INVAILD_PARAM;
    }

    if (!strncmp(pc->url, "wss", 3) && !pc->ca_path) {
        printf("ca path must not be NULL when use ssl\n");
    }

    g_cbs = malloc(sizeof(wsc_param_cb));
    if (!g_cbs) {
        printf("malloc error.\n");
        return LE_ERROR_ALLOCATING_MEM;
    }

    memset(g_cbs, 0, sizeof(wsc_param_cb));
    memcpy(g_cbs, cb, sizeof(wsc_param_cb));
    
    force_exit = 0;

    ret = client_buf_mgmt_init(1024 * 2, 1024);
    if (ret != LE_SUCCESS) {
        free(g_cbs);
        g_cbs = NULL;
        return ret;
    }

    pthread_t id;
    ret = pthread_create(&id, NULL, thread_wsc_network, pc);
    if (ret == 0) {
        printf("wsc init ok\n");
    } else {
        free(g_cbs);
        g_cbs = NULL;
#ifndef _WIN32
        printf("wsc init faild, %s.\n", strerror(errno));
#else
        char buffer[64] = { 0 };
        strerror_s(buffer, sizeof(buffer), errno);
        printf("wsc init faild, %s.\n", buffer);
#endif
        client_buf_mgmt_destroy();

        return LE_ERROR_UNKNOWN;
    }
    pthread_detach(id);

    return LE_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x6c6f
cmpq $0x0, -0x18(%rbp)
je 0x6c6f
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x6c89
leaq 0x77ff(%rip), %rdi      # 0xe475
movb $0x0, %al
callq 0x4290
movl $0x186a1, -0x4(%rbp)    # imm = 0x186A1
jmp 0x6e01
movq -0x10(%rbp), %rax
movq (%rax), %rdi
leaq 0x780a(%rip), %rsi      # 0xe4a1
movl $0x3, %edx
callq 0x40b0
cmpl $0x0, %eax
jne 0x6cbf
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x6cbf
leaq 0x77ed(%rip), %rdi      # 0xe4a5
movb $0x0, %al
callq 0x4290
movl $0x30, %edi
callq 0x4798
movq %rax, %rcx
movq 0xb2cd(%rip), %rax      # 0x11fa0
movq %rcx, (%rax)
movq 0xb2c3(%rip), %rax      # 0x11fa0
cmpq $0x0, (%rax)
jne 0x6cfd
leaq 0x77e2(%rip), %rdi      # 0xe4cc
movb $0x0, %al
callq 0x4290
movl $0x186a2, -0x4(%rbp)    # imm = 0x186A2
jmp 0x6e01
movq 0xb29c(%rip), %rax      # 0x11fa0
movq (%rax), %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x4300
movq 0xb286(%rip), %rax      # 0x11fa0
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movl $0x30, %edx
callq 0x4400
movq 0xb2be(%rip), %rax      # 0x11ff0
movl $0x0, (%rax)
movl $0x800, %edi            # imm = 0x800
movl $0x400, %esi            # imm = 0x400
callq 0x4560
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x6d78
movq 0xb249(%rip), %rax      # 0x11fa0
movq (%rax), %rdi
callq 0x4790
movq 0xb23a(%rip), %rax      # 0x11fa0
movq $0x0, (%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6e01
movq -0x10(%rbp), %rcx
leaq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
movq 0xb24d(%rip), %rdx      # 0x11fd8
callq 0x4590
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x6da9
leaq 0x773b(%rip), %rdi      # 0xe4db
movb $0x0, %al
callq 0x4290
jmp 0x6df1
movq 0xb1f0(%rip), %rax      # 0x11fa0
movq (%rax), %rdi
callq 0x4790
movq 0xb1e1(%rip), %rax      # 0x11fa0
movq $0x0, (%rax)
callq 0x4080
movl (%rax), %edi
callq 0x4710
movq %rax, %rsi
leaq 0x770c(%rip), %rdi      # 0xe4e8
movb $0x0, %al
callq 0x4290
callq 0x4270
movl $0x186a0, -0x4(%rbp)    # imm = 0x186A0
jmp 0x6e01
movq -0x28(%rbp), %rdi
callq 0x44e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)