// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
callq 0x2180
movq %rax, -0x38(%rbp)
movslq %ebx, %rbx
xorps %xmm0, %xmm0
leaq -0xc0(%rbp), %r12
movaps %xmm0, (%r12)
callq 0x40cc
movq %r14, 0x10(%r12)
movq %rbx, 0x18(%r12)
leaq -0x110(%rbp), %r15
leaq -0x138(%rbp), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x465c
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movaps %xmm1, 0x10(%r12)
movaps %xmm0, (%r12)
movq $0x0, -0x48(%rbp)
leaq 0x32d8(%rip), %rbx      # 0x8622
leaq 0x32cb(%rip), %r14      # 0x861c
movq $0x0, -0x40(%rbp)
movq $0x0, -0x30(%rbp)
cmpq $0x0, -0xb0(%rbp)
je 0x550e
movups -0x138(%rbp), %xmm0
movaps %xmm0, -0x60(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
callq 0x40cc
movaps -0x60(%rbp), %xmm0
movaps %xmm0, -0x70(%rbp)
leaq -0xa0(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
leaq -0x80(%rbp), %rdx
callq 0x4a68
movups -0xa0(%rbp), %xmm0
movups -0x90(%rbp), %xmm1
movaps %xmm1, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movl $0xcafebeef, %r12d      # imm = 0xCAFEBEEF
movq $0x0, -0x60(%rbp)
cmpl $0x0, -0x80(%rbp)
jne 0x545e
cmpl $0x4, -0xf0(%rbp)
jne 0x5524
movl -0xc8(%rbp), %eax
cmpl $0x3, %eax
je 0x5416
cmpl $0x4, %eax
jne 0x5434
movq %r15, %rdi
movq %r14, %rsi
callq 0x45e9
testl %eax, %eax
jne 0x5434
movl -0xe0(%rbp), %esi
movq -0xe8(%rbp), %rdi
callq 0x555a
movq %rax, -0x60(%rbp)
jmp 0x5434
movq %r15, %rdi
movq %rbx, %rsi
callq 0x45e9
testl %eax, %eax
jne 0x5434
movq -0xe8(%rbp), %rdi
callq 0x2280
movl %eax, %r12d
movq %r13, %rdi
movq %r15, %rsi
leaq -0x80(%rbp), %rdx
callq 0x4a68
movups -0xa0(%rbp), %xmm0
movups -0x90(%rbp), %xmm1
movaps %xmm1, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
jmp 0x53c8
cmpl $0xcafebeef, %r12d      # imm = 0xCAFEBEEF
je 0x5541
movq -0x30(%rbp), %rax
leal 0x1(%rax), %r13d
movq -0x38(%rbp), %rbx
movl %r13d, 0x10(%rbx)
leaq (,%r13,4), %rsi
movq -0x40(%rbp), %rdi
callq 0x2240
movq %rax, %r14
movq %rax, (%rbx)
leaq (,%r13,8), %rsi
movq -0x48(%rbp), %rdi
callq 0x2240
movq %rax, 0x8(%rbx)
movl -0x30(%rbp), %edx
movq %r14, -0x40(%rbp)
movl %r12d, (%r14,%rdx,4)
movq %rax, -0x48(%rbp)
movq -0x60(%rbp), %rcx
movq %rcx, (%rax,%rdx,8)
leaq -0xa0(%rbp), %rdi
leaq -0x138(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
callq 0x465c
movups -0xa0(%rbp), %xmm0
movups -0x90(%rbp), %xmm1
movaps %xmm1, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movl %r13d, %eax
movq %rax, -0x30(%rbp)
leaq 0x3120(%rip), %rbx      # 0x8622
leaq 0x3113(%rip), %r14      # 0x861c
jmp 0x5361
movq -0x38(%rbp), %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3095(%rip), %rdi      # 0x85c0
leaq 0x30af(%rip), %rsi      # 0x85e1
leaq 0x30bb(%rip), %rcx      # 0x85f4
pushq $0x33
popq %rdx
callq 0x2130
leaq 0x30dd(%rip), %rdi      # 0x8625
leaq 0x3092(%rip), %rsi      # 0x85e1
leaq 0x309e(%rip), %rcx      # 0x85f4
pushq $0x43
jmp 0x553b