// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq %rdi, %r15
callq 0x4310
testl %eax, %eax
jle 0x4b06
movl %eax, (%rbx)
movl %eax, %eax
imulq $0x844, %rax, %rdi      # imm = 0x844
callq 0x4758
testq %rax, %rax
je 0x4b0e
movq %rax, %rbx
movq %r14, -0x30(%rbp)
testq %r15, %r15
je 0x4b4f
addq $0x10, %r15
xorl %r14d, %r14d
jmp 0x4b57
andl $0x0, (%rbx)
jmp 0x4d31
leaq 0x55e3(%rip), %rax      # 0xa0f8
movq %rax, (%rsp)
leaq 0x5570(%rip), %rsi      # 0xa090
leaq 0x556f(%rip), %rdx      # 0xa096
leaq 0x556d(%rip), %rcx      # 0xa09b
leaq 0x55aa(%rip), %r8       # 0xa0df
pushq $0x3
popq %rdi
movl $0xb8, %r9d
xorl %eax, %eax
callq 0x4290
movl $0x186a2, %eax          # imm = 0x186A2
jmp 0x4d33
xorl %r14d, %r14d
xorl %r15d, %r15d
jmp 0x4b5a
movq (%r15), %r15
testq %r15, %r15
je 0x4d2a
cmpl $0x10, 0x18(%r15)
jne 0x4b93
imulq $0x844, %r14, %rax      # imm = 0x844
leaq (%rbx,%rax), %rdi
addq $0x4, %rdi
movq 0x20(%r15), %rcx
leaq 0x59c5(%rip), %rdx      # 0xa549
pushq $0x40
popq %rsi
xorl %eax, %eax
callq 0x42b0
incq %r14
jmp 0x4b57
leaq 0x54e0(%rip), %rsi      # 0xa07a
movq %r15, %rdi
callq 0x40d0
testq %rax, %rax
je 0x4d1b
imulq $0x844, %r14, %r12      # imm = 0x844
leaq (%rbx,%r12), %r13
addq $0x4, %r13
movq 0x20(%rax), %rcx
leaq 0x5984(%rip), %rdx      # 0xa549
pushq $0x40
popq %rsi
movq %r13, %rdi
xorl %eax, %eax
callq 0x42b0
leaq 0x54ac(%rip), %rsi      # 0xa085
movq %r15, %rdi
callq 0x40d0
testq %rax, %rax
je 0x4d1b
cmpl $0x10, 0x18(%rax)
jne 0x4d1b
addq %rbx, %r12
movq 0x20(%rax), %rdi
callq 0x4300
movl %eax, (%r12)
leaq 0x547f(%rip), %rsi      # 0xa08a
movq %r15, %rdi
callq 0x40d0
testq %rax, %rax
je 0x4d1b
movl (%r12), %ecx
cmpq $0x8, %rcx
ja 0x4cda
leaq 0x53f3(%rip), %rdx      # 0xa024
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
addq $0x44, %r12
movl 0x28(%rax), %ecx
leaq 0x5b6e(%rip), %rdx      # 0xa7b6
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
xorl %eax, %eax
callq 0x42b0
jmp 0x4b8e
addq $0x44, %r12
movq 0x20(%rax), %rcx
leaq 0x58de(%rip), %rdx      # 0xa549
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
jmp 0x4b87
addq $0x44, %r12
movsd 0x30(%rax), %xmm0
leaq 0x547b(%rip), %rdx      # 0xa103
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
movb $0x1, %al
callq 0x42b0
jmp 0x4b8e
movq %rax, %rdi
callq 0x40e0
testq %rax, %rax
je 0x4d42
movq %rax, %r13
addq $0x44, %r12
leaq 0x588e(%rip), %rdx      # 0xa549
movl $0x800, %esi            # imm = 0x800
movq %r12, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x42b0
movq %r13, %rdi
callq 0x4750
jmp 0x4b8e
movq %r13, 0x8(%rsp)
leaq 0x5421(%rip), %rax      # 0xa107
movq %rax, (%rsp)
leaq 0x539f(%rip), %rsi      # 0xa090
leaq 0x539e(%rip), %rdx      # 0xa096
leaq 0x539c(%rip), %rcx      # 0xa09b
leaq 0x53d9(%rip), %r8       # 0xa0df
pushq $0x3
popq %rdi
movl $0xeb, %r9d
xorl %eax, %eax
callq 0x4290
jmp 0x4b8e
movq %rbx, %rdi
callq 0x4750
movl $0x186a1, %eax          # imm = 0x186A1
jmp 0x4d33
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
leaq 0x53af(%rip), %rax      # 0xa0f8
movq %rax, (%rsp)
leaq 0x533c(%rip), %rsi      # 0xa090
leaq 0x533b(%rip), %rdx      # 0xa096
leaq 0x5339(%rip), %rcx      # 0xa09b
leaq 0x5376(%rip), %r8       # 0xa0df
pushq $0x3
popq %rdi
movl $0xe3, %r9d
xorl %eax, %eax
callq 0x4290
movq %rbx, %rdi
callq 0x4750
jmp 0x4b45