// File: /workspace/github_cpp_makefile_star2_O2/blakewford[P]kab/parser.cpp
// Function: parse(char const*, target*)
void parse(const char* json, target* t)
{
    int i = 0;
    object* temp = nullptr;
    char current = json[i];
    parse_state state = UNKNOWN;
    char attribute[MAX_BUFFER_SIZE];
    std::stack<container_object*> object_stack;
    while(current != '\0')
    {
        while(current == ' ')
        {
            i++;
            current = json[i];
        }
        if(current == '{')
        {
            switch(state)
            {
                case UNKNOWN:
                case VALUE:
                    object_stack.push(new container_object(attribute));
                    memset(attribute, '\0', MAX_BUFFER_SIZE);
                    state = ATTRIBUTE_NAME;
                    break;
                case ATTRIBUTE_NAME:
                    assert(0);
                    break;
            }
        }
        else if(current == '}')
        {
            if(temp != nullptr)
            {
                object_stack.top()->add(temp);
            }
            memset(attribute, '\0', MAX_BUFFER_SIZE);
            temp = nullptr;
            container_object* obj = object_stack.top();
            object_stack.pop();
            if(!object_stack.empty())
            {
                object_stack.top()->add(obj);
            }
            else
            {
                //Top level Weave object
                t->populate(obj);
            }
        }
        else if(current == ':')
        {
            switch(state)
            {
                case ATTRIBUTE_NAME:
                    state = VALUE;
                    break;
                case UNKNOWN:
                case VALUE:
                    assert(0);
            }
        }
        else if(current == ',')
        {
            switch(state)
            {
                case VALUE:
                    object_stack.top()->add(temp);
                    memset(attribute, '\0', MAX_BUFFER_SIZE);
                    temp = nullptr;
                    state = ATTRIBUTE_NAME;
                    break;
                case UNKNOWN:
                case ATTRIBUTE_NAME:
                    assert(0);
            }
        }
        else if(current == '"')
        {
            switch(state)
            {
                case ATTRIBUTE_NAME:
                    break;
                case VALUE:
                    if(temp == nullptr)
                    {
                        temp = new string_object(attribute);
                    }
                    break;
                case UNKNOWN:
                    assert(0);
            }
        }
        else
        {
            switch(state)
            {
                case ATTRIBUTE_NAME:
                    attribute[strlen(attribute)] = current;
                    break;
                case VALUE:
                    if(temp == nullptr)
                    {
                        long_object* obj = new long_object(attribute);
                        obj->set_value(atoi(json+i)); //HACK ALERT
                        temp = obj;
                    }
                    switch(temp->get_type())
                    {
                        case STRING:
                            ((string_object*)temp)->add(current);
                            break;
                        case LONG:
                        case CONTAINER:
                            break;
                    }
                    break;
                case UNKNOWN:
                    assert(0);
            }
        }
        current = json[++i];
    }

    if(temp != nullptr) delete temp;
    assert(object_stack.size() == 0);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, 0x50(%rsp)
movq %rdi, %rbx
movb (%rdi), %r14b
leaq 0x68(%rsp), %rdi
callq 0x39e4
movq %rbx, 0x8(%rsp)
leaq 0x1(%rbx), %rax
movq %rax, 0x58(%rsp)
xorl %ebx, %ebx
movabsq $0x100000000, %r12      # imm = 0x100000000
xorl %r13d, %r13d
xorl %r15d, %r15d
testb %r14b, %r14b
je 0x38b3
movslq %r15d, %rbp
leal 0x1(%rbp), %r15d
movq 0x58(%rsp), %rax
addq %rbp, %rax
shlq $0x20, %rbp
cmpb $0x20, %r14b
jne 0x35fa
movb (%rax), %r14b
incl %r15d
addq %r12, %rbp
incq %rax
jmp 0x35e6
movzbl %r14b, %eax
cmpl $0x22, %eax
je 0x3739
cmpl $0x2c, %eax
je 0x36ef
cmpl $0x3a, %eax
je 0x3703
cmpl $0x7b, %eax
je 0x3722
cmpl $0x7d, %eax
jne 0x374b
testq %r13, %r13
je 0x3662
movq 0x98(%rsp), %rax
cmpq 0xa0(%rsp), %rax
jne 0x3656
movq 0xb0(%rsp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x8(%rax), %rdi
movq %r13, %rsi
callq 0x3a24
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movq 0x98(%rsp), %rax
cmpq 0xa0(%rsp), %rax
jne 0x369f
movq 0xb0(%rsp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x8(%rax), %r13
leaq 0x68(%rsp), %rdi
callq 0x4116
movq 0x98(%rsp), %rax
cmpq 0x78(%rsp), %rax
je 0x382f
cmpq 0xa0(%rsp), %rax
jne 0x36de
movq 0xb0(%rsp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x8(%rax), %rdi
movq %r13, %rsi
callq 0x3a24
jmp 0x383c
cmpl $0x2, %ebx
je 0x37df
jae 0x38a2
jmp 0x390e
cmpl $0x1, %ebx
je 0x388a
testl %ebx, %ebx
je 0x38ef
cmpl $0x2, %ebx
jne 0x38a2
jmp 0x38ef
testl %ebx, %ebx
je 0x376a
cmpl $0x2, %ebx
je 0x376a
cmpl $0x1, %ebx
jne 0x38a2
jmp 0x396b
cmpl $0x2, %ebx
je 0x37b2
testl %ebx, %ebx
jne 0x38a2
jmp 0x392d
cmpl $0x1, %ebx
je 0x388e
cmpl $0x2, %ebx
je 0x3841
testl %ebx, %ebx
jne 0x38a2
jmp 0x394c
pushq $0x68
popq %rdi
callq 0x2230
movq %rax, %rbp
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3a00
movq %rbp, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x3eee
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x40(%rsp)
jmp 0x389d
pushq $0x2
popq %rax
movl %eax, %ebx
testq %r13, %r13
jne 0x38a2
movl $0x90, %edi
callq 0x2230
movq %rax, %r13
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3a3a
jmp 0x388a
movq 0x98(%rsp), %rax
cmpq 0xa0(%rsp), %rax
jne 0x3805
movq 0xb0(%rsp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x8(%rax), %rdi
movq %r13, %rsi
callq 0x3a24
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
pushq $0x1
popq %rax
movl %eax, %ebx
jmp 0x383c
movq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x3394
xorl %r13d, %r13d
jmp 0x38a2
testq %r13, %r13
jne 0x3875
pushq $0x58
popq %rdi
callq 0x2230
movq %rax, %r13
movq %rax, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3a66
sarq $0x20, %rbp
addq 0x8(%rsp), %rbp
movq %rbp, %rdi
callq 0x2310
cltq
movq %rax, 0x50(%r13)
cmpl $0x1, 0x48(%r13)
jne 0x388a
leaq 0x4c(%r13), %rdi
callq 0x20f0
movb %r14b, 0x4c(%r13,%rax)
pushq $0x2
jmp 0x389f
leaq 0x10(%rsp), %rdi
callq 0x20f0
movb %r14b, 0x10(%rsp,%rax)
pushq $0x1
popq %rax
movl %eax, %ebx
movslq %r15d, %rax
movq 0x8(%rsp), %rcx
movb (%rcx,%rax), %r14b
jmp 0x35ca
testq %r13, %r13
je 0x38c0
movq %r13, %rdi
callq 0x2200
leaq 0x68(%rsp), %rdi
callq 0x3f8a
testq %rax, %rax
jne 0x398a
leaq 0x68(%rsp), %rdi
callq 0x3ccc
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bd6(%rip), %rdi      # 0x54cc
leaq 0x1ae7(%rip), %rsi      # 0x53e4
leaq 0x1b8e(%rip), %rcx      # 0x5492
movl $0xbd, %edx
callq 0x2150
leaq 0x1bb7(%rip), %rdi      # 0x54cc
leaq 0x1ac8(%rip), %rsi      # 0x53e4
leaq 0x1b6f(%rip), %rcx      # 0x5492
movl $0xcc, %edx
callq 0x2150
leaq 0x1b98(%rip), %rdi      # 0x54cc
leaq 0x1aa9(%rip), %rsi      # 0x53e4
leaq 0x1b50(%rip), %rcx      # 0x5492
movl $0xdc, %edx
callq 0x2150
leaq 0x1b79(%rip), %rdi      # 0x54cc
leaq 0x1a8a(%rip), %rsi      # 0x53e4
leaq 0x1b31(%rip), %rcx      # 0x5492
movl $0xf8, %edx
callq 0x2150
leaq 0x1b5a(%rip), %rdi      # 0x54cc
leaq 0x1a6b(%rip), %rsi      # 0x53e4
leaq 0x1b12(%rip), %rcx      # 0x5492
movl $0x9c, %edx
callq 0x2150
leaq 0x1b24(%rip), %rdi      # 0x54b5
leaq 0x1a4c(%rip), %rsi      # 0x53e4
leaq 0x1af3(%rip), %rcx      # 0x5492
movl $0xff, %edx
callq 0x2150
jmp 0x39bc
movq %rax, %rbx
movq %rbp, %rdi
callq 0x2200
jmp 0x39bf
jmp 0x39bc
jmp 0x39bc
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x3ccc
movq %rbx, %rdi
callq 0x2360
nop