// File: night-shift[P]Srl/src/lib/Environment.cpp
// Function: Srl::Lib::Environment::store_node(Srl::Node&, Srl::Node const&, Srl::String const&)
Link<Node>* Environment::store_node(Node& parent, const Node& node, const String& name)
{
    if(this->parsing) {

        Value scope_start = Value(node.scope_type);
        this->write(scope_start, name);

        for(auto& v : node.values) {
            this->write(v.field, v.field.name());
        }

        for(auto& n : node.nodes) {
            this->store_node(parent, n.field, n.field.name());
        }

        Value scope_end = Value(Type::Scope_End);
        this->write(scope_end, name);

        return create_node(node.scope_type, name);
    }

    if(node.env != this) {
        auto* link = this->create_link(parent.nodes, Node(this->tree, node.scope_type), name);

        for(auto& n : node.nodes) {
            link->field.insert_node(n.field, n.field.name());
        }
        for(auto& v : node.values) {
            link->field.insert_value(v.field, v.field.name());
        }

        return link;

    } else {
        return this->create_link(parent.nodes, node, name);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x150(%rbp)
testb $0x1, 0x258(%rax)
je 0x3d6db
movq -0x20(%rbp), %rax
leaq -0x40(%rbp), %rdi
movzbl 0x50(%rax), %esi
callq 0x33ff0
movq -0x150(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq -0x40(%rbp), %rsi
callq 0x35a70
movq -0x20(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x37d20
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
callq 0x34da0
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x384e0
testb $0x1, %al
jne 0x3d5b1
jmp 0x3d5fb
leaq -0x50(%rbp), %rdi
callq 0x34bf0
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x158(%rbp)
movq -0x60(%rbp), %rdi
addq $0x8, %rdi
callq 0x35770
movq -0x150(%rbp), %rdi
movq -0x158(%rbp), %rsi
movq %rax, %rdx
callq 0x35a70
leaq -0x50(%rbp), %rdi
callq 0x33b30
jmp 0x3d59e
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
callq 0x35700
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
callq 0x38960
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x33700
testb $0x1, %al
jne 0x3d634
jmp 0x3d690
leaq -0x70(%rbp), %rdi
callq 0x34260
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x80(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x160(%rbp)
movq -0x80(%rbp), %rdi
addq $0x8, %rdi
callq 0x362a0
movq -0x150(%rbp), %rdi
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rdx
movq %rax, %rcx
callq 0x344c0
leaq -0x70(%rbp), %rdi
callq 0x38030
jmp 0x3d621
leaq -0x98(%rbp), %rdi
movl $0x10, %esi
callq 0x33ff0
movq -0x150(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq -0x98(%rbp), %rsi
callq 0x35a70
movq -0x150(%rbp), %rdi
movq -0x20(%rbp), %rax
movb 0x50(%rax), %al
movq -0x28(%rbp), %rdx
movzbl %al, %esi
callq 0x337b0
movq %rax, -0x8(%rbp)
jmp 0x3d934
movq -0x150(%rbp), %rcx
movq -0x20(%rbp), %rax
cmpq %rcx, (%rax)
je 0x3d914
movq -0x150(%rbp), %rax
movq -0x18(%rbp), %rcx
addq $0x8, %rcx
movq %rcx, -0x180(%rbp)
movq (%rax), %rsi
movq -0x20(%rbp), %rax
movzbl 0x50(%rax), %edx
leaq -0xf8(%rbp), %rdi
movq %rdi, -0x178(%rbp)
movl $0x1, %ecx
callq 0x33fb0
movq -0x150(%rbp), %rdi
movq -0x180(%rbp), %rsi
movq -0x178(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x36970
movq %rax, -0x170(%rbp)
jmp 0x3d74f
leaq -0xf8(%rbp), %rdi
callq 0x38bf0
movq -0x170(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rdi
callq 0x35700
movq %rax, -0x118(%rbp)
movq -0x110(%rbp), %rdi
callq 0x38960
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x33700
testb $0x1, %al
jne 0x3d7ba
jmp 0x3d84b
leaq -0x118(%rbp), %rdi
callq 0x34260
movq %rax, -0x128(%rbp)
movq -0xa0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x190(%rbp)
movq -0x128(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x188(%rbp)
movq -0x128(%rbp), %rdi
addq $0x8, %rdi
callq 0x362a0
movq -0x190(%rbp), %rdi
movq -0x188(%rbp), %rsi
movq %rax, %rdx
callq 0x37470
leaq -0x118(%rbp), %rdi
callq 0x38030
jmp 0x3d79e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x38bf0
jmp 0x3d941
movq -0x20(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rdi
callq 0x37d20
movq %rax, -0x138(%rbp)
movq -0x130(%rbp), %rdi
callq 0x34da0
movq %rax, -0x140(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x384e0
testb $0x1, %al
jne 0x3d899
jmp 0x3d907
leaq -0x138(%rbp), %rdi
callq 0x34bf0
movq %rax, -0x148(%rbp)
movq -0xa0(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x1a0(%rbp)
movq -0x148(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x198(%rbp)
movq -0x148(%rbp), %rdi
addq $0x8, %rdi
callq 0x35770
movq -0x1a0(%rbp), %rdi
movq -0x198(%rbp), %rsi
movq %rax, %rdx
callq 0x35cc0
leaq -0x138(%rbp), %rdi
callq 0x33b30
jmp 0x3d880
movq -0xa0(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x3d934
movq -0x150(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x8, %rsi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
callq 0x36970
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
movq -0x100(%rbp), %rdi
callq 0x38210
nopl (%rax)