// File: /workspace/github_c_makefile_star2_O1/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 0x4a7a
movl %eax, (%rbx)
movl %eax, %eax
imulq $0x844, %rax, %rdi      # imm = 0x844
callq 0x46b8
testq %rax, %rax
je 0x4a85
movq %rax, %rbx
movq %r15, -0x30(%rbp)
testq %r14, %r14
je 0x4ac8
movq 0x10(%r14), %r15
jmp 0x4acb
movl $0x0, (%rbx)
jmp 0x4c7e
leaq 0x666c(%rip), %rax      # 0xb0f8
movq %rax, (%rsp)
leaq 0x65f9(%rip), %rsi      # 0xb090
leaq 0x65f8(%rip), %rdx      # 0xb096
leaq 0x65f6(%rip), %rcx      # 0xb09b
leaq 0x6633(%rip), %r8       # 0xb0df
movl $0x3, %edi
movl $0xb8, %r9d
xorl %eax, %eax
callq 0x4260
movl $0x186a2, %eax          # imm = 0x186A2
jmp 0x4c80
xorl %r15d, %r15d
testq %r15, %r15
je 0x4c77
movq %rbx, %r12
addq $0x44, %r12
leaq 0x6a6b(%rip), %r13      # 0xb54d
cmpl $0x10, 0x18(%r15)
jne 0x4b15
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 0x4ae2
jmp 0x4c77
movq %r15, %rdi
leaq 0x655b(%rip), %rsi      # 0xb07a
callq 0x40a0
testq %rax, %rax
je 0x4c8f
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 0x6533(%rip), %rsi      # 0xb085
callq 0x40a0
testq %rax, %rax
je 0x4c8f
cmpl $0x10, 0x18(%rax)
jne 0x4c8f
movq 0x20(%rax), %rdi
callq 0x42d0
movl %eax, -0x44(%r12)
movq %r15, %rdi
leaq 0x6508(%rip), %rsi      # 0xb08a
callq 0x40a0
testq %rax, %rax
je 0x4c8f
movl -0x44(%r12), %ecx
cmpq $0x8, %rcx
ja 0x4c34
leaq 0x647e(%rip), %rdx      # 0xb024
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl 0x28(%rax), %ecx
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
leaq 0x6bfd(%rip), %rdx      # 0xb7be
xorl %eax, %eax
callq 0x4280
jmp 0x4b01
movq 0x20(%rax), %rcx
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
jmp 0x4af7
movsd 0x30(%rax), %xmm0
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
leaq 0x6511(%rip), %rdx      # 0xb103
movb $0x1, %al
callq 0x4280
jmp 0x4b01
movq %rax, %rdi
callq 0x40b0
testq %rax, %rax
je 0x4c9e
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 0x46b0
jmp 0x4b01
movq %r14, 0x8(%rsp)
leaq 0x64c7(%rip), %rax      # 0xb107
movq %rax, (%rsp)
movl $0x3, %edi
leaq 0x6440(%rip), %rsi      # 0xb090
leaq 0x643f(%rip), %rdx      # 0xb096
leaq 0x643d(%rip), %rcx      # 0xb09b
leaq 0x647a(%rip), %r8       # 0xb0df
movl $0xeb, %r9d
xorl %eax, %eax
callq 0x4260
jmp 0x4b01
movq -0x30(%rbp), %rax
movq %rbx, (%rax)
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
callq 0x46b0
movl $0x186a1, %eax          # imm = 0x186A1
jmp 0x4c80
leaq 0x6453(%rip), %rax      # 0xb0f8
movq %rax, (%rsp)
leaq 0x63e0(%rip), %rsi      # 0xb090
leaq 0x63df(%rip), %rdx      # 0xb096
leaq 0x63dd(%rip), %rcx      # 0xb09b
leaq 0x641a(%rip), %r8       # 0xb0df
movl $0x3, %edi
movl $0xe3, %r9d
xorl %eax, %eax
callq 0x4260
movq %rbx, %rdi
callq 0x46b0
jmp 0x4abe