// File: /workspace/github_c_makefile_star2_O2/pipde[P]deos-songlib/utils/processtab/tabparser.c
// Function: parseJSON
char *
parseJSON(FILE *in)
    {
    /* This is not a full JSON parser, but instead a simple brace-matcher.
       Its only intended use is to consume input through the end brace of a JSON string.
     */
    
    char ch;
    char buffer[JSON_LENGTH_MAX];
    int index = 0;
    int braceLevel = 0;
    bool inQuotes = false;
    bool jsonStarted = false;
    
    skipWhiteSpace(in);
    
    while ((ch = fgetc(in)))
        {
        if (index == JSON_LENGTH_MAX - 1)
            {
            Fatal("JSON string cannot be longer than %i characters\n", JSON_LENGTH_MAX - 1);
            return 0;
            }
        if (ch == EOF)
            {
            Fatal("unexpected EOF reading JSON string\n");
            return 0;
            }
        if (!jsonStarted && ch != '{')
            {
            Fatal("expected '{', found '%c' in JSON string\n", ch);
            return 0;
            }
        if (ch == '\\') 
            {
            // consume backslash and the next character
            buffer[index++] = ch;
            ch = fgetc(in);
            buffer[index++] = ch;
            if (ch == 'u') // consume 3 extra characters for unicode '\u####'
                {
                buffer[index++] = ch;
                ch = fgetc(in);
                buffer[index++] = ch;
                ch = fgetc(in);
                buffer[index++] = ch;
                ch = fgetc(in);
                }
            }
        else if (ch == '\"')
            {
            inQuotes = !inQuotes;
            buffer[index++] = ch;
            }   
        else if (ch == '{')
            {
            jsonStarted = true;
            if (!inQuotes) braceLevel++;
            buffer[index++] = ch;
            }
        else if (ch == '}')
            {
            if (!inQuotes) braceLevel--;
            buffer[index++] = ch;
            if (braceLevel == 0) break;
            }
        else
            {
            buffer[index++] = ch;
            }
        }
        buffer[index] = '\0';
        return StringDup(buffer);
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10018, %rsp          # imm = 0x10018
movq %rdi, %rbx
callq 0x30af
xorl %ecx, %ecx
leaq 0x10(%rsp), %r14
xorl %edx, %edx
xorl %r15d, %r15d
xorl %r12d, %r12d
movl %edx, 0xc(%rsp)
movl %ecx, %r13d
movq %rbx, %rdi
callq 0x10e0
testb %al, %al
je 0x32fe
cmpl $0xffff, %r13d          # imm = 0xFFFF
je 0x3315
movl %eax, %esi
shll $0x18, %esi
cmpl $0xff000000, %esi       # imm = 0xFF000000
je 0x3325
cmpl $0x7b000000, %esi       # imm = 0x7B000000
sete %cl
orb %r12b, %cl
testb $0x1, %cl
je 0x3337
movslq %r13d, %rbp
cmpl $0x5c000000, %esi       # imm = 0x5C000000
je 0x326e
cmpl $0x22000000, %esi       # imm = 0x22000000
je 0x32bc
movl %r15d, %ecx
notb %cl
cmpl $0x7b000000, %esi       # imm = 0x7B000000
je 0x32c2
cmpl $0x7d000000, %esi       # imm = 0x7D000000
je 0x32e0
incl %r13d
movb %al, 0x10(%rsp,%rbp)
movl %r13d, %ecx
jmp 0x31f4
movb %al, 0x10(%rsp,%rbp)
movq %rbx, %rdi
callq 0x10e0
leaq 0x2(%rbp), %rcx
movb %al, 0x11(%rsp,%rbp)
cmpb $0x75, %al
jne 0x31f4
movb %al, 0x10(%rsp,%rcx)
movq %rbx, %rdi
callq 0x10e0
movb %al, 0x3(%rbp,%r14)
movq %rbx, %rdi
callq 0x10e0
addl $0x5, %r13d
movb %al, 0x4(%rbp,%r14)
movq %rbx, %rdi
callq 0x10e0
movl %r13d, %ecx
jmp 0x31f4
xorb $0x1, %r15b
jmp 0x3262
andb $0x1, %cl
movzbl %cl, %ecx
movl 0xc(%rsp), %edx
addl %ecx, %edx
incl %r13d
movb %al, 0x10(%rsp,%rbp)
movb $0x1, %r12b
movl %r13d, %ecx
jmp 0x31f0
andb $0x1, %cl
movzbl %cl, %edx
incl %r13d
movb %al, 0x10(%rsp,%rbp)
movl %r13d, %ecx
movl 0xc(%rsp), %eax
subl %edx, %eax
movl %eax, %edx
jne 0x31f0
movslq %r13d, %rax
movb $0x0, 0x10(%rsp,%rax)
leaq 0x10(%rsp), %rdi
callq 0x47a8
movq %rax, %rbx
jmp 0x334a
leaq 0x2c4f(%rip), %rdi      # 0x5f6b
xorl %ebx, %ebx
movl $0xffff, %esi           # imm = 0xFFFF
jmp 0x3343
leaq 0x2c70(%rip), %rdi      # 0x5f9c
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4610
jmp 0x334a
sarl $0x18, %esi
leaq 0x2c7f(%rip), %rdi      # 0x5fc0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4610
movq %rbx, %rax
addq $0x10018, %rsp          # imm = 0x10018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq