// File: /workspace/github_c_makefile_star2_O3/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 0x8aea(%rip), %rax      # 0xe4c8
imulq $0x844, %rax, %rsi      # imm = 0x844
movl $0x1, %edi
callq 0x4370
testq %rax, %rax
je 0x5a3c
movq 0x8abd(%rip), %r10      # 0xe4b8
testq %r10, %r10
je 0x5a50
movq 0x8ab9(%rip), %rcx      # 0xe4c0
movq %rcx, (%rsp)
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r12, %rcx
movl %r15d, %r8d
movq %rax, %r14
movq %rax, %r9
callq *%r10
xorl %r13d, %r13d
testl %eax, %eax
je 0x5abb
movl %eax, %r12d
xorl %r15d, %r15d
movl -0x2c(%rbp), %ebx
movq %r14, %rdi
jmp 0x5a9b
movl $0x186a2, %eax          # imm = 0x186A2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48f9(%rip), %rcx      # 0xa350
movq %rcx, (%rsp)
leaq 0x462e(%rip), %rsi      # 0xa090
leaq 0x462d(%rip), %rdx      # 0xa096
leaq 0x462b(%rip), %rcx      # 0xa09b
leaq 0x48c3(%rip), %r8       # 0xa33a
xorl %r15d, %r15d
movl $0x3, %edi
movq %rax, %rbx
movl $0x27b, %r9d            # imm = 0x27B
xorl %eax, %eax
callq 0x4260
movq %rbx, %rdi
movl $0x186a0, %r12d         # imm = 0x186A0
movl -0x2c(%rbp), %ebx
callq 0x46d0
movl %r12d, %edi
movl %ebx, %esi
movq %r15, %rdx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4390
movl 0x8a07(%rip), %eax      # 0xe4c8
testl %eax, %eax
movl -0x2c(%rbp), %ebx
jle 0x5ae9
movq %r14, %rcx
addq $0x4, %rcx
xorl %r13d, %r13d
cmpb $0x0, (%rcx)
je 0x5ae9
incq %r13
addq $0x844, %rcx            # imm = 0x844
cmpq %r13, %rax
jne 0x5ad2
movl %eax, %r13d
callq 0x45e0
xorl %r12d, %r12d
testq %rax, %rax
je 0x5b24
movq %rax, %r15
movq %r14, %rdi
movl %r13d, %esi
callq 0x45a0
testq %rax, %rax
je 0x5a37
leaq 0x4723(%rip), %rsi      # 0xa237
movq %r15, %rdi
movq %rax, %rdx
callq 0x4610
jmp 0x5a37
xorl %r15d, %r15d
jmp 0x5a37