// File: /workspace/github_cpp_makefile_star2_O1/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, 0xa0(%rsp)
movq %rdi, 0x8(%rsp)
movb (%rdi), %r14b
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x411a
movl $0x0, %ebp
testb %r14b, %r14b
je 0x3ddc
movq 0x8(%rsp), %rax
incq %rax
movq %rax, 0xa8(%rsp)
movabsq $0x100000000, %r15      # imm = 0x100000000
xorl %ebp, %ebp
xorl %r13d, %r13d
movslq %ebx, %r12
leal 0x1(%r12), %ebx
movq 0xa8(%rsp), %rax
addq %r12, %rax
shlq $0x20, %r12
cmpb $0x20, %r14b
jne 0x39ac
movb (%rax), %r14b
incl %ebx
addq %r15, %r12
incq %rax
jmp 0x3999
movzbl %r14b, %eax
cmpl $0x39, %eax
jle 0x3a58
cmpl $0x3a, %eax
je 0x3a77
cmpl $0x7b, %eax
je 0x3a99
cmpl $0x7d, %eax
jne 0x3acb
testq %rbp, %rbp
je 0x3a02
movq 0x40(%rsp), %rax
cmpq 0x48(%rsp), %rax
jne 0x39f6
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x8(%rax), %rdi
movq %rbp, %rsi
callq 0x3f20
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rdi
movq %rax, %rcx
cmpq %rdi, %rax
jne 0x3a42
movq 0x58(%rsp), %rcx
movq -0x8(%rcx), %rcx
movl $0x200, %edx            # imm = 0x200
addq %rdx, %rcx
movq -0x8(%rcx), %r12
cmpq %rdi, %rax
je 0x3c74
addq $-0x8, %rax
jmp 0x3ca2
cmpl $0x22, %eax
je 0x3ab3
cmpl $0x2c, %eax
jne 0x3acb
cmpl $0x2, %r13d
je 0x3c26
jae 0x3dc7
jmp 0x3e69
cmpl $0x1, %r13d
je 0x3c1b
testl %r13d, %r13d
je 0x3e4a
cmpl $0x2, %r13d
jne 0x3dc7
jmp 0x3e4a
testl %r13d, %r13d
je 0x3aed
cmpl $0x2, %r13d
je 0x3aed
cmpl $0x1, %r13d
jne 0x3dc7
jmp 0x3ea7
cmpl $0x2, %r13d
je 0x3b95
testl %r13d, %r13d
jne 0x3dc7
jmp 0x3e88
cmpl $0x1, %r13d
je 0x3d81
cmpl $0x2, %r13d
je 0x3ceb
testl %r13d, %r13d
jne 0x3dc7
jmp 0x3ec6
movl $0x68, %edi
callq 0x2220
movq %rax, %r12
leaq 0x423f(%rip), %rax      # 0x7d40
movq %rax, (%r12)
movq %r12, %r13
addq $0x8, %r13
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r12)
movups %xmm0, 0x18(%r12)
movups %xmm0, 0x28(%r12)
movups %xmm0, 0x38(%r12)
leaq 0x60(%rsp), %r14
movq %r14, %rdi
callq 0x20e0
movq %r13, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2190
movl $0x2, 0x48(%r12)
leaq 0x41a6(%rip), %rax      # 0x7cf8
movq %rax, (%r12)
xorps %xmm0, %xmm0
movups %xmm0, 0x50(%r12)
movq $0x0, 0x60(%r12)
movq %r12, 0xb0(%rsp)
movq 0x40(%rsp), %rax
movq 0x50(%rsp), %rcx
addq $-0x8, %rcx
cmpq %rcx, %rax
je 0x3d92
movq %r12, (%rax)
addq $0x8, 0x40(%rsp)
jmp 0x3da4
movl $0x2, %r13d
testq %rbp, %rbp
jne 0x3dc7
movl $0x90, %edi
callq 0x2220
movq %rax, %rbp
leaq 0x4188(%rip), %rax      # 0x7d40
movq %rax, (%rbp)
movq %rbp, %r12
addq $0x8, %r12
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbp)
movups %xmm0, 0x18(%rbp)
movups %xmm0, 0x28(%rbp)
movups %xmm0, 0x38(%rbp)
leaq 0x60(%rsp), %r14
movq %r14, %rdi
callq 0x20e0
movq %r12, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x2190
movl $0x1, 0x48(%rbp)
leaq 0x4161(%rip), %rax      # 0x7d60
movq %rax, (%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x4c(%rbp)
movups %xmm0, 0x5c(%rbp)
movups %xmm0, 0x6c(%rbp)
movups %xmm0, 0x7c(%rbp)
jmp 0x3dc7
movl $0x2, %r13d
jmp 0x3dc7
movq 0x40(%rsp), %rax
cmpq 0x48(%rsp), %rax
jne 0x3c43
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x8(%rax), %rdi
movq %rbp, %rsi
callq 0x3f20
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movl $0x1, %r13d
jmp 0x3ce4
callq 0x21e0
movq 0x58(%rsp), %rax
leaq -0x8(%rax), %rcx
movq %rcx, 0x58(%rsp)
movq -0x8(%rax), %rax
movq %rax, 0x48(%rsp)
leaq 0x200(%rax), %rcx
movq %rcx, 0x50(%rsp)
addq $0x1f8, %rax            # imm = 0x1F8
movq %rax, 0x40(%rsp)
cmpq 0x20(%rsp), %rax
je 0x3cd4
cmpq 0x48(%rsp), %rax
jne 0x3cc6
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rax
movl $0x200, %ecx            # imm = 0x200
addq %rcx, %rax
movq -0x8(%rax), %rdi
movq %r12, %rsi
callq 0x3f20
jmp 0x3ce4
movq 0xa0(%rsp), %rdi
movq %r12, %rsi
callq 0x36a8
xorl %ebp, %ebp
jmp 0x3dc7
testq %rbp, %rbp
jne 0x3d65
movl $0x58, %edi
callq 0x2220
movq %rax, %rbp
leaq 0x403c(%rip), %rax      # 0x7d40
movq %rax, (%rbp)
movq %rbp, %r13
addq $0x8, %r13
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rbp)
movups %xmm0, 0x18(%rbp)
movups %xmm0, 0x28(%rbp)
movups %xmm0, 0x38(%rbp)
leaq 0x60(%rsp), %rdi
callq 0x20e0
movq %r13, %rdi
leaq 0x60(%rsp), %rsi
movq %rax, %rdx
callq 0x2190
movl $0x0, 0x48(%rbp)
leaq 0x404e(%rip), %rax      # 0x7d98
movq %rax, (%rbp)
sarq $0x20, %r12
addq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x2310
cltq
movq %rax, 0x50(%rbp)
movl $0x2, %r13d
cmpl $0x1, 0x48(%rbp)
jne 0x3dc7
leaq 0x4c(%rbp), %rdi
callq 0x20e0
movb %r14b, 0x4c(%rbp,%rax)
jmp 0x3dc7
leaq 0x60(%rsp), %rdi
callq 0x20e0
movb %r14b, 0x60(%rsp,%rax)
jmp 0x3dc1
leaq 0x10(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x4282
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x90(%rsp)
movl $0x1, %r13d
movslq %ebx, %rax
movq 0x8(%rsp), %rcx
movb (%rcx,%rax), %r14b
testb %r14b, %r14b
jne 0x3982
testq %rbp, %rbp
je 0x3de9
movq %rbp, %rdi
callq 0x21e0
movq 0x58(%rsp), %rax
movq %rax, %rcx
subq 0x38(%rsp), %rcx
shrq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
shlq $0x6, %rcx
movq 0x30(%rsp), %rax
movq 0x40(%rsp), %rdx
subq 0x48(%rsp), %rdx
sarq $0x3, %rdx
addq %rcx, %rdx
subq 0x20(%rsp), %rax
sarq $0x3, %rax
addq %rdx, %rax
jne 0x3ee5
leaq 0x10(%rsp), %rdi
callq 0x40d6
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16c2(%rip), %rdi      # 0x5513
leaq 0x15d0(%rip), %rsi      # 0x5428
leaq 0x167a(%rip), %rcx      # 0x54d9
movl $0xbd, %edx
callq 0x2120
leaq 0x16a3(%rip), %rdi      # 0x5513
leaq 0x15b1(%rip), %rsi      # 0x5428
leaq 0x165b(%rip), %rcx      # 0x54d9
movl $0xcc, %edx
callq 0x2120
leaq 0x1684(%rip), %rdi      # 0x5513
leaq 0x1592(%rip), %rsi      # 0x5428
leaq 0x163c(%rip), %rcx      # 0x54d9
movl $0xdc, %edx
callq 0x2120
leaq 0x1665(%rip), %rdi      # 0x5513
leaq 0x1573(%rip), %rsi      # 0x5428
leaq 0x161d(%rip), %rcx      # 0x54d9
movl $0x9c, %edx
callq 0x2120
leaq 0x1646(%rip), %rdi      # 0x5513
leaq 0x1554(%rip), %rsi      # 0x5428
leaq 0x15fe(%rip), %rcx      # 0x54d9
movl $0xf8, %edx
callq 0x2120
leaq 0x1610(%rip), %rdi      # 0x54fc
leaq 0x1535(%rip), %rsi      # 0x5428
leaq 0x15df(%rip), %rcx      # 0x54d9
movl $0xff, %edx
callq 0x2120
jmp 0x3f0a
jmp 0x3f0a
jmp 0x3f0a
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x40d6
movq %rbx, %rdi
callq 0x2360
nop