// File: /workspace/github_c_makefile_star2_O0/back1127[P]linkedge-thing-access-websocket_client_sdk/sdk/leda.c
// Function: leda_send_method_sync
int leda_send_method_sync(const char *pk, const char *dn, const char *method, const char *event_name,
                     const leda_device_data_t *data, int data_cnt)
{
    cJSON *root, *payload, *params, *item, *sub_item;
    unsigned int msg_id;
    char *msg;
    size_t len;
    int ret, code = 0, i;

    if (!pk || !dn || !method) {
        return LE_ERROR_INVAILD_PARAM;
    }

    msg_id = get_msg_id();

    root = cJSON_CreateObject();
    if (!root) {
        return LE_ERROR_ALLOCATING_MEM;
    }
    cJSON_AddStringToObject(root, "version", PROTOCOL_VERSION);
    cJSON_AddNumberToObject(root, "messageId", msg_id);
    cJSON_AddStringToObject(root, "method", method);
    payload = cJSON_CreateObject();
    if (!payload) {
        return LE_ERROR_ALLOCATING_MEM;
    }
    cJSON_AddItemToObject(root, "payload", payload);
    cJSON_AddStringToObject(payload, "productKey", pk);
    cJSON_AddStringToObject(payload, "deviceName", dn);

    if (0 == strcmp(method, METHOD_ONLINE) || 0 == strcmp(method, METHOD_OFFLINE)) {
        goto next_step;
    }
    params = struct_data_to_json_data(data, data_cnt);
    if (!params) {
        cJSON_Delete(root);
        goto next_step;
    }
    if (event_name) {
        cJSON_AddStringToObject(payload, "identifier", event_name);
        cJSON_AddItemToObject(payload, "outputData", params);
    } else {
        cJSON_AddItemToObject(payload, "properties", params);
    }

next_step:
    msg = cJSON_Print(root);
    cJSON_Delete(root);
    if (!msg) {
        return LE_ERROR_ALLOCATING_MEM;
    }
    len = strlen(msg);

    ret = wsa_insert_reply(msg_id);
    if (ret != LE_SUCCESS) {
        free(msg);
        return ret;
    }
    log_i(LOG_TAG, "send messege to server: %s", msg);
    ret = wsc_add_msg(msg, len, 0);
    free(msg);
    if (ret != LE_SUCCESS) {
        wsa_remove_reply(msg_id);
        return ret;
    }
    
    ret = wsa_get_reply_result(msg_id, 3000, &code, NULL);
    if (ret != LE_SUCCESS) {
        log_e(LOG_TAG, "reply code:%d\n", code);
        return ret;
    }

    return code;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movl $0x0, -0x80(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x57ef
cmpq $0x0, -0x18(%rbp)
je 0x57ef
cmpq $0x0, -0x20(%rbp)
jne 0x57fb
movl $0x186a1, -0x4(%rbp)    # imm = 0x186A1
jmp 0x5a8f
callq 0x4030
movl %eax, -0x64(%rbp)
callq 0x4680
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x581f
movl $0x186a2, -0x4(%rbp)    # imm = 0x186A2
jmp 0x5a8f
movq -0x40(%rbp), %rdi
leaq 0x89cf(%rip), %rsi      # 0xe1f9
leaq 0x89d0(%rip), %rdx      # 0xe201
callq 0x45b0
movq -0x40(%rbp), %rdi
movl -0x64(%rbp), %eax
cvtsi2sd %rax, %xmm0
leaq 0x894b(%rip), %rsi      # 0xe194
callq 0x4260
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x8a35(%rip), %rsi      # 0xe292
callq 0x45b0
callq 0x4680
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x587e
movl $0x186a2, -0x4(%rbp)    # imm = 0x186A2
jmp 0x5a8f
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rdx
leaq 0x8945(%rip), %rsi      # 0xe1d2
callq 0x46e0
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x8965(%rip), %rsi      # 0xe206
callq 0x45b0
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x895c(%rip), %rsi      # 0xe211
callq 0x45b0
movq -0x20(%rbp), %rdi
leaq 0x8957(%rip), %rsi      # 0xe21c
callq 0x43c0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x58ea
movq -0x20(%rbp), %rdi
leaq 0x894c(%rip), %rsi      # 0xe229
callq 0x43c0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x58ec
jmp 0x5955
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x4640
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x590e
movq -0x40(%rbp), %rdi
callq 0x41e0
jmp 0x5955
cmpq $0x0, -0x28(%rbp)
je 0x593f
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x8756(%rip), %rsi      # 0xe07a
callq 0x45b0
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rdx
leaq 0x88ff(%rip), %rsi      # 0xe237
callq 0x46e0
jmp 0x5953
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rdx
leaq 0x8975(%rip), %rsi      # 0xe2c3
callq 0x46e0
jmp 0x5955
movq -0x40(%rbp), %rdi
callq 0x40f0
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rdi
callq 0x41e0
cmpq $0x0, -0x70(%rbp)
jne 0x597e
movl $0x186a2, -0x4(%rbp)    # imm = 0x186A2
jmp 0x5a8f
movq -0x70(%rbp), %rdi
callq 0x4250
movq %rax, -0x78(%rbp)
movl -0x64(%rbp), %edi
callq 0x43f0
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0x7c(%rbp)
je 0x59b0
movq -0x70(%rbp), %rdi
callq 0x4790
movl -0x7c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5a8f
movq -0x70(%rbp), %rax
movl $0x1, %edi
leaq 0x8882(%rip), %rsi      # 0xe242
leaq 0x86cf(%rip), %rdx      # 0xe096
leaq 0x86cd(%rip), %rcx      # 0xe09b
leaq 0x8873(%rip), %r8       # 0xe248
movl $0x1d0, %r9d            # imm = 0x1D0
leaq 0x887c(%rip), %r10      # 0xe25e
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x42b0
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rsi
xorl %edx, %edx
callq 0x4530
movl %eax, -0x7c(%rbp)
movq -0x70(%rbp), %rdi
callq 0x4790
cmpl $0x0, -0x7c(%rbp)
je 0x5a23
movl -0x64(%rbp), %edi
callq 0x43e0
movl -0x7c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5a8f
movl -0x64(%rbp), %edi
movl $0xbb8, %esi            # imm = 0xBB8
leaq -0x80(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x4040
movl %eax, -0x7c(%rbp)
cmpl $0x0, -0x7c(%rbp)
je 0x5a89
movl -0x80(%rbp), %eax
movl $0x3, %edi
leaq 0x8640(%rip), %rsi      # 0xe090
leaq 0x863f(%rip), %rdx      # 0xe096
leaq 0x863d(%rip), %rcx      # 0xe09b
leaq 0x87e3(%rip), %r8       # 0xe248
movl $0x1da, %r9d            # imm = 0x1DA
leaq 0x8807(%rip), %r10      # 0xe279
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x42b0
movl -0x7c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5a8f
movl -0x80(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)