// File: /workspace/github_c_makefile_star2_O0/back1127[P]linkedge-thing-access-websocket_client_sdk/sdk/leda.c
// Function: leda_send_method
int leda_send_method(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) {
        log_e(LOG_TAG, "invalid param!");
        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);

    log_i(LOG_TAG, "send messege to server: %s", msg);
    ret = wsc_add_msg(msg, len, 0);
    free(msg);
    if (ret != LE_SUCCESS) {
        return -ret;
    }

    return msg_id;
}

// 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 0x5adf
cmpq $0x0, -0x18(%rbp)
je 0x5adf
cmpq $0x0, -0x20(%rbp)
jne 0x5b24
movl $0x3, %edi
leaq 0x85a5(%rip), %rsi      # 0xe090
leaq 0x85a4(%rip), %rdx      # 0xe096
leaq 0x85a2(%rip), %rcx      # 0xe09b
leaq 0x8788(%rip), %r8       # 0xe288
movl $0x1eb, %r9d            # imm = 0x1EB
leaq 0x878c(%rip), %rax      # 0xe299
movq %rax, (%rsp)
movb $0x0, %al
callq 0x42b0
movl $0xfffe795f, -0x4(%rbp) # imm = 0xFFFE795F
jmp 0x5d27
callq 0x4030
movl %eax, -0x64(%rbp)
callq 0x4680
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x5b48
movl $0xfffe795e, -0x4(%rbp) # imm = 0xFFFE795E
jmp 0x5d27
movq -0x40(%rbp), %rdi
leaq 0x86a6(%rip), %rsi      # 0xe1f9
leaq 0x86a7(%rip), %rdx      # 0xe201
callq 0x45b0
movq -0x40(%rbp), %rdi
movl -0x64(%rbp), %eax
cvtsi2sd %rax, %xmm0
leaq 0x8622(%rip), %rsi      # 0xe194
callq 0x4260
movq -0x40(%rbp), %rdi
movq -0x20(%rbp), %rdx
leaq 0x870c(%rip), %rsi      # 0xe292
callq 0x45b0
callq 0x4680
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x5ba7
movl $0xfffe795e, -0x4(%rbp) # imm = 0xFFFE795E
jmp 0x5d27
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rdx
leaq 0x861c(%rip), %rsi      # 0xe1d2
callq 0x46e0
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rdx
leaq 0x863c(%rip), %rsi      # 0xe206
callq 0x45b0
movq -0x48(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x8633(%rip), %rsi      # 0xe211
callq 0x45b0
movq -0x20(%rbp), %rdi
leaq 0x862e(%rip), %rsi      # 0xe21c
callq 0x43c0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x5c13
movq -0x20(%rbp), %rdi
leaq 0x8623(%rip), %rsi      # 0xe229
callq 0x43c0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x5c15
jmp 0x5c7e
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
callq 0x4640
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x5c37
movq -0x40(%rbp), %rdi
callq 0x41e0
jmp 0x5c7e
cmpq $0x0, -0x28(%rbp)
je 0x5c68
movq -0x48(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x842d(%rip), %rsi      # 0xe07a
callq 0x45b0
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rdx
leaq 0x85d6(%rip), %rsi      # 0xe237
callq 0x46e0
jmp 0x5c7c
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rdx
leaq 0x864c(%rip), %rsi      # 0xe2c3
callq 0x46e0
jmp 0x5c7e
movq -0x40(%rbp), %rdi
callq 0x40f0
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rdi
callq 0x41e0
cmpq $0x0, -0x70(%rbp)
jne 0x5ca7
movl $0xfffe795e, -0x4(%rbp) # imm = 0xFFFE795E
jmp 0x5d27
movq -0x70(%rbp), %rdi
callq 0x4250
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rax
movl $0x1, %edi
leaq 0x857e(%rip), %rsi      # 0xe242
leaq 0x83cb(%rip), %rdx      # 0xe096
leaq 0x83c9(%rip), %rcx      # 0xe09b
leaq 0x85af(%rip), %r8       # 0xe288
movl $0x217, %r9d            # imm = 0x217
leaq 0x8578(%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 0x5d21
xorl %eax, %eax
subl -0x7c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x5d27
movl -0x64(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)