// File: /workspace/github_c_makefile_star2_O1/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 0x3432
movq %rbx, %rdi
callq 0x10e0
xorl %r14d, %r14d
testb %al, %al
je 0x36bb
movl %eax, %esi
xorl %r13d, %r13d
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpl $0xffff, %ebp           # imm = 0xFFFF
je 0x36d0
shll $0x18, %esi
cmpl $0xff000000, %esi       # imm = 0xFF000000
je 0x36e0
cmpl $0x7b000000, %esi       # imm = 0x7B000000
sete %cl
orb %r13b, %cl
testb $0x1, %cl
je 0x36f2
cmpl $0x7affffff, %esi       # imm = 0x7AFFFFFF
jg 0x364a
cmpl $0x22000000, %esi       # imm = 0x22000000
je 0x3677
cmpl $0x5c000000, %esi       # imm = 0x5C000000
jne 0x367b
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 0x3643
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 0x36a3
cmpl $0x7b000000, %esi       # imm = 0x7B000000
je 0x3686
cmpl $0x7d000000, %esi       # imm = 0x7D000000
jne 0x367b
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 0x36a3
jmp 0x36b8
xorb $0x1, %r12b
movslq %ebp, %rcx
incl %ebp
movb %al, 0x10(%rsp,%rcx)
jmp 0x36a0
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 0x359e
movslq %r15d, %r14
movb $0x0, 0x10(%rsp,%r14)
leaq 0x10(%rsp), %rdi
callq 0x4c54
movq %rax, %rbx
jmp 0x3705
leaq 0x2894(%rip), %rdi      # 0x5f6b
xorl %ebx, %ebx
movl $0xffff, %esi           # imm = 0xFFFF
jmp 0x36fe
leaq 0x28b5(%rip), %rdi      # 0x5f9c
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4b44
jmp 0x3705
sarl $0x18, %esi
leaq 0x28c4(%rip), %rdi      # 0x5fc0
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4b44
movq %rbx, %rax
addq $0x10018, %rsp          # imm = 0x10018
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq