// File: /workspace/github_c_makefile_star2_O1/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 $0x1d8, %rsp            # imm = 0x1D8
movq %rdi, %rbx
movl $0x0, 0x10(%rsi)
movq %rsi, -0x120(%rbp)
movq $0x0, 0x8(%rsi)
callq 0x20d0
movq %rax, %r14
callq 0x4254
xorps %xmm0, %xmm0
leaq -0x180(%rbp), %r15
movaps %xmm0, (%r15)
movq %rbx, 0x10(%r15)
movq %r14, 0x18(%r15)
leaq -0xf0(%rbp), %rbx
leaq -0x1d0(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4c99
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movaps %xmm1, 0x10(%r15)
movaps %xmm0, (%r15)
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x5ad0
movq -0x1d0(%rbp), %rcx
xorl %edx, %edx
leaq 0x3c9d(%rip), %rsi      # 0x9751
cmpq $0xa, %rdx
je 0x5ad0
movb (%rcx,%rdx), %dil
cmpb (%rdx,%rsi), %dil
jne 0x6306
incq %rdx
cmpq %rdx, %rax
jne 0x5ab4
cmpl $0x2, -0x188(%rbp)
jne 0x6344
movups -0x1a8(%rbp), %xmm0
movaps %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
leaq -0x160(%rbp), %rbx
movaps %xmm0, (%rbx)
movaps %xmm0, 0x10(%rbx)
callq 0x4254
movaps -0x40(%rbp), %xmm0
movaps %xmm0, 0x10(%rbx)
leaq -0xf0(%rbp), %r14
leaq -0x1f8(%rbp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4833
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movaps %xmm1, 0x10(%rbx)
movaps %xmm0, (%rbx)
cmpq $0x0, 0x10(%rbx)
je 0x612e
leaq -0x70(%rbp), %r13
leaq 0x3cad(%rip), %r14      # 0x97f2
movq -0x120(%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 -0x1f8(%rbp), %xmm1
movaps %xmm1, -0x40(%rbp)
movaps %xmm0, -0xa0(%rbp)
movaps %xmm0, -0x90(%rbp)
callq 0x4254
movaps -0x40(%rbp), %xmm0
movaps %xmm0, -0x90(%rbp)
movq %r13, %rdi
leaq -0xf0(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x4c99
movups -0x70(%rbp), %xmm0
movups -0x60(%rbp), %xmm1
movaps %xmm1, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
cmpl $0x0, -0xa0(%rbp)
je 0x5c3a
movq %r13, %rdi
leaq -0x1f8(%rbp), %rsi
leaq -0x160(%rbp), %rdx
callq 0x4833
movups -0x70(%rbp), %xmm0
movups -0x60(%rbp), %xmm1
movaps %xmm1, -0x150(%rbp)
movaps %xmm0, -0x160(%rbp)
cmpq $0x0, -0x150(%rbp)
jne 0x5b45
jmp 0x612e
leaq (%rbx,%r15), %rax
movq %rax, -0x40(%rbp)
leaq (%rbx,%r15), %rax
addq $-0x58, %rax
movq %rax, -0x118(%rbp)
cmpl $0x4, -0xd0(%rbp)
jne 0x62c8
movq -0xe8(%rbp), %rax
movl -0xa8(%rbp), %ecx
cmpl $0x2, %ecx
je 0x5cfc
cmpl $0x4, %ecx
jne 0x5d47
movq -0xc8(%rbp), %r12
movq -0xc0(%rbp), %rbx
testq %rax, %rax
je 0x5cb5
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x4, %rdx
je 0x5cb5
movb (%rcx,%rdx), %sil
cmpb (%rdx,%r14), %sil
jne 0x5d85
incq %rdx
cmpq %rdx, %rax
jne 0x5c99
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 0x5cf2
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 0x5d47
testq %rax, %rax
leaq 0x3b17(%rip), %r8       # 0x981d
je 0x5d2d
movq -0xf0(%rbp), %rdx
xorl %esi, %esi
cmpq $0x7, %rsi
je 0x5d2d
movb (%rdx,%rsi), %dil
cmpb (%rsi,%r8), %dil
jne 0x5e00
incq %rsi
cmpq %rsi, %rax
jne 0x5d11
movq -0xc8(%rbp), %rdi
movl -0xc0(%rbp), %esi
callq 0x55fb
movq -0x40(%rbp), %rcx
movq %rax, -0x50(%rcx)
movq %r13, %rdi
leaq -0xf0(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x4c99
movups -0x70(%rbp), %xmm0
movups -0x60(%rbp), %xmm1
movaps %xmm1, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
cmpl $0x0, -0xa0(%rbp)
je 0x5c51
jmp 0x5bfb
testq %rax, %rax
je 0x5db6
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x4, %rdx
je 0x5db6
movb (%rcx,%rdx), %sil
leaq 0x3a58(%rip), %rdi      # 0x97fc
cmpb (%rdx,%rdi), %sil
jne 0x5e53
incq %rdx
cmpq %rdx, %rax
jne 0x5d93
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 0x5df3
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 0x5d47
cmpl $0x2, %ecx
jne 0x5d47
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x5, %rdx
je 0x5e35
movb (%rcx,%rdx), %sil
leaq 0x3a02(%rip), %rdi      # 0x9825
cmpb (%rdx,%rdi), %sil
jne 0x5d47
incq %rdx
cmpq %rdx, %rax
jne 0x5e12
movq -0xc8(%rbp), %rsi
movl -0xc0(%rbp), %edx
movq -0x118(%rbp), %rdi
callq 0x58e4
jmp 0x5d47
testq %rax, %rax
leaq 0x399a(%rip), %rdi      # 0x97f7
je 0x5e80
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x9, %rdx
je 0x5e80
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x5ecf
incq %rdx
cmpq %rdx, %rax
jne 0x5e68
movq %r12, -0x48(%rbp)
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 0x5ec2
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq -0x48(%rbp), %rsi
movq %rbx, %rdx
callq 0x21e0
movq -0x40(%rbp), %rax
movq %r15, -0x38(%rax)
jmp 0x5d47
testq %rax, %rax
leaq 0x3928(%rip), %rdi      # 0x9801
je 0x5efc
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x5, %rdx
je 0x5efc
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x5f46
incq %rdx
cmpq %rdx, %rax
jne 0x5ee4
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 0x5f39
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 0x5d47
testq %rax, %rax
leaq 0x38b7(%rip), %rdi      # 0x9807
je 0x5f73
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x5, %rdx
je 0x5f73
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x5fc2
incq %rdx
cmpq %rdx, %rax
jne 0x5f5b
movq %r12, -0x48(%rbp)
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 0x5fb5
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq -0x48(%rbp), %rsi
movq %rbx, %rdx
callq 0x21e0
movq -0x40(%rbp), %rax
movq %r15, -0x20(%rax)
jmp 0x5d47
testq %rax, %rax
leaq 0x3841(%rip), %rdi      # 0x980d
je 0x5fef
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x7, %rdx
je 0x5fef
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x6039
incq %rdx
cmpq %rdx, %rax
jne 0x5fd7
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 0x602c
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 0x5d47
testq %rax, %rax
leaq 0x37d2(%rip), %rdi      # 0x9815
je 0x6066
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x7, %rdx
je 0x6066
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x60b5
incq %rdx
cmpq %rdx, %rax
jne 0x604e
movq %r12, -0x48(%rbp)
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 0x60a8
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq %r15, %rdi
movq -0x48(%rbp), %rsi
movq %rbx, %rdx
callq 0x21e0
movq -0x40(%rbp), %rax
movq %r15, -0x18(%rax)
jmp 0x5d47
testq %rax, %rax
je 0x60e6
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x4, %rdx
je 0x60e6
movb (%rcx,%rdx), %sil
leaq 0x3def(%rip), %rdi      # 0x9ec3
cmpb (%rdx,%rdi), %sil
jne 0x5d47
incq %rdx
cmpq %rdx, %rax
jne 0x60c3
movzbl (%r12), %eax
cmpl $0x54, %eax
je 0x6114
cmpl $0x66, %eax
je 0x6107
cmpl $0x69, %eax
jne 0x6121
movq -0x40(%rbp), %rax
movb $0x69, -0x10(%rax)
jmp 0x5d47
movq -0x40(%rbp), %rax
movb $0x66, -0x10(%rax)
jmp 0x5d47
movq -0x40(%rbp), %rax
movb $0x54, -0x10(%rax)
jmp 0x5d47
movq -0x40(%rbp), %rax
movb $0x0, -0x10(%rax)
jmp 0x5d47
leaq -0xf0(%rbp), %rbx
leaq -0x1d0(%rbp), %r14
leaq -0x180(%rbp), %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4c99
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movaps %xmm1, 0x10(%r15)
movaps %xmm0, (%r15)
movq 0x8(%r14), %rax
testq %rax, %rax
je 0x6196
movq -0x1d0(%rbp), %rcx
xorl %edx, %edx
leaq 0x36b1(%rip), %rsi      # 0x982b
cmpq $0x7, %rdx
je 0x6196
movb (%rcx,%rdx), %dil
cmpb (%rdx,%rsi), %dil
jne 0x6325
incq %rdx
cmpq %rdx, %rax
jne 0x617a
cmpl $0x2, -0x188(%rbp)
jne 0x6363
movups -0x1a8(%rbp), %xmm0
movaps %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rbx
movaps %xmm0, (%rbx)
movaps %xmm0, 0x10(%rbx)
callq 0x4254
movaps -0x40(%rbp), %xmm0
movaps %xmm0, 0x10(%rbx)
leaq -0xf0(%rbp), %r14
leaq -0xa0(%rbp), %rsi
movq %r14, %rdi
movq %rbx, %rdx
callq 0x4833
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movaps %xmm1, -0x170(%rbp)
movaps %xmm0, -0x180(%rbp)
cmpq $0x0, 0x10(%rbx)
je 0x62b6
leaq -0x140(%rbp), %rbx
leaq -0x110(%rbp), %r15
leaq -0xa0(%rbp), %r12
leaq -0x70(%rbp), %r13
movups -0xa0(%rbp), %xmm0
movaps %xmm0, -0x40(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x110(%rbp)
movaps %xmm0, -0x100(%rbp)
callq 0x4254
movaps -0x40(%rbp), %xmm0
movaps %xmm0, -0x100(%rbp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x4c99
movups -0x140(%rbp), %xmm0
movups -0x130(%rbp), %xmm1
movaps %xmm1, -0x100(%rbp)
movaps %xmm0, -0x110(%rbp)
cmpl $0x0, -0x110(%rbp)
jne 0x6287
cmpl $0x4, -0xd0(%rbp)
je 0x6249
jmp 0x62e7
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x4833
movups -0x140(%rbp), %xmm0
movups -0x130(%rbp), %xmm1
movaps %xmm1, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x621d
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3501(%rip), %rdi      # 0x97d0
leaq 0x3353(%rip), %rsi      # 0x9629
leaq 0x34a6(%rip), %rcx      # 0x9783
movl $0x91, %edx
callq 0x2130
leaq 0x34e2(%rip), %rdi      # 0x97d0
leaq 0x3334(%rip), %rsi      # 0x9629
leaq 0x3487(%rip), %rcx      # 0x9783
movl $0xd6, %edx
callq 0x2130
leaq 0x344f(%rip), %rdi      # 0x975c
leaq 0x3315(%rip), %rsi      # 0x9629
leaq 0x3468(%rip), %rcx      # 0x9783
movl $0x7d, %edx
callq 0x2130
leaq 0x3507(%rip), %rdi      # 0x9833
leaq 0x32f6(%rip), %rsi      # 0x9629
leaq 0x3449(%rip), %rcx      # 0x9783
movl $0xc8, %edx
callq 0x2130
leaq 0x3464(%rip), %rdi      # 0x97af
leaq 0x32d7(%rip), %rsi      # 0x9629
leaq 0x342a(%rip), %rcx      # 0x9783
movl $0x7e, %edx
callq 0x2130
leaq 0x3445(%rip), %rdi      # 0x97af
leaq 0x32b8(%rip), %rsi      # 0x9629
leaq 0x340b(%rip), %rcx      # 0x9783
movl $0xc9, %edx
callq 0x2130
nop