// File: /workspace/github_c_makefile_star2_O3/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 0x3479
movq %rbx, %rdi
callq 0x10e0
xorl %r14d, %r14d
testb %al, %al
je 0x3702
movl %eax, %esi
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpl $0xffff, %ebp           # imm = 0xFFFF
je 0x3717
shll $0x18, %esi
cmpl $0xff000000, %esi       # imm = 0xFF000000
je 0x3727
cmpl $0x7b000000, %esi       # imm = 0x7B000000
sete %cl
orb %r13b, %cl
testb $0x1, %cl
je 0x3739
cmpl $0x7affffff, %esi       # imm = 0x7AFFFFFF
jg 0x3691
cmpl $0x22000000, %esi       # imm = 0x22000000
je 0x36be
cmpl $0x5c000000, %esi       # imm = 0x5C000000
jne 0x36c2
movq %r12, 0x8(%rsp)
movslq %ebp, %r12
movb %al, 0x10(%rsp,%r12)
movq %rbx, %rdi
callq 0x10e0
leaq 0x2(%r12), %r15
movb %al, 0x11(%rsp,%r12)
cmpb $0x75, %al
jne 0x368a
movb %al, 0x10(%rsp,%r15)
movq %rbx, %rdi
callq 0x10e0
leaq 0x10(%rsp), %r15
movb %al, 0x3(%r12,%r15)
movq %rbx, %rdi
callq 0x10e0
addl $0x5, %ebp
movb %al, 0x4(%r12,%r15)
movq %rbx, %rdi
callq 0x10e0
movl %ebp, %r15d
movq 0x8(%rsp), %r12
jmp 0x36ea
cmpl $0x7b000000, %esi       # imm = 0x7B000000
je 0x36cd
cmpl $0x7d000000, %esi       # imm = 0x7D000000
jne 0x36c2
movl %r12d, %ecx
notb %cl
andb $0x1, %cl
movzbl %cl, %ecx
leal 0x1(%rbp), %r15d
movslq %ebp, %rdx
movb %al, 0x10(%rsp,%rdx)
subl %ecx, %r14d
jne 0x36ea
jmp 0x36ff
xorb $0x1, %r12b
movslq %ebp, %rcx
incl %ebp
movb %al, 0x10(%rsp,%rcx)
jmp 0x36e7
movl %r12d, %ecx
notb %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %r14d
movslq %ebp, %rcx
incl %ebp
movb %al, 0x10(%rsp,%rcx)
movb $0x1, %r13b
movl %ebp, %r15d
movq %rbx, %rdi
callq 0x10e0
movl %eax, %esi
movl %r15d, %ebp
testb %al, %al
jne 0x35e5
movslq %r15d, %r14
movb $0x0, 0x10(%rsp,%r14)
leaq 0x10(%rsp), %rdi
callq 0x523a
movq %rax, %rbx
jmp 0x374c
leaq 0x384d(%rip), %rdi      # 0x6f6b
xorl %ebx, %ebx
movl $0xffff, %esi           # imm = 0xFFFF
jmp 0x3745
leaq 0x386e(%rip), %rdi      # 0x6f9c
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x5138
jmp 0x374c
sarl $0x18, %esi
leaq 0x387d(%rip), %rdi      # 0x6fc0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x5138
movq %rbx, %rax
addq $0x10018, %rsp          # imm = 0x10018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq