// File: night-shift[P]Srl/src/lib/Node.cpp
// Function: Srl::Node::consume_value(bool, unsigned long)
Value Node::consume_value(bool throw_ex, size_t)
{
    if(this->values.size() > 0) {
        auto itr = this->values.begin();
        auto stored_field = move(itr->field);
        this->values.erase(itr);

        return stored_field;
    }

    while(!this->parsed) {
        MemBlock seg_name; Value val;
        tie(seg_name, val) = this->env->parser->read(this->env->in);

        auto tp = val.type();

        if(tp == Type::Scope_End) {
            this->parsed = true;
            break;
        }

        if(!TpTools::is_scope(tp)) {
            val.name_ptr = this->env->store_string(seg_name).first;
            return val;

        } else {
            auto* link = this->env->store_node(*this, Node(this->env->tree, tp), seg_name);
            link->field.read_source();
        }
    }

    if(throw_ex) {
        throw Exception("Cannot access Value. Index out of bounds");
    }

    return Value(Type::Null);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, -0x180(%rbp)
movb %dl, %al
movq %rdi, -0x178(%rbp)
movq %rsi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq %rcx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x170(%rbp)
addq $0x28, %rdi
callq 0x37c30
cmpq $0x0, %rax
jbe 0x47ce8
movq -0x170(%rbp), %rdi
addq $0x28, %rdi
callq 0x34cb0
movq %rax, -0x20(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x368a0
movq -0x180(%rbp), %rcx
movq %rax, %rdx
movq -0x170(%rbp), %rax
movq 0x8(%rdx), %rsi
movq %rsi, (%rcx)
movq 0x10(%rdx), %rsi
movq %rsi, 0x8(%rcx)
movq 0x18(%rdx), %rdx
movq %rdx, 0x10(%rcx)
addq $0x28, %rax
movq %rax, -0x188(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x35720
movq -0x188(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0x38500
movq %rax, -0x30(%rbp)
jmp 0x47fe5
jmp 0x47cea
movq -0x170(%rbp), %rax
movb 0x51(%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x47cff
jmp 0x47ef1
leaq -0x40(%rbp), %rdi
callq 0x374c0
movq -0x180(%rbp), %rdi
movl $0xb, %esi
callq 0x33ff0
movq -0x170(%rbp), %rax
movq (%rax), %rcx
movq 0x250(%rcx), %rsi
movq (%rax), %rdx
addq $0x260, %rdx            # imm = 0x260
movq (%rsi), %rax
leaq -0x68(%rbp), %rdi
callq *0x10(%rax)
movq -0x180(%rbp), %rdx
leaq -0x78(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x37cb0
leaq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x35650
movq -0x180(%rbp), %rdi
callq 0x35b80
movb %al, -0x79(%rbp)
cmpb $0x10, -0x79(%rbp)
jne 0x47d84
movq -0x170(%rbp), %rax
movb $0x1, 0x51(%rax)
jmp 0x47ef1
movzbl -0x79(%rbp), %edi
callq 0x35db0
testb $0x1, %al
jne 0x47e15
movq -0x170(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x190(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
movl $0x1, %ecx
callq 0x38280
movq -0x190(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x34140
movq %rax, %rcx
movq -0x180(%rbp), %rax
movq %rcx, -0x90(%rbp)
movq %rdx, -0x88(%rbp)
movq -0x90(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x47fe5
movq -0x170(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
movq (%rax), %rsi
movzbl -0x79(%rbp), %edx
leaq -0x110(%rbp), %rdi
movl $0x1, %ecx
movl %ecx, -0x194(%rbp)
callq 0x33fb0
movl -0x194(%rbp), %ecx
movups -0x40(%rbp), %xmm0
movaps %xmm0, -0x130(%rbp)
movq -0x130(%rbp), %rsi
movq -0x128(%rbp), %rdx
leaq -0x120(%rbp), %rdi
callq 0x38280
jmp 0x47e71
movq -0x170(%rbp), %rsi
movq -0x1a0(%rbp), %rdi
leaq -0x110(%rbp), %rdx
leaq -0x120(%rbp), %rcx
callq 0x344c0
movq %rax, -0x1a8(%rbp)
jmp 0x47e9b
leaq -0x110(%rbp), %rdi
callq 0x38bf0
movq -0x1a8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
addq $0x8, %rdi
xorl %esi, %esi
callq 0x361e0
jmp 0x47eec
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x138(%rbp)
movl %eax, -0x13c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x38bf0
jmp 0x47ff5
jmp 0x47cea
testb $0x1, -0x9(%rbp)
je 0x47fd4
movb $0x1, -0x162(%rbp)
movl $0x28, %edi
callq 0x34160
movq %rax, -0x1b8(%rbp)
leaq -0x161(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x38240
movq -0x1b0(%rbp), %rdx
leaq 0x21630(%rip), %rsi     # 0x69564
leaq -0x160(%rbp), %rdi
callq 0x37f40
jmp 0x47f42
movq -0x1b8(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x33910
jmp 0x47f57
movq -0x1b8(%rbp), %rdi
movb $0x0, -0x162(%rbp)
movq 0x3b07c(%rip), %rsi     # 0x82fe8
movq 0x3afc5(%rip), %rdx     # 0x82f38
callq 0x37fc0
jmp 0x48001
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x138(%rbp)
movl %eax, -0x13c(%rbp)
jmp 0x47faf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x138(%rbp)
movl %eax, -0x13c(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x38ce0
leaq -0x161(%rbp), %rdi
callq 0x35f90
testb $0x1, -0x162(%rbp)
jne 0x47fc6
jmp 0x47fd2
movq -0x1b8(%rbp), %rdi
callq 0x34ce0
jmp 0x47ff5
movq -0x180(%rbp), %rdi
movl $0xb, %esi
callq 0x33ff0
movq -0x178(%rbp), %rax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq -0x138(%rbp), %rdi
callq 0x38210
nopw %cs:(%rax,%rax)