// File: nachogoro[P]wordcrack-herminia/src/Trie.cpp
// Function: Trie::recursiveInsertion(TrieNode*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void Trie::recursiveInsertion(TrieNode* parent, const std::string& word)
{
    if (parent->word == word)
    {
        parent->isValidWord = true;
        return;
    }

    size_t parentLength = parent->word.size();
    std::string prefix = word.substr(0, parentLength+1);

    auto node = findNodeInSetStartingWith(parent->childrenWords, prefix);
    TrieNode* newParent = NULL;
    if (node == parent->childrenWords.end())
    {
        std::unique_ptr<TrieNode> newNode(new TrieNode(prefix, false));
        parent->childrenWords.push_back(std::move(newNode));
        newParent = parent->childrenWords.back().get();
    }
    else if (prefix != (*node)->word)
    {
        // Since the trie optimises space by not creating intermediate nodes
        // with just one child, it is possible that some reorganising of the
        // trie is necessary at this point.
        std::unique_ptr<TrieNode> newNode(new TrieNode(prefix, false));
        newNode->childrenWords.push_back(std::move(*node));
        parent->childrenWords.erase(node);
        parent->childrenWords.push_back(std::move(newNode));
        newParent = parent->childrenWords.back().get();
    }
    else
    {
        newParent = node->get();
    }


    recursiveInsertion(newParent, word);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0xa8(%rbp)
movq %rsi, -0xa0(%rbp)
movq %rdx, -0x98(%rbp)
callq 0x31c0
movq -0xa8(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xbd50
testb $0x1, %al
jne 0xafa4
jmp 0xafb1
movq -0x10(%rbp), %rax
movb $0x1, 0x20(%rax)
jmp 0xb26d
movq -0x10(%rbp), %rdi
callq 0x3180
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rcx
incq %rcx
xorl %eax, %eax
movl %eax, %edx
leaq -0x40(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x3240
movq -0xb8(%rbp), %rsi
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0xb290
movq %rax, -0xb0(%rbp)
jmp 0xaffa
movq -0xb0(%rbp), %rax
movq %rax, -0x48(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0xbe60
movq %rax, -0x68(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xbe00
testb $0x1, %al
jne 0xb034
jmp 0xb0f7
movl $0x40, %edi
callq 0x3230
movq %rax, -0xc0(%rbp)
jmp 0xb047
movq -0xc0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
xorl %edx, %edx
callq 0xad70
jmp 0xb05b
movq -0xc0(%rbp), %rsi
leaq -0x70(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0xbc80
movq -0xc8(%rbp), %rsi
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0xbea0
jmp 0xb088
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0xbee0
movq %rax, %rdi
callq 0xbd10
movq %rax, -0x60(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xa6e0
jmp 0xb24e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xb276
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0x3200
jmp 0xb276
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x70(%rbp), %rdi
callq 0xa6e0
jmp 0xb276
leaq -0x48(%rbp), %rdi
callq 0xbf70
movq %rax, %rdi
callq 0xbfa0
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0xbf30
testb $0x1, %al
jne 0xb11d
jmp 0xb237
movl $0x40, %edi
callq 0x3230
movq %rax, -0xd0(%rbp)
jmp 0xb130
movq -0xd0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
xorl %edx, %edx
callq 0xad70
jmp 0xb144
movq -0xd0(%rbp), %rsi
leaq -0x78(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0xbc80
movq -0xe0(%rbp), %rdi
callq 0xbfa0
addq $0x28, %rax
movq %rax, -0xd8(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xbf70
movq -0xd8(%rbp), %rdi
movq %rax, %rsi
callq 0xbea0
jmp 0xb18c
movq -0x10(%rbp), %rax
addq $0x28, %rax
movq %rax, -0xf0(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xc050
movq -0xf0(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0xbfd0
movq %rax, -0xe8(%rbp)
jmp 0xb1c1
movq -0xe8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
leaq -0x78(%rbp), %rsi
callq 0xbea0
jmp 0xb1e2
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0xbee0
movq %rax, %rdi
callq 0xbd10
movq %rax, -0x60(%rbp)
leaq -0x78(%rbp), %rdi
callq 0xa6e0
jmp 0xb24c
movq -0xd0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
callq 0x3200
jmp 0xb276
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x78(%rbp), %rdi
callq 0xa6e0
jmp 0xb276
leaq -0x48(%rbp), %rdi
callq 0xc0a0
movq %rax, %rdi
callq 0xbd10
movq %rax, -0x60(%rbp)
jmp 0xb24e
movq -0x90(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0xaf40
jmp 0xb264
leaq -0x40(%rbp), %rdi
callq 0x3150
addq $0xf0, %rsp
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x3150
movq -0x50(%rbp), %rdi
callq 0x33f0
nopl (%rax,%rax)