// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r15
testq %rdi, %rdi
setne %al
testq %rsi, %rsi
setne %dl
andb %al, %dl
testq %r15, %r15
setne %al
testb %al, %dl
je 0x5640
movq %rsi, %r12
movq %rdi, %r13
movq %r8, -0x40(%rbp)
movl %r9d, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
leaq 0x9f18(%rip), %rbx      # 0xf430
movq %rbx, %rdi
callq 0x4680
movl 0x9f31(%rip), %r14d     # 0xf458
incl %r14d
movl %r14d, 0x9f27(%rip)     # 0xf458
movq %rbx, %rdi
callq 0x43e0
callq 0x45b0
movq %rax, %rbx
movl $0xfffe795e, %eax       # imm = 0xFFFE795E
testq %rbx, %rbx
je 0x5684
leaq 0x5ca3(%rip), %rsi      # 0xb1f9
leaq 0x5ca4(%rip), %rdx      # 0xb201
movq %rbx, %rdi
callq 0x44f0
movl %r14d, -0x2c(%rbp)
movl %r14d, %eax
cvtsi2sd %rax, %xmm0
leaq 0x5c1c(%rip), %rsi      # 0xb194
movq %rbx, %rdi
callq 0x4210
leaq 0x5d0b(%rip), %rsi      # 0xb292
movq %rbx, %rdi
movq %r15, %rdx
callq 0x44f0
callq 0x45b0
testq %rax, %rax
je 0x5693
movq %rax, %r14
leaq 0x5c28(%rip), %rsi      # 0xb1d2
movq %rbx, %rdi
movq %rax, %rdx
callq 0x45f0
leaq 0x5c4a(%rip), %rsi      # 0xb206
movq %r14, %rdi
movq %r13, %rdx
callq 0x44f0
leaq 0x5c43(%rip), %rsi      # 0xb211
movq %r14, %rdi
movq %r12, %rdx
callq 0x44f0
leaq 0x5c3c(%rip), %rsi      # 0xb21c
movq %r15, %rdi
callq 0x4360
testl %eax, %eax
movl -0x2c(%rbp), %r12d
je 0x56b6
leaq 0x5c2e(%rip), %rsi      # 0xb229
movq %r15, %rdi
callq 0x4360
testl %eax, %eax
je 0x56b6
movq -0x40(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x4570
testq %rax, %rax
je 0x569a
movq %rax, %r15
movq -0x38(%rbp), %rdx
testq %rdx, %rdx
je 0x56a4
leaq 0x5a4b(%rip), %rsi      # 0xb07a
movq %r14, %rdi
callq 0x44f0
leaq 0x5bf9(%rip), %rsi      # 0xb237
jmp 0x56ab
subq $0x8, %rsp
leaq 0x5c4e(%rip), %r10      # 0xb299
leaq 0x5a3e(%rip), %rsi      # 0xb090
leaq 0x5a3d(%rip), %rdx      # 0xb096
leaq 0x5a3b(%rip), %rcx      # 0xb09b
leaq 0x5c21(%rip), %r8       # 0xb288
movl $0x3, %edi
movl $0x1eb, %r9d            # imm = 0x1EB
xorl %eax, %eax
pushq %r10
callq 0x4260
addq $0x10, %rsp
movl $0xfffe795f, %eax       # imm = 0xFFFE795F
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xfffe795e, %eax       # imm = 0xFFFE795E
jmp 0x5684
movq %rbx, %rdi
callq 0x41a0
jmp 0x56b6
leaq 0x5c18(%rip), %rsi      # 0xb2c3
movq %r14, %rdi
movq %r15, %rdx
callq 0x45f0
movq %rbx, %rdi
callq 0x40b0
movq %rax, %r15
movq %rbx, %rdi
callq 0x41a0
testq %r15, %r15
movl $0xfffe795e, %eax       # imm = 0xFFFE795E
je 0x5684
movq %r15, %rdi
callq 0x4200
movq %rax, %rbx
leaq 0x5b79(%rip), %r10      # 0xb25e
leaq 0x5b56(%rip), %rsi      # 0xb242
leaq 0x59a3(%rip), %rdx      # 0xb096
leaq 0x59a1(%rip), %rcx      # 0xb09b
leaq 0x5b87(%rip), %r8       # 0xb288
movl $0x1, %edi
movl $0x217, %r9d            # imm = 0x217
xorl %eax, %eax
pushq %r15
pushq %r10
callq 0x4260
addq $0x10, %rsp
movq %r15, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x4470
movl %eax, %ebx
movq %r15, %rdi
callq 0x46b0
movl %ebx, %eax
negl %eax
cmovael %r12d, %eax
jmp 0x5684