// File: night-shift[P]Srl/src/lib/Node.cpp
// Function: Srl::Node::consume_value(bool, Srl::String const&)
Value Node::consume_value(bool throw_ex, const String& id)
{
    auto stored_itr = find_link_iterator(id, this->values, *this->env);

    if(stored_itr != this->values.end()) {
        auto stored_field = move(stored_itr->field);
        this->values.erase(stored_itr);
        return stored_field;
    }

    auto name_conv = this->env->conv_string(id);

    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)) {
            if(compare(name_conv, seg_name)) {
                return val;
            }

            this->env->store_value(*this, val, seg_name);

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

    if(throw_ex) {
        throw field_name_not_found_ex(id, this->name());
    }

    return Value(Type::Null);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x168(%rbp)
movb %dl, %al
movq %rdi, -0x160(%rbp)
movq %rsi, -0x8(%rbp)
andb $0x1, %al
movb %al, -0x9(%rbp)
movq %rcx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x18(%rbp), %rdi
movq %rax, %rsi
addq $0x28, %rsi
movq (%rax), %rdx
callq 0x47770
movq -0x158(%rbp), %rdi
movq %rax, -0x20(%rbp)
addq $0x28, %rdi
callq 0x344b0
movq %rax, -0x28(%rbp)
leaq -0x20(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x337f0
testb $0x1, %al
jne 0x47411
jmp 0x47473
leaq -0x20(%rbp), %rdi
callq 0x368a0
movq -0x168(%rbp), %rcx
movq %rax, %rdx
movq -0x158(%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, -0x170(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x35720
movq -0x170(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x38500
movq %rax, -0x38(%rbp)
jmp 0x4774d
movq -0x158(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x37800
movq %rax, -0x48(%rbp)
movq %rdx, -0x40(%rbp)
movq -0x158(%rbp), %rax
movb 0x51(%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x474a3
jmp 0x476ab
leaq -0x58(%rbp), %rdi
callq 0x374c0
movq -0x168(%rbp), %rdi
movl $0xb, %esi
callq 0x33ff0
movq -0x158(%rbp), %rax
movq (%rax), %rcx
movq 0x250(%rcx), %rsi
movq (%rax), %rdx
addq $0x260, %rdx            # imm = 0x260
movq (%rsi), %rax
leaq -0x80(%rbp), %rdi
callq *0x10(%rax)
movq -0x168(%rbp), %rdx
leaq -0x90(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x37cb0
leaq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x35650
movq -0x168(%rbp), %rdi
callq 0x35b80
movb %al, -0x91(%rbp)
cmpb $0x10, -0x91(%rbp)
jne 0x47534
movq -0x158(%rbp), %rax
movb $0x1, 0x51(%rax)
jmp 0x476ab
movzbl -0x91(%rbp), %edi
callq 0x35db0
testb $0x1, %al
jne 0x475cc
leaq -0x48(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x47340
testb $0x1, %al
jne 0x4755b
jmp 0x47560
jmp 0x4774d
movq -0x158(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x178(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xb8(%rbp), %rsi
movq -0xb0(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
movl $0x1, %ecx
callq 0x38280
movq -0x178(%rbp), %rdi
movq -0x158(%rbp), %rsi
movq -0x168(%rbp), %rdx
leaq -0xa8(%rbp), %rcx
callq 0x387c0
jmp 0x476a6
movq -0x158(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x188(%rbp)
movq (%rax), %rsi
movzbl -0x91(%rbp), %edx
leaq -0x118(%rbp), %rdi
movl $0x1, %ecx
movl %ecx, -0x17c(%rbp)
callq 0x33fb0
movl -0x17c(%rbp), %ecx
movups -0x58(%rbp), %xmm0
movaps %xmm0, -0x140(%rbp)
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rdx
leaq -0x128(%rbp), %rdi
callq 0x38280
jmp 0x4762b
movq -0x158(%rbp), %rsi
movq -0x188(%rbp), %rdi
leaq -0x118(%rbp), %rdx
leaq -0x128(%rbp), %rcx
callq 0x344c0
movq %rax, -0x190(%rbp)
jmp 0x47655
leaq -0x118(%rbp), %rdi
callq 0x38bf0
movq -0x190(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rdi
addq $0x8, %rdi
xorl %esi, %esi
callq 0x361e0
jmp 0x476a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x38bf0
jmp 0x4775d
jmp 0x4748e
testb $0x1, -0x9(%rbp)
je 0x4773c
movl $0x28, %edi
callq 0x34160
movq -0x158(%rbp), %rdi
movq %rax, -0x1a8(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1a0(%rbp)
callq 0x362a0
movq %rax, -0x198(%rbp)
jmp 0x476e6
movq -0x198(%rbp), %rdx
movq -0x1a0(%rbp), %rsi
movq -0x1a8(%rbp), %rdi
callq 0x46ca0
jmp 0x47702
movq -0x1a8(%rbp), %rdi
movq 0x3b8d8(%rip), %rsi     # 0x82fe8
movq 0x3b821(%rip), %rdx     # 0x82f38
callq 0x37fc0
movq -0x1a8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
callq 0x34ce0
jmp 0x4775d
movq -0x168(%rbp), %rdi
movl $0xb, %esi
callq 0x33ff0
movq -0x160(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0x148(%rbp), %rdi
callq 0x38210
nopl (%rax)