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

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

    auto id_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(id_conv, seg_name)) {
                return Node(this->env->tree, tp, false);
            }

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

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

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

    return Node(this->env->tree);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movq %rdi, -0x188(%rbp)
movb %dl, %al
movq %rdi, %rdx
movq %rdx, -0x180(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x20(%rbp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
movq (%rax), %rdx
callq 0x47290
movq -0x178(%rbp), %rdi
movq %rax, -0x28(%rbp)
addq $0x8, %rdi
callq 0x36ee0
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x357a0
testb $0x1, %al
jne 0x46ef8
jmp 0x46f66
movb $0x0, -0x31(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x366d0
movq -0x188(%rbp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
callq 0x360e0
movq -0x178(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x190(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x36730
movq -0x190(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x37f60
movq %rax, -0x48(%rbp)
movb $0x1, -0x31(%rbp)
testb $0x1, -0x31(%rbp)
jne 0x46f61
movq -0x188(%rbp), %rdi
callq 0x38bf0
jmp 0x4726d
movq -0x178(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x37800
movq %rax, -0x58(%rbp)
movq %rdx, -0x50(%rbp)
movq -0x178(%rbp), %rax
movb 0x51(%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x46f96
jmp 0x471b9
leaq -0x68(%rbp), %rdi
callq 0x374c0
leaq -0x80(%rbp), %rdi
movl $0xb, %esi
callq 0x33ff0
movq -0x178(%rbp), %rax
movq (%rax), %rcx
movq 0x250(%rcx), %rsi
movq (%rax), %rdx
addq $0x260, %rdx            # imm = 0x260
movq (%rsi), %rax
leaq -0xa8(%rbp), %rdi
callq *0x10(%rax)
leaq -0xb8(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x37cb0
leaq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x35650
leaq -0x80(%rbp), %rdi
callq 0x35b80
movb %al, -0xb9(%rbp)
cmpb $0x10, -0xb9(%rbp)
jne 0x47024
movq -0x178(%rbp), %rax
movb $0x1, 0x51(%rax)
jmp 0x471b9
movzbl -0xb9(%rbp), %edi
callq 0x35db0
testb $0x1, %al
jne 0x47039
jmp 0x47150
leaq -0x58(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x47340
testb $0x1, %al
jne 0x4704c
jmp 0x47073
movq -0x188(%rbp), %rdi
movq -0x178(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rsi
xorl %ecx, %ecx
movzbl -0xb9(%rbp), %edx
callq 0x33fb0
jmp 0x4726d
movq -0x178(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1a0(%rbp)
movq (%rax), %rsi
movzbl -0xb9(%rbp), %edx
leaq -0x120(%rbp), %rdi
movl $0x1, %ecx
movl %ecx, -0x194(%rbp)
callq 0x33fb0
movl -0x194(%rbp), %ecx
movups -0x68(%rbp), %xmm0
movaps %xmm0, -0x140(%rbp)
movq -0x140(%rbp), %rsi
movq -0x138(%rbp), %rdx
leaq -0x130(%rbp), %rdi
callq 0x38280
jmp 0x470d2
movq -0x178(%rbp), %rsi
movq -0x1a0(%rbp), %rdi
leaq -0x120(%rbp), %rdx
leaq -0x130(%rbp), %rcx
callq 0x344c0
movq %rax, -0x1a8(%rbp)
jmp 0x470fc
leaq -0x120(%rbp), %rdi
callq 0x38bf0
movq -0x1a8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rdi
addq $0x8, %rdi
xorl %esi, %esi
callq 0x361e0
jmp 0x471b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x38bf0
jmp 0x4727d
movq -0x178(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x1b0(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x170(%rbp), %rsi
movq -0x168(%rbp), %rdx
leaq -0x160(%rbp), %rdi
movl $0x1, %ecx
callq 0x38280
movq -0x1b0(%rbp), %rdi
movq -0x178(%rbp), %rsi
leaq -0x80(%rbp), %rdx
leaq -0x160(%rbp), %rcx
callq 0x387c0
jmp 0x46f81
testb $0x1, -0x11(%rbp)
je 0x4724a
movl $0x28, %edi
callq 0x34160
movq -0x178(%rbp), %rdi
movq %rax, -0x1c8(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x1c0(%rbp)
callq 0x362a0
movq %rax, -0x1b8(%rbp)
jmp 0x471f4
movq -0x1b8(%rbp), %rdx
movq -0x1c0(%rbp), %rsi
movq -0x1c8(%rbp), %rdi
callq 0x46ca0
jmp 0x47210
movq -0x1c8(%rbp), %rdi
movq 0x3bdca(%rip), %rsi     # 0x82fe8
movq 0x3bd13(%rip), %rdx     # 0x82f38
callq 0x37fc0
movq -0x1c8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x148(%rbp)
movl %eax, -0x14c(%rbp)
callq 0x34ce0
jmp 0x4727d
movq -0x188(%rbp), %rdi
movq -0x178(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rsi
movl $0xe, %edx
movl $0x1, %ecx
callq 0x33fb0
movq -0x180(%rbp), %rax
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
movq -0x148(%rbp), %rdi
callq 0x38210
nopl (%rax)