// File: /workspace/github_c_makefile_star2_O3/mruby-zest[P]osc-bridge/src/parse-schema.c
// Function: parse_schema
void parse_schema(const char *json, schema_t *sch)
{
    sch->elements = 0;
    sch->handles  = 0;

    /* Lexer example */
    mm_json_size len = strlen(json);

    /* create iterator  */
    struct mm_json_iter iter;
    iter = mm_json_begin(json, len);

    //Read in parameters
    struct mm_json_pair pair;
    iter = mm_json_parse(&pair, &iter);
    assert(!mm_json_cmp(&pair.name, "parameters"));
    assert(pair.value.type == MM_JSON_ARRAY);

    //Read in parameter objects
    struct mm_json_iter array = mm_json_begin(pair.value.str, pair.value.len);
    struct mm_json_token tok;
    array = mm_json_read(&tok, &array);
    while (array.src) {
        /* read single token */
        printf("new schema handle...\n");
        sch->elements += 1;
        sch->handles   = realloc(sch->handles, sch->elements*sizeof(schema_handle_t));

        schema_handle_t *handle = sch->handles+(sch->elements-1);
        memset(handle, 0, sizeof(schema_handle_t));

        struct mm_json_iter array2 = mm_json_begin(tok.str, tok.len);
        struct mm_json_pair pair2;
        array2 = mm_json_parse(&pair2, &array2);
        while (!array2.err) {
            assert(pair2.name.type == MM_JSON_STRING);
            printf("  ");
            print_string(pair2.name.str, pair2.name.len);
            unsigned pad = pair2.name.len < 10 ? 10-pair2.name.len : 0;
            for(unsigned i=0; i<pad; ++i)
                putchar(' ');

            if(pair2.value.type == MM_JSON_STRING) {
                printf(" = \"");
                print_string(pair2.value.str, pair2.value.len);
                printf("\"\n");

                struct mm_json_token v = pair2.value;
                if(mm_json_cmp(&pair2.name, "path") == 0)
                    handle->pattern = strndup(v.str, v.len);
                else if(mm_json_cmp(&pair2.name, "name") == 0)
                    handle->name = strndup(v.str, v.len);
                else if(mm_json_cmp(&pair2.name, "shortname") == 0)
                    handle->short_name = strndup(v.str, v.len);
                else if(mm_json_cmp(&pair2.name, "units") == 0)
                    handle->units = strndup(v.str, v.len);
                else if(mm_json_cmp(&pair2.name, "scale") == 0)
                    handle->scale = strndup(v.str, v.len);
                else if(mm_json_cmp(&pair2.name, "tooltip") == 0)
                    handle->documentation = strndup(v.str, v.len);
                else if(mm_json_cmp(&pair2.name, "default") == 0)
                    handle->default_ = strndup(v.str, v.len);
                else if(mm_json_cmp(&pair2.name, "type") == 0) {
                    if(v.str[0] == 'i')
                        handle->type = 'i';
                    else if(v.str[0] == 'f')
                        handle->type = 'f';
                    else if(v.str[0] == 'T')
                        handle->type = 'T';
                    else
                        handle->type = 0;
                }
            } else if(pair2.value.type == MM_JSON_ARRAY &&
                    mm_json_cmp(&pair2.name, "options") == 0) {
                handle->opts = parse_options(pair2.value.str, pair2.value.len);
            } else if(pair2.value.type == MM_JSON_ARRAY &&
                    mm_json_cmp(&pair2.name, "range") == 0) {
                parse_range(handle, pair2.value.str, pair2.value.len);
            } else
                printf(" = ????\n");
            array2 = mm_json_parse(&pair2, &array2);
        }

        //MM_JSON_OBJECT
        array = mm_json_read(&tok, &array);
    }

    {
        printf("ACTIONS...\n\n");
        iter = mm_json_parse(&pair, &iter);
        assert(!mm_json_cmp(&pair.name, "actions"));
        assert(pair.value.type == MM_JSON_ARRAY);

        //Read in parameter objects
        struct mm_json_iter array = mm_json_begin(pair.value.str, pair.value.len);
        struct mm_json_token tok;
        iter = mm_json_read(&tok, &array);
        while (array.src) {
            /* read single token */
            printf("field.type = %d\n", tok.type);
            struct mm_json_iter array2 = mm_json_begin(tok.str, tok.len);
            struct mm_json_pair pair2;
            array2 = mm_json_parse(&pair2, &array2);
            while (!array2.err) {
                assert(pair2.name.type == MM_JSON_STRING);
                printf("  field.name[");
                print_string(pair2.name.str, pair2.name.len);
                if(pair2.value.type == MM_JSON_STRING) {
                    printf("] = \"");
                    print_string(pair2.value.str, pair2.value.len);
                    printf("\"\n");
                } else
                    printf("] = ????\n");
                array2 = mm_json_parse(&pair2, &array2);
            }

            //MM_JSON_OBJECT
            array = mm_json_read(&tok, &array);
        }
    }

    return;

    /* read subobject (array/objects) */
    iter = mm_json_parse(&pair, &iter);
    printf("pair.name = %s\n", pair.name.str);
    printf("pair.value.type = %d\n", pair.value.type);
    assert(pair.value.type == MM_JSON_ARRAY);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, %rbx
movl $0x0, 0x10(%rsi)
movq %rsi, -0xc0(%rbp)
movq $0x0, 0x8(%rsi)
callq 0x20d0
movq %rax, %r14
xorps %xmm0, %xmm0
leaq -0x170(%rbp), %r15
movaps %xmm0, (%r15)
callq 0x4240
movq %rbx, 0x10(%r15)
movq %r14, 0x18(%r15)
leaq -0x110(%rbp), %rbx
leaq -0x1c0(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4c59
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movaps %xmm1, 0x10(%r15)
movaps %xmm0, (%r15)
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x5aa8
movq -0x1c0(%rbp), %rcx
xorl %edx, %edx
leaq 0x3cc5(%rip), %rsi      # 0x9751
cmpq $0xa, %rdx
je 0x5aa8
movb (%rcx,%rdx), %dil
cmpb (%rdx,%rsi), %dil
jne 0x624d
incq %rdx
cmpq %rdx, %rax
jne 0x5a8c
cmpl $0x2, -0x178(%rbp)
jne 0x628b
movups -0x198(%rbp), %xmm0
movaps %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
leaq -0x150(%rbp), %rbx
movaps %xmm0, (%rbx)
callq 0x4240
movaps -0x40(%rbp), %xmm0
movaps %xmm0, 0x10(%rbx)
leaq -0x110(%rbp), %r14
leaq -0x1e8(%rbp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4816
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movaps %xmm1, 0x10(%rbx)
movaps %xmm0, (%rbx)
cmpq $0x0, 0x10(%rbx)
je 0x607f
leaq -0x60(%rbp), %r13
leaq 0x3cd9(%rip), %r14      # 0x97f2
movq -0xc0(%rbp), %r15
movslq 0x10(%r15), %rax
incq %rax
movl %eax, 0x10(%r15)
movq 0x8(%r15), %rdi
imulq $0x58, %rax, %rsi
callq 0x2240
movq %rax, %rbx
movq %rax, 0x8(%r15)
movslq 0x10(%r15), %rax
imulq $0x58, %rax, %r15
xorps %xmm0, %xmm0
movups %xmm0, -0x58(%rbx,%r15)
movups %xmm0, -0x48(%rbx,%r15)
movups %xmm0, -0x38(%rbx,%r15)
movups %xmm0, -0x28(%rbx,%r15)
movups %xmm0, -0x18(%rbx,%r15)
movq $0x0, -0x8(%rbx,%r15)
movups -0x1e8(%rbp), %xmm1
movaps %xmm1, -0x40(%rbp)
movaps %xmm0, -0x90(%rbp)
callq 0x4240
movaps -0x40(%rbp), %xmm0
movaps %xmm0, -0x80(%rbp)
movq %r13, %rdi
leaq -0x110(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x4c59
movups -0x60(%rbp), %xmm0
movups -0x50(%rbp), %xmm1
movaps %xmm1, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
je 0x5c01
movq %r13, %rdi
leaq -0x1e8(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0x4816
movups -0x60(%rbp), %xmm0
movups -0x50(%rbp), %xmm1
movaps %xmm1, -0x140(%rbp)
movaps %xmm0, -0x150(%rbp)
cmpq $0x0, -0x140(%rbp)
jne 0x5b19
jmp 0x607f
leaq (%rbx,%r15), %rax
movq %rax, -0x40(%rbp)
leaq (%rbx,%r15), %rax
addq $-0x58, %rax
movq %rax, -0xb8(%rbp)
cmpl $0x4, -0xf0(%rbp)
jne 0x620f
movq -0x108(%rbp), %rax
movl -0xc8(%rbp), %ecx
cmpl $0x2, %ecx
je 0x5cca
cmpl $0x4, %ecx
jne 0x5d15
movq -0xe8(%rbp), %r12
movq -0xe0(%rbp), %rbx
testq %rax, %rax
leaq 0x3ba0(%rip), %rdi      # 0x97fc
je 0x5c83
movq -0x110(%rbp), %rcx
xorl %edx, %edx
cmpq $0x4, %rdx
je 0x5c83
movb (%rcx,%rdx), %sil
cmpb (%rdx,%r14), %sil
jne 0x5d50
incq %rdx
cmpq %rdx, %rax
jne 0x5c67
movq %rbx, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
movl $0x1, %esi
callq 0x2180
movq %rax, %r15
testl %ebx, %ebx
jle 0x5cc0
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x21e0
movq -0x40(%rbp), %rax
movq %r15, -0x48(%rax)
jmp 0x5d15
testq %rax, %rax
leaq 0x3b49(%rip), %rdi      # 0x981d
je 0x5cfb
movq -0x110(%rbp), %rcx
xorl %edx, %edx
cmpq $0x7, %rdx
je 0x5cfb
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x5db8
incq %rdx
cmpq %rdx, %rax
jne 0x5cdf
movq -0xe8(%rbp), %rdi
movl -0xe0(%rbp), %esi
callq 0x5593
movq -0x40(%rbp), %rcx
movq %rax, -0x50(%rcx)
movq %r13, %rdi
leaq -0x110(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x4c59
movups -0x60(%rbp), %xmm0
movups -0x50(%rbp), %xmm1
movaps %xmm1, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
je 0x5c18
jmp 0x5bc2
xorl %edx, %edx
cmpq $0x4, %rdx
je 0x5d6e
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x5dfb
incq %rdx
cmpq %rdx, %rax
jne 0x5d52
movq %rbx, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
movl $0x1, %esi
callq 0x2180
movq %rax, %r15
testl %ebx, %ebx
jle 0x5dab
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x21e0
movq -0x40(%rbp), %rax
movq %r15, -0x40(%rax)
jmp 0x5d15
xorl %edx, %edx
cmpq $0x5, %rdx
je 0x5ddd
movb (%rcx,%rdx), %sil
leaq 0x3a5a(%rip), %rdi      # 0x9825
cmpb (%rdx,%rdi), %sil
jne 0x5d15
incq %rdx
cmpq %rdx, %rax
jne 0x5dba
movq -0xe8(%rbp), %rsi
movl -0xe0(%rbp), %edx
movq -0xb8(%rbp), %rdi
callq 0x58c1
jmp 0x5d15
xorl %edx, %edx
leaq 0x39f3(%rip), %rdi      # 0x97f7
cmpq $0x9, %rdx
je 0x5e1c
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x5e66
incq %rdx
cmpq %rdx, %rax
jne 0x5e04
movq %rbx, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
movl $0x1, %esi
callq 0x2180
movq %rax, %r15
testl %ebx, %ebx
jle 0x5e59
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x21e0
movq -0x40(%rbp), %rax
movq %r15, -0x38(%rax)
jmp 0x5d15
xorl %edx, %edx
leaq 0x3992(%rip), %rdi      # 0x9801
cmpq $0x5, %rdx
je 0x5e87
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x5ed1
incq %rdx
cmpq %rdx, %rax
jne 0x5e6f
movq %rbx, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
movl $0x1, %esi
callq 0x2180
movq %rax, %r15
testl %ebx, %ebx
jle 0x5ec4
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x21e0
movq -0x40(%rbp), %rax
movq %r15, -0x30(%rax)
jmp 0x5d15
xorl %edx, %edx
leaq 0x392d(%rip), %rdi      # 0x9807
cmpq $0x5, %rdx
je 0x5ef2
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x5f3c
incq %rdx
cmpq %rdx, %rax
jne 0x5eda
movq %rbx, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
movl $0x1, %esi
callq 0x2180
movq %rax, %r15
testl %ebx, %ebx
jle 0x5f2f
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x21e0
movq -0x40(%rbp), %rax
movq %r15, -0x20(%rax)
jmp 0x5d15
xorl %edx, %edx
leaq 0x38c8(%rip), %rdi      # 0x980d
cmpq $0x7, %rdx
je 0x5f5d
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x5fa7
incq %rdx
cmpq %rdx, %rax
jne 0x5f45
movq %rbx, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
movl $0x1, %esi
callq 0x2180
movq %rax, %r15
testl %ebx, %ebx
jle 0x5f9a
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x21e0
movq -0x40(%rbp), %rax
movq %r15, -0x28(%rax)
jmp 0x5d15
xorl %edx, %edx
leaq 0x3865(%rip), %rdi      # 0x9815
cmpq $0x7, %rdx
je 0x5fc8
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x6012
incq %rdx
cmpq %rdx, %rax
jne 0x5fb0
movq %rbx, %rdi
shlq $0x20, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %rdi
sarq $0x20, %rdi
movl $0x1, %esi
callq 0x2180
movq %rax, %r15
testl %ebx, %ebx
jle 0x6005
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x21e0
movq -0x40(%rbp), %rax
movq %r15, -0x18(%rax)
jmp 0x5d15
xorl %edx, %edx
cmpq $0x4, %rdx
je 0x6037
movb (%rcx,%rdx), %sil
leaq 0x3e9e(%rip), %rdi      # 0x9ec3
cmpb (%rdx,%rdi), %sil
jne 0x5d15
incq %rdx
cmpq %rdx, %rax
jne 0x6014
movzbl (%r12), %eax
cmpl $0x54, %eax
je 0x6065
cmpl $0x66, %eax
je 0x6058
cmpl $0x69, %eax
jne 0x6072
movq -0x40(%rbp), %rax
movb $0x69, -0x10(%rax)
jmp 0x5d15
movq -0x40(%rbp), %rax
movb $0x66, -0x10(%rax)
jmp 0x5d15
movq -0x40(%rbp), %rax
movb $0x54, -0x10(%rax)
jmp 0x5d15
movq -0x40(%rbp), %rax
movb $0x0, -0x10(%rax)
jmp 0x5d15
leaq -0x110(%rbp), %rbx
leaq -0x1c0(%rbp), %r14
leaq -0x170(%rbp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4c59
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movaps %xmm1, 0x10(%r15)
movaps %xmm0, (%r15)
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x60e7
movq -0x1c0(%rbp), %rcx
xorl %edx, %edx
leaq 0x3760(%rip), %rsi      # 0x982b
cmpq $0x7, %rdx
je 0x60e7
movb (%rcx,%rdx), %dil
cmpb (%rdx,%rsi), %dil
jne 0x626c
incq %rdx
cmpq %rdx, %rax
jne 0x60cb
cmpl $0x2, -0x178(%rbp)
jne 0x62aa
movq -0x198(%rbp), %r15
movq -0x190(%rbp), %r14
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %rbx
movaps %xmm0, (%rbx)
callq 0x4240
movq %r15, 0x10(%rbx)
movq %r14, 0x18(%rbx)
leaq -0x110(%rbp), %r14
leaq -0x90(%rbp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4816
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movaps %xmm1, -0x160(%rbp)
movaps %xmm0, -0x170(%rbp)
testq %r15, %r15
je 0x61fd
leaq -0x130(%rbp), %rbx
leaq -0xb0(%rbp), %r15
leaq -0x90(%rbp), %r12
leaq -0x60(%rbp), %r13
movups -0x90(%rbp), %xmm0
movaps %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xb0(%rbp)
callq 0x4240
movaps -0x40(%rbp), %xmm0
movaps %xmm0, -0xa0(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4c59
movups -0x130(%rbp), %xmm0
movups -0x120(%rbp), %xmm1
movaps %xmm1, -0xa0(%rbp)
movaps %xmm0, -0xb0(%rbp)
cmpl $0x0, -0xb0(%rbp)
jne 0x61ce
cmpl $0x4, -0xf0(%rbp)
je 0x6190
jmp 0x622e
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x4816
movups -0x130(%rbp), %xmm0
movups -0x120(%rbp), %xmm1
movaps %xmm1, -0x50(%rbp)
movaps %xmm0, -0x60(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x616b
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x35ba(%rip), %rdi      # 0x97d0
leaq 0x340c(%rip), %rsi      # 0x9629
leaq 0x355f(%rip), %rcx      # 0x9783
movl $0x91, %edx
callq 0x2130
leaq 0x359b(%rip), %rdi      # 0x97d0
leaq 0x33ed(%rip), %rsi      # 0x9629
leaq 0x3540(%rip), %rcx      # 0x9783
movl $0xd6, %edx
callq 0x2130
leaq 0x3508(%rip), %rdi      # 0x975c
leaq 0x33ce(%rip), %rsi      # 0x9629
leaq 0x3521(%rip), %rcx      # 0x9783
movl $0x7d, %edx
callq 0x2130
leaq 0x35c0(%rip), %rdi      # 0x9833
leaq 0x33af(%rip), %rsi      # 0x9629
leaq 0x3502(%rip), %rcx      # 0x9783
movl $0xc8, %edx
callq 0x2130
leaq 0x351d(%rip), %rdi      # 0x97af
leaq 0x3390(%rip), %rsi      # 0x9629
leaq 0x34e3(%rip), %rcx      # 0x9783
movl $0x7e, %edx
callq 0x2130
leaq 0x34fe(%rip), %rdi      # 0x97af
leaq 0x3371(%rip), %rsi      # 0x9629
leaq 0x34c4(%rip), %rcx      # 0x9783
movl $0xc9, %edx
callq 0x2130
nopl (%rax)