// File: night-shift[P]Srl/src/lib/PSrl.cpp
// Function: Srl::PSrl::read(Srl::Lib::In&)
pair<Lib::MemBlock, Value> PSrl::read(In& source)
{
    Flag flag; MemBlock name;
    tie(flag, name) = this->read_head(source);

    if(!flag) {
        if(this->scope_stack.size() < 1) {
            error();
        }
        this->pop_scope();

        return { MemBlock(), Type::Scope_End };
    }

    if(is_scope(flag)) {
        auto tp = flag & FObject ? Type::Object : Type::Array;
        this->push_scope(tp);

        return { name, tp };
    }

    if(flag & FNum) {
        return this->read_num(flag, name, source);
    }


    if(flag & (FBinary | FString)) {
        auto size  = decode_integer(source);
        auto block = source.read_block(size, error);
        auto type = flag & FBinary ? Type::Binary : Type::String;

        return { name, Value(block, type, Encoding::UTF8) };
    }

    if(flag & FNull) {
        return { name, Type::Null };
    }

    /* shouldn't end down here */
    error();
    return { name, Type::Null };
;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0xc0(%rbp)
movq %rdi, -0xb8(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x374c0
movq -0xb0(%rbp), %rsi
movq -0x10(%rbp), %rdx
leaq -0x40(%rbp), %rdi
callq 0x37720
leaq -0x50(%rbp), %rdi
leaq -0x11(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0x38260
leaq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x350a0
cmpb $0x0, -0x11(%rbp)
jne 0x5d101
movq -0xb0(%rbp), %rdi
addq $0x78, %rdi
callq 0x36180
cmpq $0x1, %rax
jae 0x5d0cf
leaq 0x2a1d6(%rip), %rdi     # 0x872a0
callq 0x35bb0
movq -0xb0(%rbp), %rdi
callq 0x38740
leaq -0x60(%rbp), %rdi
callq 0x374c0
movq -0xc0(%rbp), %rdi
movb $0x10, -0x61(%rbp)
leaq -0x60(%rbp), %rsi
leaq -0x61(%rbp), %rdx
callq 0x35a90
jmp 0x5d294
movzbl -0x11(%rbp), %edi
callq 0x5d2b0
testb $0x1, %al
jne 0x5d110
jmp 0x5d16a
movzbl -0x11(%rbp), %ecx
andl $0x40, %ecx
movb $0xe, %al
movb $0xf, %dl
movb %dl, -0xc2(%rbp)
cmpl $0x0, %ecx
movb %al, -0xc1(%rbp)
jne 0x5d138
movb -0xc2(%rbp), %al
movb %al, -0xc1(%rbp)
movq -0xb0(%rbp), %rdi
movb -0xc1(%rbp), %al
movb %al, -0x62(%rbp)
movzbl -0x62(%rbp), %esi
callq 0x383c0
movq -0xc0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x62(%rbp), %rdx
callq 0x37660
jmp 0x5d294
movzbl -0x11(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5d19c
movq -0xb0(%rbp), %rsi
movq -0xc0(%rbp), %rdi
movb -0x11(%rbp), %al
movq -0x10(%rbp), %r8
leaq -0x28(%rbp), %rcx
movzbl %al, %edx
callq 0x36780
jmp 0x5d294
movzbl -0x11(%rbp), %eax
andl $0x30, %eax
cmpl $0x0, %eax
je 0x5d23e
movq -0x10(%rbp), %rdi
callq 0x5cb60
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x70(%rbp), %rsi
leaq 0x2a0d8(%rip), %rdx     # 0x872a0
callq 0x386b0
movq %rax, -0x80(%rbp)
movq %rdx, -0x78(%rbp)
movzbl -0x11(%rbp), %ecx
andl $0x10, %ecx
movb $0xd, %al
movb $0xc, %dl
movb %dl, -0xc4(%rbp)
cmpl $0x0, %ecx
movb %al, -0xc3(%rbp)
jne 0x5d1fd
movb -0xc4(%rbp), %al
movb %al, -0xc3(%rbp)
movb -0xc3(%rbp), %al
movb %al, -0x81(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x1, %ecx
movzbl -0x81(%rbp), %edx
callq 0x38660
movq -0xc0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x35c10
jmp 0x5d294
movzbl -0x11(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x5d26a
movq -0xc0(%rbp), %rdi
movb $0xb, -0xa1(%rbp)
leaq -0x28(%rbp), %rsi
leaq -0xa1(%rbp), %rdx
callq 0x356e0
jmp 0x5d294
leaq 0x2a02f(%rip), %rdi     # 0x872a0
callq 0x35bb0
movq -0xc0(%rbp), %rdi
movb $0xb, -0xa2(%rbp)
leaq -0x28(%rbp), %rsi
leaq -0xa2(%rbp), %rdx
callq 0x356e0
movq -0xb8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)