// File: /workspace/github_c_makefile_star2_O1/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 $0xf8, %rsp
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 -0xa0(%rbp), %rbx
movaps %xmm0, 0x10(%rbx)
movaps %xmm0, (%rbx)
callq 0x4254
movq %r14, 0x10(%rbx)
movq %r15, 0x18(%rbx)
leaq -0xf0(%rbp), %r14
leaq -0x118(%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 0x5890
leaq -0x50(%rbp), %r13
leaq 0x3fe3(%rip), %r15      # 0x966a
movups -0x118(%rbp), %xmm0
movaps %xmm0, -0x80(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x50(%rbp)
movaps %xmm0, -0x40(%rbp)
callq 0x4254
movaps -0x80(%rbp), %xmm0
movaps %xmm0, -0x40(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
movq %r13, %rdx
callq 0x4c99
movups -0x70(%rbp), %xmm0
movups -0x60(%rbp), %xmm1
movaps %xmm1, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0x56e0
movl $0xcafebeef, %r14d      # imm = 0xCAFEBEEF
xorl %ebx, %ebx
jmp 0x57f0
movl $0xcafebeef, %r14d      # imm = 0xCAFEBEEF
xorl %ebx, %ebx
cmpl $0x4, -0xd0(%rbp)
jne 0x58a6
movl -0xa8(%rbp), %eax
cmpl $0x3, %eax
je 0x5787
cmpl $0x4, %eax
jne 0x57c3
movq -0xe8(%rbp), %rax
movq -0xc8(%rbp), %r15
movq -0xc0(%rbp), %r12
testq %rax, %rax
leaq 0x3f38(%rip), %rdi      # 0x9664
je 0x574f
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x5, %rdx
je 0x574f
movb (%rcx,%rdx), %sil
cmpb (%rdx,%rdi), %sil
jne 0x577e
incq %rdx
cmpq %rdx, %rax
jne 0x5737
leal 0x1(%r12), %eax
movslq %eax, %rdi
movl $0x1, %esi
callq 0x2180
movq %rax, %rbx
testl %r12d, %r12d
jle 0x577e
andl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x21e0
leaq 0x3ee5(%rip), %r15      # 0x966a
jmp 0x57c3
movq -0xe8(%rbp), %rax
movq -0xc8(%rbp), %rdi
testq %rax, %rax
je 0x57bb
movq -0xf0(%rbp), %rcx
xorl %edx, %edx
cmpq $0x2, %rdx
je 0x57bb
movb (%rcx,%rdx), %sil
cmpb (%rdx,%r15), %sil
jne 0x57c3
incq %rdx
cmpq %rdx, %rax
jne 0x57a3
callq 0x2280
movl %eax, %r14d
leaq -0x70(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
movq %r13, %rdx
callq 0x4c99
movups -0x70(%rbp), %xmm0
movups -0x60(%rbp), %xmm1
movaps %xmm1, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
cmpl $0x0, -0x50(%rbp)
je 0x56e8
movq %rbx, -0x80(%rbp)
cmpl $0xcafebeef, %r14d      # imm = 0xCAFEBEEF
je 0x58c5
movl %r14d, %r13d
movq -0x30(%rbp), %r14
movl 0x10(%r14), %ebx
leal 0x1(%rbx), %r15d
movl %r15d, 0x10(%r14)
movq (%r14), %rdi
leaq (,%r15,4), %rsi
callq 0x2240
movq %rax, %r12
movq %rax, (%r14)
movq 0x8(%r14), %rdi
shlq $0x3, %r15
movq %r15, %rsi
callq 0x2240
movq %rax, 0x8(%r14)
movl %r13d, (%r12,%rbx,4)
movq -0x80(%rbp), %rcx
movq %rcx, (%rax,%rbx,8)
leaq -0x70(%rbp), %rdi
leaq -0x118(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x4833
movups -0x70(%rbp), %xmm0
movups -0x60(%rbp), %xmm1
movaps %xmm1, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
cmpq $0x0, -0x90(%rbp)
leaq -0x50(%rbp), %r13
leaq 0x3de0(%rip), %r15      # 0x966a
jne 0x5687
movq -0x30(%rbp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3d5b(%rip), %rdi      # 0x9608
leaq 0x3d75(%rip), %rsi      # 0x9629
leaq 0x3d81(%rip), %rcx      # 0x963c
movl $0x33, %edx
callq 0x2130
leaq 0x3da1(%rip), %rdi      # 0x966d
leaq 0x3d56(%rip), %rsi      # 0x9629
leaq 0x3d62(%rip), %rcx      # 0x963c
movl $0x43, %edx
callq 0x2130