// File: /workspace/github_c_makefile_star2_O2/back1127[P]linkedge-thing-access-websocket_client_sdk/sdk/leda.c
// Function: leda_rsp_call_service
int leda_rsp_call_service(char *pk, char *dn, int msg_id, const char *service_name, leda_device_data_t *input_params,
                          int params_cnt)
{
    int ret = LE_ERROR_UNKNOWN, i;
    leda_device_data_t *output_params = NULL;
    cJSON *payload = NULL, *params;

    output_params = malloc(sizeof(leda_device_data_t) * g_devs_cb.service_output_max_count);
    if (!output_params) {
        return LE_ERROR_ALLOCATING_MEM;
    }
    memset(output_params, 0, sizeof(leda_device_data_t) * g_devs_cb.service_output_max_count);
    if (g_devs_cb.call_service_cb) {
        ret = g_devs_cb.call_service_cb(pk, dn, service_name, input_params, params_cnt, output_params, g_devs_cb.usr_data_call_service);
    } else {
        log_e(LOG_TAG, "callback call_service_cb unregistered!\n");
    }

    if (ret != LE_SUCCESS) {
        goto end;
    }
    params_cnt = 0;
    for (i = 0; i < g_devs_cb.service_output_max_count; i++) {
        if (strlen(output_params[i].key) == 0) {
            break;
        }
        ++params_cnt;
    }
    payload = cJSON_CreateObject();
    if (!payload) {
        goto end;
    }
    params = struct_data_to_json_data(output_params, params_cnt);
    if (params) {
        cJSON_AddItemToObject(payload, "outputData", params);
    }

end:

    if (output_params) {
        free(output_params);
    }

    return leda_send_rsp(ret, msg_id, payload);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, %r15d
movq %r8, %r12
movq %rcx, %r13
movl %edx, -0x2c(%rbp)
movq %rsi, %rbx
movq %rdi, %r14
movslq 0x8b38(%rip), %rax      # 0xe508
imulq $0x844, %rax, %rsi      # imm = 0x844
pushq $0x1
popq %rdi
callq 0x43a0
movq %rax, -0x38(%rbp)
testq %rax, %rax
je 0x5a27
movq 0x8b09(%rip), %rax      # 0xe4f8
testq %rax, %rax
je 0x5a3b
movq 0x8b05(%rip), %rcx      # 0xe500
movq %rcx, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r12, %rcx
movl %r15d, %r8d
movq -0x38(%rbp), %rbx
movq %rbx, %r9
callq *%rax
xorl %r15d, %r15d
testl %eax, %eax
je 0x5aa3
movl %eax, %r12d
jmp 0x5a7f
movl $0x186a2, %eax          # imm = 0x186A2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x490e(%rip), %rax      # 0xa350
movq %rax, (%rsp)
leaq 0x4643(%rip), %rsi      # 0xa090
leaq 0x4642(%rip), %rdx      # 0xa096
leaq 0x4640(%rip), %rcx      # 0xa09b
leaq 0x48d8(%rip), %r8       # 0xa33a
xorl %r15d, %r15d
pushq $0x3
popq %rdi
movl $0x27b, %r9d            # imm = 0x27B
xorl %eax, %eax
callq 0x4290
movl $0x186a0, %r12d         # imm = 0x186A0
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x4750
movl %r12d, %edi
movl -0x2c(%rbp), %esi
movq %r15, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x43c0
movl 0x8a5e(%rip), %r13d     # 0xe508
testl %r13d, %r13d
cmovlel %r15d, %r13d
movq %rbx, %rax
addq $0x4, %rax
cmpq %r15, %r13
je 0x5ad0
cmpb $0x0, (%rax)
je 0x5acd
incq %r15
addq $0x844, %rax            # imm = 0x844
jmp 0x5ab8
movl %r15d, %r13d
callq 0x4640
xorl %r12d, %r12d
testq %rax, %rax
je 0x5b07
movq %rax, %r15
movq %rbx, %rdi
movl %r13d, %esi
callq 0x4600
testq %rax, %rax
je 0x5a7f
leaq 0x4740(%rip), %rsi      # 0xa237
movq %r15, %rdi
movq %rax, %rdx
callq 0x4690
jmp 0x5a7f
xorl %r15d, %r15d
jmp 0x5a7f