// File: /workspace/github_c_makefile_star2_O0/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
subq $0x3a0, %rsp            # imm = 0x3A0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rdi
callq 0x20b0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x5b40
movq -0x58(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x6200
movq -0xc8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0xa8(%rbp), %rdi
leaq 0x5090(%rip), %rsi      # 0xc789
callq 0x5a90
cmpl $0x0, %eax
jne 0x7705
jmp 0x7724
leaq 0x5088(%rip), %rdi      # 0xc794
leaq 0x4f4e(%rip), %rsi      # 0xc661
movl $0x7d, %edx
leaq 0x509c(%rip), %rcx      # 0xc7bb
callq 0x2120
cmpl $0x2, -0x60(%rbp)
jne 0x772c
jmp 0x774b
leaq 0x50b4(%rip), %rdi      # 0xc7e7
leaq 0x4f27(%rip), %rsi      # 0xc661
movl $0x7e, %edx
leaq 0x5075(%rip), %rcx      # 0xc7bb
callq 0x2120
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq -0xe8(%rbp), %rdi
callq 0x5b40
leaq -0x130(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x5b90
movq -0x130(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x128(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0xd0(%rbp)
cmpq $0x0, -0xd8(%rbp)
je 0x7d1e
jmp 0x77c1
jmp 0x77c3
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rax
imulq $0x58, %rax, %rsi
callq 0x2230
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x138(%rbp)
movq -0x138(%rbp), %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0x2130
movq -0x110(%rbp), %rsi
movq -0x108(%rbp), %rdx
leaq -0x158(%rbp), %rdi
callq 0x5b40
leaq -0x1c8(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
leaq -0x158(%rbp), %rdx
callq 0x6200
movq -0x1c8(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x1c0(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x1b8(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x1b0(%rbp), %rax
movq %rax, -0x140(%rbp)
cmpl $0x0, -0x158(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x78ab
jmp 0x7cc7
cmpl $0x4, -0x188(%rbp)
jne 0x78b6
jmp 0x78d5
leaq 0x4f4b(%rip), %rdi      # 0xc808
leaq 0x4d9d(%rip), %rsi      # 0xc661
movl $0x91, %edx
leaq 0x4eeb(%rip), %rcx      # 0xc7bb
callq 0x2120
jmp 0x78d7
jmp 0x78d9
movq -0x1a8(%rbp), %rdi
movq -0x1a0(%rbp), %rax
movl %eax, %esi
callq 0x7100
cmpq $0xa, -0x1a0(%rbp)
jae 0x790d
movl $0xa, %eax
subq -0x1a0(%rbp), %rax
movq %rax, -0x398(%rbp)
jmp 0x7918
xorl %eax, %eax
movq %rax, -0x398(%rbp)
jmp 0x7918
movq -0x398(%rbp), %rax
movl %eax, -0x1cc(%rbp)
movl $0x0, -0x1d0(%rbp)
movl -0x1d0(%rbp), %eax
cmpl -0x1cc(%rbp), %eax
jae 0x7950
jmp 0x793f
movl -0x1d0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1d0(%rbp)
jmp 0x792f
cmpl $0x4, -0x160(%rbp)
jne 0x7be1
jmp 0x795f
jmp 0x7961
movq -0x180(%rbp), %rdi
movq -0x178(%rbp), %rax
movl %eax, %esi
callq 0x7100
jmp 0x7978
leaq -0x1a8(%rbp), %rsi
addq $0x28, %rsi
leaq -0x1f8(%rbp), %rdi
movl $0x28, %edx
callq 0x21e0
leaq -0x1a8(%rbp), %rdi
leaq 0x4e88(%rip), %rsi      # 0xc82a
callq 0x5a90
cmpl $0x0, %eax
jne 0x79d4
movq -0x1f8(%rbp), %rdi
movq -0x1f0(%rbp), %rax
movl %eax, %esi
callq 0x7480
movq %rax, %rcx
movq -0x138(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x7bdc
leaq -0x1a8(%rbp), %rdi
leaq 0x4e52(%rip), %rsi      # 0xc834
callq 0x5a90
cmpl $0x0, %eax
jne 0x7a14
movq -0x1f8(%rbp), %rdi
movq -0x1f0(%rbp), %rax
movl %eax, %esi
callq 0x7480
movq %rax, %rcx
movq -0x138(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x7bda
leaq -0x1a8(%rbp), %rdi
leaq 0x4e0d(%rip), %rsi      # 0xc82f
callq 0x5a90
cmpl $0x0, %eax
jne 0x7a54
movq -0x1f8(%rbp), %rdi
movq -0x1f0(%rbp), %rax
movl %eax, %esi
callq 0x7480
movq %rax, %rcx
movq -0x138(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x7bd8
leaq -0x1a8(%rbp), %rdi
leaq 0x4dd7(%rip), %rsi      # 0xc839
callq 0x5a90
cmpl $0x0, %eax
jne 0x7a94
movq -0x1f8(%rbp), %rdi
movq -0x1f0(%rbp), %rax
movl %eax, %esi
callq 0x7480
movq %rax, %rcx
movq -0x138(%rbp), %rax
movq %rcx, 0x28(%rax)
jmp 0x7bd6
leaq -0x1a8(%rbp), %rdi
leaq 0x4d9d(%rip), %rsi      # 0xc83f
callq 0x5a90
cmpl $0x0, %eax
jne 0x7ad4
movq -0x1f8(%rbp), %rdi
movq -0x1f0(%rbp), %rax
movl %eax, %esi
callq 0x7480
movq %rax, %rcx
movq -0x138(%rbp), %rax
movq %rcx, 0x38(%rax)
jmp 0x7bd4
leaq -0x1a8(%rbp), %rdi
leaq 0x4d63(%rip), %rsi      # 0xc845
callq 0x5a90
cmpl $0x0, %eax
jne 0x7b14
movq -0x1f8(%rbp), %rdi
movq -0x1f0(%rbp), %rax
movl %eax, %esi
callq 0x7480
movq %rax, %rcx
movq -0x138(%rbp), %rax
movq %rcx, 0x30(%rax)
jmp 0x7bd2
leaq -0x1a8(%rbp), %rdi
leaq 0x4d2b(%rip), %rsi      # 0xc84d
callq 0x5a90
cmpl $0x0, %eax
jne 0x7b51
movq -0x1f8(%rbp), %rdi
movq -0x1f0(%rbp), %rax
movl %eax, %esi
callq 0x7480
movq %rax, %rcx
movq -0x138(%rbp), %rax
movq %rcx, 0x40(%rax)
jmp 0x7bd0
leaq -0x1a8(%rbp), %rdi
leaq 0x55ba(%rip), %rsi      # 0xd119
callq 0x5a90
cmpl $0x0, %eax
jne 0x7bce
movq -0x1f8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x69, %eax
jne 0x7b85
movq -0x138(%rbp), %rax
movb $0x69, 0x48(%rax)
jmp 0x7bcc
movq -0x1f8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x66, %eax
jne 0x7ba1
movq -0x138(%rbp), %rax
movb $0x66, 0x48(%rax)
jmp 0x7bca
movq -0x1f8(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x54, %eax
jne 0x7bbd
movq -0x138(%rbp), %rax
movb $0x54, 0x48(%rax)
jmp 0x7bc8
movq -0x138(%rbp), %rax
movb $0x0, 0x48(%rax)
jmp 0x7bca
jmp 0x7bcc
jmp 0x7bce
jmp 0x7bd0
jmp 0x7bd2
jmp 0x7bd4
jmp 0x7bd6
jmp 0x7bd8
jmp 0x7bda
jmp 0x7bdc
jmp 0x7c70
cmpl $0x2, -0x160(%rbp)
jne 0x7c27
leaq -0x1a8(%rbp), %rdi
leaq 0x4c5d(%rip), %rsi      # 0xc855
callq 0x5a90
cmpl $0x0, %eax
jne 0x7c27
movq -0x180(%rbp), %rdi
movq -0x178(%rbp), %rax
movl %eax, %esi
callq 0x7130
movq %rax, %rcx
movq -0x138(%rbp), %rax
movq %rcx, 0x8(%rax)
jmp 0x7c6e
cmpl $0x2, -0x160(%rbp)
jne 0x7c66
leaq -0x1a8(%rbp), %rdi
leaq 0x4c1f(%rip), %rsi      # 0xc85d
callq 0x5a90
cmpl $0x0, %eax
jne 0x7c66
movq -0x138(%rbp), %rdi
movq -0x180(%rbp), %rsi
movq -0x178(%rbp), %rax
movl %eax, %edx
callq 0x74e0
jmp 0x7c6c
jmp 0x7c68
jmp 0x7c6a
jmp 0x7c6c
jmp 0x7c6e
jmp 0x7c70
leaq -0x218(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
leaq -0x158(%rbp), %rdx
callq 0x6200
movq -0x218(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x210(%rbp), %rax
movq %rax, -0x150(%rbp)
movq -0x208(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x200(%rbp), %rax
movq %rax, -0x140(%rbp)
jmp 0x7896
leaq -0x238(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x5b90
movq -0x238(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x230(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x228(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x220(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0x77b1
jmp 0x7d20
jmp 0x7d22
leaq -0x258(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x6200
movq -0x258(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x250(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x248(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x240(%rbp), %rax
movq %rax, -0x20(%rbp)
leaq -0xa8(%rbp), %rdi
leaq 0x4af0(%rip), %rsi      # 0xc863
callq 0x5a90
cmpl $0x0, %eax
jne 0x7d7f
jmp 0x7d9e
leaq 0x4ae5(%rip), %rdi      # 0xc86b
leaq 0x48d4(%rip), %rsi      # 0xc661
movl $0xc8, %edx
leaq 0x4a22(%rip), %rcx      # 0xc7bb
callq 0x2120
cmpl $0x2, -0x60(%rbp)
jne 0x7da6
jmp 0x7dc5
leaq 0x4a3a(%rip), %rdi      # 0xc7e7
leaq 0x48ad(%rip), %rsi      # 0xc661
movl $0xc9, %edx
leaq 0x49fb(%rip), %rcx      # 0xc7bb
callq 0x2120
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq -0x278(%rbp), %rdi
callq 0x5b40
leaq -0x2c0(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
leaq -0x278(%rbp), %rdx
callq 0x5b90
movq -0x2c0(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x2b8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x2b0(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x2a8(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x268(%rbp)
je 0x7fcf
jmp 0x7e2f
jmp 0x7e31
movq -0x2a0(%rbp), %rsi
movq -0x298(%rbp), %rdx
leaq -0x2e0(%rbp), %rdi
callq 0x5b40
leaq -0x350(%rbp), %rdi
leaq -0x330(%rbp), %rsi
leaq -0x2e0(%rbp), %rdx
callq 0x6200
movq -0x350(%rbp), %rax
movq %rax, -0x2e0(%rbp)
movq -0x348(%rbp), %rax
movq %rax, -0x2d8(%rbp)
movq -0x340(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0x338(%rbp), %rax
movq %rax, -0x2c8(%rbp)
cmpl $0x0, -0x2e0(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x7eb2
jmp 0x7f78
cmpl $0x4, -0x310(%rbp)
jne 0x7ebd
jmp 0x7edc
leaq 0x4944(%rip), %rdi      # 0xc808
leaq 0x4796(%rip), %rsi      # 0xc661
movl $0xd6, %edx
leaq 0x48e4(%rip), %rcx      # 0xc7bb
callq 0x2120
jmp 0x7ede
jmp 0x7ee0
movq -0x330(%rbp), %rdi
movq -0x328(%rbp), %rax
movl %eax, %esi
callq 0x7100
cmpl $0x4, -0x2e8(%rbp)
jne 0x7f1b
jmp 0x7f00
jmp 0x7f02
movq -0x308(%rbp), %rdi
movq -0x300(%rbp), %rax
movl %eax, %esi
callq 0x7100
jmp 0x7f19
jmp 0x7f21
jmp 0x7f1d
jmp 0x7f1f
jmp 0x7f21
leaq -0x370(%rbp), %rdi
leaq -0x330(%rbp), %rsi
leaq -0x2e0(%rbp), %rdx
callq 0x6200
movq -0x370(%rbp), %rax
movq %rax, -0x2e0(%rbp)
movq -0x368(%rbp), %rax
movq %rax, -0x2d8(%rbp)
movq -0x360(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0x358(%rbp), %rax
movq %rax, -0x2c8(%rbp)
jmp 0x7e9d
leaq -0x390(%rbp), %rdi
leaq -0x2a0(%rbp), %rsi
leaq -0x278(%rbp), %rdx
callq 0x5b90
movq -0x390(%rbp), %rax
movq %rax, -0x278(%rbp)
movq -0x388(%rbp), %rax
movq %rax, -0x270(%rbp)
movq -0x380(%rbp), %rax
movq %rax, -0x268(%rbp)
movq -0x378(%rbp), %rax
movq %rax, -0x260(%rbp)
jmp 0x7e1f
addq $0x3a0, %rsp            # imm = 0x3A0
popq %rbp
retq
nopl (%rax,%rax)