// File: night-shift[P]Srl/src/lib/PJson.cpp
// Function: Srl::PJson::read(Srl::Lib::In&)
pair<Lib::MemBlock, Value> PJson::read(In& source)
{
    State state;
    while(!state.complete) {

        /* literals can be 'un-quoted', values in 'square-brackets' don't have a name */
        if(!state.reading_value && this->scope_type != Type::Array) {

            source.move_until(error, '\"', ':', '{', '[', '}', ']', '/');

        } else {
            source.move_while(error, ' ', ',', '\n', '\t', '\r');
        }

        bool move = true;
        char c = *source.pointer();
        switch(c) {
            case '\"': this->process_quote(source, state);
                       break;

            case ':' : if(state.reading_value) {
                           this->throw_exception(state, "Redundant colon.");
                        }
                        state.reading_value = true;
                        break;
            case '{' :
            case '}' :
            case '[' :
            case ']' : this->process_bracket(c, state);
                       break;
            case '/' : skip_comment(source);
                       break;

            default  : this->process_char(source, state, move);
        }

        if(move) {
            source.move(1, error);
        }
    }

    return { state.name, state.value };
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x78(%rbp)
movq %rdi, -0x70(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x36030
movb -0x18(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x4ef6a
jmp 0x4f101
testb $0x1, -0x16(%rbp)
jne 0x4efd2
movq -0x68(%rbp), %rax
cmpb $0xf, 0x60(%rax)
je 0x4efd2
movq -0x10(%rbp), %rdi
movb $0x22, -0x41(%rbp)
movb $0x3a, -0x42(%rbp)
movb $0x7b, -0x43(%rbp)
movb $0x5b, -0x44(%rbp)
movb $0x7d, -0x45(%rbp)
movb $0x5d, -0x46(%rbp)
movb $0x2f, -0x47(%rbp)
leaq 0x37d5f(%rip), %rsi     # 0x86d00
leaq -0x41(%rbp), %rdx
leaq -0x42(%rbp), %rcx
leaq -0x43(%rbp), %r8
leaq -0x44(%rbp), %r9
leaq -0x45(%rbp), %r11
leaq -0x46(%rbp), %r10
leaq -0x47(%rbp), %rax
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x35cf0
jmp 0x4f00e
movq -0x10(%rbp), %rdi
movb $0x20, -0x48(%rbp)
movb $0x2c, -0x49(%rbp)
movb $0xa, -0x4a(%rbp)
movb $0x9, -0x4b(%rbp)
movb $0xd, -0x4c(%rbp)
leaq 0x37d0f(%rip), %rsi     # 0x86d00
leaq -0x48(%rbp), %rdx
leaq -0x49(%rbp), %rcx
leaq -0x4a(%rbp), %r8
leaq -0x4b(%rbp), %r9
leaq -0x4c(%rbp), %rax
movq %rax, (%rsp)
callq 0x38a40
movb $0x1, -0x4d(%rbp)
movq -0x10(%rbp), %rdi
callq 0x34240
movb (%rax), %al
movb %al, -0x4e(%rbp)
movsbl -0x4e(%rbp), %eax
movl %eax, -0x7c(%rbp)
subl $0x22, %eax
je 0x4f06e
jmp 0x4f02e
movl -0x7c(%rbp), %eax
subl $0x2f, %eax
je 0x4f0c1
jmp 0x4f03c
movl -0x7c(%rbp), %eax
subl $0x3a, %eax
je 0x4f081
jmp 0x4f046
movl -0x7c(%rbp), %eax
subl $0x5b, %eax
je 0x4f0ae
jmp 0x4f050
movl -0x7c(%rbp), %eax
subl $0x5d, %eax
je 0x4f0ae
jmp 0x4f05a
movl -0x7c(%rbp), %eax
subl $0x7b, %eax
je 0x4f0ae
jmp 0x4f064
movl -0x7c(%rbp), %eax
subl $0x7d, %eax
je 0x4f0ae
jmp 0x4f0cc
movq -0x68(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0x37bd0
jmp 0x4f0e1
testb $0x1, -0x16(%rbp)
je 0x4f0a8
leaq -0x60(%rbp), %rdi
leaq 0x1a835(%rip), %rsi     # 0x698c7
callq 0x34040
movq -0x68(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x33320
movb $0x1, -0x16(%rbp)
jmp 0x4f0e1
movq -0x68(%rbp), %rdi
leaq -0x40(%rbp), %rdx
movsbl -0x4e(%rbp), %esi
callq 0x33690
jmp 0x4f0e1
movq -0x10(%rbp), %rdi
callq 0x4f880
jmp 0x4f0e1
movq -0x68(%rbp), %rdi
movq -0x10(%rbp), %rsi
leaq -0x40(%rbp), %rdx
leaq -0x4d(%rbp), %rcx
callq 0x34050
testb $0x1, -0x4d(%rbp)
je 0x4f0fc
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq 0x37c09(%rip), %rdx     # 0x86d00
callq 0x384f0
jmp 0x4ef5c
movq -0x78(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x40(%rbp), %rdx
addq $0x10, %rdx
callq 0x35e20
movq -0x70(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)