// File: night-shift[P]Srl/src/lib/Node.cpp
// Function: Srl::Node::consume_node(bool, unsigned long)
Node Node::consume_node(bool throw_ex, size_t)
{
    if(this->nodes.size() > 0) {
        auto itr = this->nodes.begin();
        auto stored_field = move(itr->field);
        this->nodes.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)) {
            Node node(this->env->tree, tp, false);
            node.name_ptr = this->env->store_string(seg_name).first;

            return node;

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

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x150(%rbp)
movb %dl, %al
movq %rdi, %rdx
movq %rdx, -0x148(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x140(%rbp)
addq $0x8, %rdi
callq 0x37420
cmpq $0x0, %rax
jbe 0x478ef
movq -0x140(%rbp), %rdi
addq $0x8, %rdi
callq 0x34010
movq %rax, -0x28(%rbp)
movb $0x0, -0x29(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x366d0
movq -0x150(%rbp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
callq 0x360e0
movq -0x140(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x158(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x36730
movq -0x158(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x37f60
movq %rax, -0x40(%rbp)
movb $0x1, -0x29(%rbp)
testb $0x1, -0x29(%rbp)
jne 0x478ea
movq -0x150(%rbp), %rdi
callq 0x38bf0
jmp 0x47c0b
jmp 0x478f1
movq -0x140(%rbp), %rax
movb 0x51(%rax), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x47906
jmp 0x47b0f
leaq -0x50(%rbp), %rdi
callq 0x374c0
leaq -0x68(%rbp), %rdi
movl $0xb, %esi
callq 0x33ff0
movq -0x140(%rbp), %rax
movq (%rax), %rcx
movq 0x250(%rcx), %rsi
movq (%rax), %rdx
addq $0x260, %rdx            # imm = 0x260
movq (%rsi), %rax
leaq -0x90(%rbp), %rdi
callq *0x10(%rax)
leaq -0xa0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
leaq -0x68(%rbp), %rdx
callq 0x37cb0
leaq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x35650
leaq -0x68(%rbp), %rdi
callq 0x35b80
movb %al, -0xa1(%rbp)
cmpb $0x10, -0xa1(%rbp)
jne 0x47994
movq -0x140(%rbp), %rax
movb $0x1, 0x51(%rax)
jmp 0x47b0f
movzbl -0xa1(%rbp), %edi
callq 0x35db0
testb $0x1, %al
jne 0x479a9
jmp 0x47aa6
movq -0x140(%rbp), %rax
movq -0x150(%rbp), %rdi
movb $0x0, -0xa2(%rbp)
movq (%rax), %rax
movq (%rax), %rsi
movzbl -0xa1(%rbp), %edx
xorl %ecx, %ecx
callq 0x33fb0
movq -0x140(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x160(%rbp)
movups -0x50(%rbp), %xmm0
movaps %xmm0, -0xe0(%rbp)
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
movl $0x1, %ecx
callq 0x38280
jmp 0x47a0f
movq -0x160(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x34140
movq %rdx, -0x170(%rbp)
movq %rax, -0x168(%rbp)
jmp 0x47a32
movq -0x150(%rbp), %rax
movq -0x170(%rbp), %rcx
movq -0x168(%rbp), %rdx
movq %rdx, -0xb8(%rbp)
movq %rcx, -0xb0(%rbp)
movq -0xb8(%rbp), %rcx
movq %rcx, 0x48(%rax)
movb $0x1, -0xa2(%rbp)
testb $0x1, -0xa2(%rbp)
jne 0x47aa1
jmp 0x47a95
movq -0x150(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
callq 0x38bf0
jmp 0x47c1b
movq -0x150(%rbp), %rdi
callq 0x38bf0
jmp 0x47c0b
movq -0x140(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x178(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x110(%rbp), %rsi
movq -0x108(%rbp), %rdx
leaq -0x100(%rbp), %rdi
movl $0x1, %ecx
callq 0x38280
movq -0x178(%rbp), %rdi
movq -0x140(%rbp), %rsi
leaq -0x68(%rbp), %rdx
leaq -0x100(%rbp), %rcx
callq 0x387c0
jmp 0x478f1
testb $0x1, -0x11(%rbp)
je 0x47bf2
movb $0x1, -0x132(%rbp)
movl $0x28, %edi
callq 0x34160
movq %rax, -0x188(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x38240
movq -0x180(%rbp), %rdx
leaq 0x219ea(%rip), %rsi     # 0x6953c
leaq -0x130(%rbp), %rdi
callq 0x37f40
jmp 0x47b60
movq -0x188(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x33910
jmp 0x47b75
movq -0x188(%rbp), %rdi
movb $0x0, -0x132(%rbp)
movq 0x3b45e(%rip), %rsi     # 0x82fe8
movq 0x3b3a7(%rip), %rdx     # 0x82f38
callq 0x37fc0
jmp 0x47c27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
jmp 0x47bcd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x38ce0
leaq -0x131(%rbp), %rdi
callq 0x35f90
testb $0x1, -0x132(%rbp)
jne 0x47be4
jmp 0x47bf0
movq -0x188(%rbp), %rdi
callq 0x34ce0
jmp 0x47c1b
movq -0x150(%rbp), %rdi
movq -0x140(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rsi
callq 0x38b30
movq -0x148(%rbp), %rax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0xe8(%rbp), %rdi
callq 0x38210
nopw (%rax,%rax)