// File: night-shift[P]Srl/src/lib/Node.cpp
// Function: Srl::Node::consume_item(Srl::String const&, bool)
Union Node::consume_item(const String& id, bool throw_err)
{
    auto* storednode = find_link<Name>(id, this->nodes);

    if(storednode) {
        return Union(storednode->field);
    }

    auto* storedvalue = find_link<Name>(id, this->values);

    if(storedvalue) {
        return Union(storedvalue->field);
    }

    auto hash = hash_string(id, *this->env);

    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)) {
            auto* link = this->env->store_node(*this, Node(this->env->tree, tp), seg_name);
            link->field.read_source();
            if(link->hash == hash && link->field.name() == id) {
                return Union(link->field);
            }

        } else {
            auto* link = this->env->store_value(*this, val, seg_name);
            if(link->hash == hash && link->field.name() == id) {
                return Union(link->field);
            }
        }
    }

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

    return Union();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movb %dl, %al
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x18(%rbp), %rdx
movq %rdx, -0x190(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x40(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
addq $0x8, %rdx
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq 0x3c725(%rip), %r8      # 0x82f30
movq %r8, %rcx
callq 0x46c10
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x46834
movq -0x30(%rbp), %rsi
addq $0x8, %rsi
leaq -0x10(%rbp), %rdi
callq 0x33a40
jmp 0x46be4
movq -0x190(%rbp), %rdx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
addq $0x28, %rdx
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq 0x3c6cf(%rip), %r8      # 0x82f30
movq %r8, %rcx
callq 0x45fd0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x4688a
movq -0x48(%rbp), %rsi
addq $0x8, %rsi
leaq -0x10(%rbp), %rdi
callq 0x368f0
jmp 0x46be4
movq -0x190(%rbp), %rax
movq -0x20(%rbp), %rdi
movq (%rax), %rsi
callq 0x45100
movq %rax, -0x60(%rbp)
movq -0x190(%rbp), %rax
movb 0x51(%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x468b6
jmp 0x46b4a
leaq -0x70(%rbp), %rdi
callq 0x374c0
leaq -0x88(%rbp), %rdi
movl $0xb, %esi
callq 0x33ff0
movq -0x190(%rbp), %rax
movq (%rax), %rcx
movq 0x250(%rcx), %rsi
movq (%rax), %rdx
addq $0x260, %rdx            # imm = 0x260
movq (%rsi), %rax
leaq -0xb0(%rbp), %rdi
callq *0x10(%rax)
leaq -0xc0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x37cb0
leaq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x35650
leaq -0x88(%rbp), %rdi
callq 0x35b80
movb %al, -0xc1(%rbp)
cmpb $0x10, -0xc1(%rbp)
jne 0x4694d
movq -0x190(%rbp), %rax
movb $0x1, 0x51(%rax)
jmp 0x46b4a
movzbl -0xc1(%rbp), %edi
callq 0x35db0
testb $0x1, %al
jne 0x46962
jmp 0x46a8a
movq -0x190(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
movq (%rax), %rsi
movzbl -0xc1(%rbp), %edx
leaq -0x128(%rbp), %rdi
movl $0x1, %ecx
movl %ecx, -0x194(%rbp)
callq 0x33fb0
movl -0x194(%rbp), %ecx
movups -0x70(%rbp), %xmm0
movaps %xmm0, -0x150(%rbp)
movq -0x150(%rbp), %rsi
movq -0x148(%rbp), %rdx
leaq -0x138(%rbp), %rdi
callq 0x38280
jmp 0x469c1
movq -0x190(%rbp), %rsi
movq -0x1a0(%rbp), %rdi
leaq -0x128(%rbp), %rdx
leaq -0x138(%rbp), %rcx
callq 0x344c0
movq %rax, -0x1a8(%rbp)
jmp 0x469eb
leaq -0x128(%rbp), %rdi
callq 0x38bf0
movq -0x1a8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
addq $0x8, %rdi
xorl %esi, %esi
callq 0x361e0
movq -0xd0(%rbp), %rax
movq (%rax), %rax
cmpq -0x60(%rbp), %rax
jne 0x46a85
movq -0xd0(%rbp), %rdi
addq $0x8, %rdi
callq 0x362a0
movq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x33e90
testb $0x1, %al
jne 0x46a49
jmp 0x46a85
movq -0xd0(%rbp), %rsi
addq $0x8, %rsi
leaq -0x10(%rbp), %rdi
callq 0x33a40
jmp 0x46be4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x38bf0
jmp 0x46bf5
jmp 0x46b45
movq -0x190(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1b0(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x180(%rbp)
movq -0x188(%rbp), %rsi
movq -0x180(%rbp), %rdx
leaq -0x178(%rbp), %rdi
movl $0x1, %ecx
callq 0x38280
movq -0x1b0(%rbp), %rdi
movq -0x190(%rbp), %rsi
leaq -0x88(%rbp), %rdx
leaq -0x178(%rbp), %rcx
callq 0x387c0
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rax
movq (%rax), %rax
cmpq -0x60(%rbp), %rax
jne 0x46b43
movq -0x168(%rbp), %rdi
addq $0x8, %rdi
callq 0x35770
movq %rax, %rdi
movq -0x20(%rbp), %rsi
callq 0x33e90
testb $0x1, %al
jne 0x46b2a
jmp 0x46b43
movq -0x168(%rbp), %rsi
addq $0x8, %rsi
leaq -0x10(%rbp), %rdi
callq 0x368f0
jmp 0x46be4
jmp 0x46b45
jmp 0x468a1
testb $0x1, -0x21(%rbp)
je 0x46bdb
movl $0x28, %edi
callq 0x34160
movq -0x190(%rbp), %rdi
movq %rax, -0x1c8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x1c0(%rbp)
callq 0x362a0
movq %rax, -0x1b8(%rbp)
jmp 0x46b85
movq -0x1b8(%rbp), %rdx
movq -0x1c0(%rbp), %rsi
movq -0x1c8(%rbp), %rdi
callq 0x46ca0
jmp 0x46ba1
movq -0x1c8(%rbp), %rdi
movq 0x3c439(%rip), %rsi     # 0x82fe8
movq 0x3c382(%rip), %rdx     # 0x82f38
callq 0x37fc0
movq -0x1c8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x158(%rbp)
movl %eax, -0x15c(%rbp)
callq 0x34ce0
jmp 0x46bf5
leaq -0x10(%rbp), %rdi
callq 0x36c00
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rdx
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
movq -0x158(%rbp), %rdi
callq 0x38210
nopw %cs:(%rax,%rax)