// File: /workspace/github_c_makefile_star2_O3/mruby-zest[P]osc-bridge/src/parse-schema.c
// Function: parse_options
opt_t *parse_options(const char *str, int len)
{
    printf("parse options...\n");
    opt_t *o = calloc(1, sizeof(opt_t));
    struct mm_json_iter array = mm_json_begin(str, len);
    struct mm_json_token tok;
    array = mm_json_read(&tok, &array);
    while(array.src) {
        //printf("option?\n");

        int   id   = 0xcafebeef;
        char *text = 0;

        struct mm_json_iter array2 = mm_json_begin(tok.str, tok.len);
        struct mm_json_pair pair;
        array2 = mm_json_parse(&pair, &array2);
        while (!array2.err) {
            assert(pair.name.type == MM_JSON_STRING);

            if(pair.value.type == MM_JSON_STRING) {
                struct mm_json_token v = pair.value;
                if(mm_json_cmp(&pair.name, "value") == 0)
                    text = strndup(v.str, v.len);
            } else if(pair.value.type == MM_JSON_NUMBER) {
                struct mm_json_token v = pair.value;
                if(mm_json_cmp(&pair.name, "id") == 0)
                    id = atoi(v.str);
            } else
                printf(" = ????\n");

            array2 = mm_json_parse(&pair, &array2);
        }

        assert(id != (int) 0xcafebeef);

        //Add to the list of options
        o->num_opts++;
        o->ids = realloc(o->ids, sizeof(o->ids[0])*o->num_opts);
        o->labels = realloc(o->labels, sizeof(o->labels[0])*o->num_opts);
        o->ids[o->num_opts-1]    = id;
        o->labels[o->num_opts-1] = text;
        //printf(" %d -> <%s>\n", id, text);


        array = mm_json_read(&tok, &array);
    }
    return o;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movl %esi, %ebx
movq %rdi, %r14
movl $0x1, %edi
movl $0x18, %esi
callq 0x2180
movq %rax, -0x30(%rbp)
movslq %ebx, %r15
xorps %xmm0, %xmm0
leaq -0x110(%rbp), %rbx
movaps %xmm0, (%rbx)
callq 0x4240
movq %r14, 0x10(%rbx)
movq %r15, 0x18(%rbx)
leaq -0xf0(%rbp), %r14
leaq -0x138(%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 0x586d
movq $0x0, -0x40(%rbp)
leaq -0x68(%rbp), %r12
leaq -0xf0(%rbp), %r15
leaq 0x403a(%rip), %r14      # 0x9664
movq $0x0, -0x38(%rbp)
xorl %eax, %eax
movq %rax, -0x48(%rbp)
movups -0x138(%rbp), %xmm0
movaps %xmm0, -0xa0(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x90(%rbp)
callq 0x4240
movaps -0xa0(%rbp), %xmm0
movaps %xmm0, -0x80(%rbp)
movq %r12, %rdi
movq %r15, %rsi
leaq -0x90(%rbp), %rdx
callq 0x4c59
movups -0x68(%rbp), %xmm0
movups -0x58(%rbp), %xmm1
movaps %xmm1, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
jne 0x58a2
movl $0xcafebeef, %ebx       # imm = 0xCAFEBEEF
xorl %edi, %edi
cmpl $0x4, -0xd0(%rbp)
jne 0x5883
movl -0xa8(%rbp), %eax
cmpl $0x3, %eax
je 0x5729
cmpl $0x4, %eax
jne 0x5770
movq -0xe8(%rbp), %rax
movq -0xc8(%rbp), %r12
movq -0xc0(%rbp), %r15
testq %rax, %rax
je 0x56f9
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x5, %rdx
je 0x56f9
movb (%rcx,%rdx), %sil
cmpb (%rdx,%r14), %sil
jne 0x577a
incq %rdx
cmpq %rdx, %rax
jne 0x56dd
leal 0x1(%r15), %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x2180
testl %r15d, %r15d
jle 0x5775
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movq %rax, %r13
movq %rax, %rdi
movq %r12, %rsi
movq %r15, %rdx
callq 0x21e0
jmp 0x577d
movq %rdi, %r13
movq -0xe8(%rbp), %rax
movq -0xc8(%rbp), %rdi
testq %rax, %rax
leaq 0x3f26(%rip), %r8       # 0x966a
je 0x5767
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x2, %rdx
je 0x5767
movb (%rcx,%rdx), %sil
cmpb (%rdx,%r8), %sil
jne 0x5788
incq %rdx
cmpq %rdx, %rax
jne 0x574f
callq 0x2280
movl %eax, %ebx
jmp 0x5788
movq %rdi, %r13
jmp 0x5788
movq %rax, %r13
jmp 0x577d
movq %rdi, %r13
leaq -0x68(%rbp), %r12
leaq -0xf0(%rbp), %r15
movq %r12, %rdi
movq %r15, %rsi
leaq -0x90(%rbp), %rdx
callq 0x4c59
movups -0x68(%rbp), %xmm0
movups -0x58(%rbp), %xmm1
movaps %xmm1, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
movq %r13, %rdi
je 0x5699
cmpl $0xcafebeef, %ebx       # imm = 0xCAFEBEEF
movl %ebx, -0xa0(%rbp)
je 0x58a2
movq -0x48(%rbp), %rax
leal 0x1(%rax), %ebx
movq -0x30(%rbp), %r12
movl %ebx, 0x10(%r12)
leaq (,%rbx,4), %rsi
movq -0x38(%rbp), %rdi
callq 0x2240
movq %rax, %r15
movq %rax, (%r12)
leaq (,%rbx,8), %rsi
movq -0x40(%rbp), %rdi
callq 0x2240
movq %rax, 0x8(%r12)
leaq -0x68(%rbp), %r12
movl -0x48(%rbp), %edx
movq %r15, -0x38(%rbp)
movl -0xa0(%rbp), %ecx
movl %ecx, (%r15,%rdx,4)
movq %rax, -0x40(%rbp)
movq %r13, (%rax,%rdx,8)
movq %r12, %rdi
leaq -0x138(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x4816
movups -0x68(%rbp), %xmm0
movups -0x58(%rbp), %xmm1
movaps %xmm1, -0x100(%rbp)
movaps %xmm0, -0x110(%rbp)
cmpq $0x0, -0x100(%rbp)
movl %ebx, %eax
leaq -0xf0(%rbp), %r15
jne 0x5634
movq -0x30(%rbp), %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3d7e(%rip), %rdi      # 0x9608
leaq 0x3d98(%rip), %rsi      # 0x9629
leaq 0x3da4(%rip), %rcx      # 0x963c
movl $0x33, %edx
callq 0x2130
leaq 0x3dc4(%rip), %rdi      # 0x966d
leaq 0x3d79(%rip), %rsi      # 0x9629
leaq 0x3d85(%rip), %rcx      # 0x963c
movl $0x43, %edx
callq 0x2130