// File: /workspace/github_c_makefile_star2_O3/back1127[P]linkedge-thing-access-websocket_client_sdk/sdk/leda.c
// Function: json_data_to_struct_data
int json_data_to_struct_data(cJSON *json_data, leda_device_data_t **struct_data, int *data_cnt)
{
    int size, i = 0;
    cJSON *item, *sub_item;
    char *buff;
    leda_device_data_t *data;
    

    size = cJSON_GetArraySize(json_data);
    if (size <= 0) {
        *data_cnt = 0;
        return LE_SUCCESS;
    }
    *data_cnt = size;
    data = malloc(sizeof(leda_device_data_t) * size);
    if (!data) {
        log_e(LOG_TAG, "no memory!");
        return LE_ERROR_ALLOCATING_MEM;
    }
    cJSON_ArrayForEach(item, json_data) {
        if (item->type == cJSON_String) {
            snprintf(data[i++].key, MAX_PARAM_NAME_LENGTH, "%s", item->valuestring);
            continue;
        }
        sub_item = cJSON_GetObjectItem(item, "identifier");
        if (!sub_item) {
            free(data);
            return LE_ERROR_INVAILD_PARAM;
        }
        snprintf(data[i].key, MAX_PARAM_NAME_LENGTH, "%s", sub_item->valuestring);
        sub_item = cJSON_GetObjectItem(item, "type");
        if (!sub_item | sub_item->type != cJSON_String) {
            free(data);
            return LE_ERROR_INVAILD_PARAM;
        }
        data[i].type = type_string_to_number(sub_item->valuestring);
        sub_item = cJSON_GetObjectItem(item, "value");
        if (!sub_item) {
            free(data);
            return LE_ERROR_INVAILD_PARAM;
        }
        switch (data[i].type) {
            case LEDA_TYPE_INT:
            case LEDA_TYPE_BOOL:
            case LEDA_TYPE_ENUM:
                snprintf(data[i].value, MAX_PARAM_VALUE_LENGTH, "%d", sub_item->valueint);
                break;
            case LEDA_TYPE_FLOAT:
            case LEDA_TYPE_DOUBLE:
                snprintf(data[i].value, MAX_PARAM_VALUE_LENGTH, "%lf", sub_item->valuedouble);
                break;
            case LEDA_TYPE_TEXT:
            case LEDA_TYPE_DATE:
                snprintf(data[i].value, MAX_PARAM_VALUE_LENGTH, "%s", sub_item->valuestring);
                break;
            case LEDA_TYPE_STRUCT:
            case LEDA_TYPE_ARRAY:
                buff = cJSON_Print(sub_item);
                if (!buff) {
                    log_e(LOG_TAG, "no memory!");
                    free(data);
                    return LE_ERROR_ALLOCATING_MEM;
                }
                snprintf(data[i].value, MAX_PARAM_VALUE_LENGTH, "%s", buff);
                free(buff);
                break;
            default:
                log_e(LOG_TAG, "invalid type for %s !\n", data[i].key);
                break;
        }
        ++i;
    }
    *struct_data = data;

    return LE_SUCCESS;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
callq 0x42e0
testl %eax, %eax
jle 0x4c50
movl %eax, (%rbx)
movl %eax, %eax
imulq $0x844, %rax, %rdi      # imm = 0x844
callq 0x46d8
testq %rax, %rax
je 0x4c63
movq %rax, %rbx
movq %r15, -0x30(%rbp)
testq %r14, %r14
je 0x4c58
movq 0x10(%r14), %r15
testq %r15, %r15
je 0x4c58
movq %rbx, %r12
addq $0x44, %r12
leaq 0x5a8e(%rip), %r13      # 0xa549
cmpl $0x10, 0x18(%r15)
jne 0x4aee
leaq -0x40(%r12), %rdi
movq 0x20(%r15), %rcx
movl $0x40, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0x4280
movq (%r15), %r15
addq $0x844, %r12            # imm = 0x844
testq %r15, %r15
jne 0x4abb
jmp 0x4c58
movq %r15, %rdi
leaq 0x5582(%rip), %rsi      # 0xa07a
callq 0x40a0
testq %rax, %rax
je 0x4ca3
leaq -0x40(%r12), %r14
movq 0x20(%rax), %rcx
movl $0x40, %esi
movq %r14, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x4280
movq %r15, %rdi
leaq 0x555a(%rip), %rsi      # 0xa085
callq 0x40a0
testq %rax, %rax
je 0x4ca3
cmpl $0x10, 0x18(%rax)
jne 0x4ca3
movq 0x20(%rax), %rdi
callq 0x42d0
movl %eax, -0x44(%r12)
movq %r15, %rdi
leaq 0x552f(%rip), %rsi      # 0xa08a
callq 0x40a0
testq %rax, %rax
je 0x4ca3
movl -0x44(%r12), %ecx
cmpq $0x8, %rcx
ja 0x4c0d
leaq 0x54a5(%rip), %rdx      # 0xa024
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl 0x28(%rax), %ecx
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
leaq 0x5c20(%rip), %rdx      # 0xa7ba
xorl %eax, %eax
callq 0x4280
jmp 0x4ada
movq 0x20(%rax), %rcx
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
jmp 0x4ad0
movsd 0x30(%rax), %xmm0
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
leaq 0x5538(%rip), %rdx      # 0xa103
movb $0x1, %al
callq 0x4280
jmp 0x4ada
movq %rax, %rdi
callq 0x40b0
testq %rax, %rax
je 0x4cbf
movq %rax, %r14
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x4280
movq %r14, %rdi
callq 0x46d0
jmp 0x4ada
movq %r14, 0x8(%rsp)
leaq 0x54ee(%rip), %rax      # 0xa107
movq %rax, (%rsp)
movl $0x3, %edi
leaq 0x5467(%rip), %rsi      # 0xa090
leaq 0x5466(%rip), %rdx      # 0xa096
leaq 0x5464(%rip), %rcx      # 0xa09b
leaq 0x54a1(%rip), %r8       # 0xa0df
movl $0xeb, %r9d
xorl %eax, %eax
callq 0x4260
jmp 0x4ada
movl $0x0, (%rbx)
jmp 0x4c5f
movq -0x30(%rbp), %rax
movq %rbx, (%rax)
xorl %eax, %eax
jmp 0x4cb0
leaq 0x548e(%rip), %rax      # 0xa0f8
movq %rax, (%rsp)
leaq 0x541b(%rip), %rsi      # 0xa090
leaq 0x541a(%rip), %rdx      # 0xa096
leaq 0x5418(%rip), %rcx      # 0xa09b
leaq 0x5455(%rip), %r8       # 0xa0df
movl $0x3, %edi
movl $0xb8, %r9d
xorl %eax, %eax
callq 0x4260
movl $0x186a2, %eax          # imm = 0x186A2
jmp 0x4cb0
movq %rbx, %rdi
callq 0x46d0
movl $0x186a1, %eax          # imm = 0x186A1
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5432(%rip), %rax      # 0xa0f8
movq %rax, (%rsp)
leaq 0x53bf(%rip), %rsi      # 0xa090
leaq 0x53be(%rip), %rdx      # 0xa096
leaq 0x53bc(%rip), %rcx      # 0xa09b
leaq 0x53f9(%rip), %r8       # 0xa0df
movl $0x3, %edi
movl $0xe3, %r9d
xorl %eax, %eax
callq 0x4260
movq %rbx, %rdi
callq 0x46d0
jmp 0x4c9c