// File: /workspace/github_c_makefile_star2_O0/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
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
jmp 0x7144
movl $0x1, %edi
movl $0x18, %esi
callq 0x2180
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rsi
movslq -0xc(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x5b40
leaq -0x80(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x5b90
movq -0x80(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x746b
movl $0xcafebeef, -0x84(%rbp) # imm = 0xCAFEBEEF
movq $0x0, -0x90(%rbp)
movq -0x60(%rbp), %rsi
movq -0x58(%rbp), %rdx
leaq -0xb0(%rbp), %rdi
callq 0x5b40
leaq -0x120(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x6200
movq -0x120(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x98(%rbp)
cmpl $0x0, -0xb0(%rbp)
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x7234
jmp 0x7369
cmpl $0x4, -0xe0(%rbp)
jne 0x723f
jmp 0x725e
leaq 0x53fa(%rip), %rdi      # 0xc640
leaq 0x5414(%rip), %rsi      # 0xc661
movl $0x33, %edx
leaq 0x541b(%rip), %rcx      # 0xc674
callq 0x2120
cmpl $0x4, -0xb8(%rbp)
jne 0x72b9
leaq -0x100(%rbp), %rsi
addq $0x28, %rsi
leaq -0x148(%rbp), %rdi
movl $0x28, %edx
callq 0x21e0
leaq -0x100(%rbp), %rdi
leaq 0x540b(%rip), %rsi      # 0xc69c
callq 0x5a90
cmpl $0x0, %eax
jne 0x72b7
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rax
movl %eax, %esi
callq 0x7480
movq %rax, -0x90(%rbp)
jmp 0x7312
cmpl $0x3, -0xb8(%rbp)
jne 0x730a
leaq -0x100(%rbp), %rsi
addq $0x28, %rsi
leaq -0x170(%rbp), %rdi
movl $0x28, %edx
callq 0x21e0
leaq -0x100(%rbp), %rdi
leaq 0x53b6(%rip), %rsi      # 0xc6a2
callq 0x5a90
cmpl $0x0, %eax
jne 0x7308
movq -0x170(%rbp), %rdi
callq 0x2270
movl %eax, -0x84(%rbp)
jmp 0x7310
jmp 0x730c
jmp 0x730e
jmp 0x7310
jmp 0x7312
leaq -0x190(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x6200
movq -0x190(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x188(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x180(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x98(%rbp)
jmp 0x721f
cmpl $0xcafebeef, -0x84(%rbp) # imm = 0xCAFEBEEF
je 0x7377
jmp 0x7396
leaq 0x5327(%rip), %rdi      # 0xc6a5
leaq 0x52dc(%rip), %rsi      # 0xc661
movl $0x43, %edx
leaq 0x52e3(%rip), %rcx      # 0xc674
callq 0x2120
movq -0x18(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %esi
shlq $0x2, %rsi
callq 0x2230
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, %esi
shlq $0x3, %rsi
callq 0x2230
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x84(%rbp), %edx
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl %edx, (%rax,%rcx,4)
movq -0x90(%rbp), %rdx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
leaq -0x1b0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
leaq -0x38(%rbp), %rdx
callq 0x5b90
movq -0x1b0(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x1a8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x1a0(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x198(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x7199
movq -0x18(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
nopl (%rax,%rax)