// File: /workspace/github_c_makefile_star2_O1/stevenmherring[P]DNS/sequential-trie.c
// Function: insert
int _insert (const char *string, size_t strlen, int32_t ip4_address,
  struct trie_node *node, struct trie_node *parent, struct trie_node *left) {

    int cmp, keylen;

    // First things first, check if we are NULL
    assert (node != NULL);
    assert (node->strlen < 64);

    // Take the minimum of the two lengths
    cmp = compare_keys (node->key, node->strlen, string, strlen, &keylen);
    if (cmp == 0) {
      // Yes, either quit, or recur on the children

      // If this key is longer than our search string, we need to insert
      // "above" this node
      if (node->strlen > keylen) {
        struct trie_node *new_node;

        assert(keylen == strlen);
        assert((!parent) || parent->children == node);

        new_node = new_leaf (string, strlen, ip4_address);
        node->strlen -= keylen;
        new_node->children = node;

        assert ((!parent) || (!left));

        if (parent) {
          parent->children = new_node;
        } else if (left) {
          left->next = new_node;
        } else if ((!parent) || (!left)) {
          root = new_node;
        }
        return 1;

      } else if (strlen > keylen) {

        if (node->children == NULL) {
          // Insert leaf here
          struct trie_node *new_node = new_leaf (string, strlen - keylen, ip4_address);
          node->children = new_node;
          return 1;
        } else {
          // Recur on children list, store "parent" (loosely defined)
          return _insert(string, strlen - keylen, ip4_address,
            node->children, node, NULL);
          }
        } else {
          assert (strlen == keylen);
          if (node->ip4_address == 0) {
            node->ip4_address = ip4_address;
            return 1;
          } else {
            return 0;
          }
        }

      } else {
        /* Is there any common substring? */
        int i, cmp2, keylen2, overlap = 0;
        for (i = 1; i < keylen; i++) {
          cmp2 = compare_keys (&node->key[i], node->strlen - i,
            &string[i], strlen - i, &keylen2);
            assert (keylen2 > 0);
            if (cmp2 == 0) {
              overlap = 1;
              break;
            }
          }

          if (overlap) {
            // Insert a common parent, recur
            struct trie_node *new_node = new_leaf (&string[i], strlen - i, 0);
            int diff = node->strlen - i;
            assert ((node->strlen - diff) > 0);
            node->strlen -= diff;
            new_node->children = node;
            assert ((!parent) || (!left));

            if (node == root) {
              new_node->next = node->next;
              node->next = NULL;
              root = new_node;
            } else if (parent) {
              assert(parent->children == node);
              new_node->next = NULL;
              parent->children = new_node;
            } else if (left) {
              new_node->next = node->next;
              node->next = NULL;
              left->next = new_node;
            } else if ((!parent) && (!left)) {
              root = new_node;
            }

            return _insert(string, i, ip4_address,
              node, new_node, NULL);
            } else if (cmp < 0) {
              if (node->next == NULL) {
                // Insert here
                struct trie_node *new_node = new_leaf (string, strlen, ip4_address);
                node->next = new_node;
                return 1;
              } else {
                // No, recur right (the node's key is "greater" than  the search key)
                return _insert(string, strlen, ip4_address, node->next, NULL, node);
              }
            } else {
              // Insert here
              struct trie_node *new_node = new_leaf (string, strlen, ip4_address);
              new_node->next = node;
              if (node == root)
              root = new_node;
              else if (parent && parent->children == node)
              parent->children = new_node;
              else if (left && left->next == node)
              left->next = new_node;
            }
            return 1;
          }
        }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, (%rsp)
testq %rcx, %rcx
je 0x17a8
movq %rcx, %rbx
movq %rsi, %r13
movq %r8, 0x10(%rsp)
movl 0x8(%rcx), %esi
cmpl $0x40, %esi
jae 0x17c7
movq %r9, %r12
movl %edx, %r15d
leaq 0x18(%rbx), %r14
leaq 0x8(%rsp), %r8
movq %r14, %rdi
movq (%rsp), %rdx
movl %r13d, %ecx
callq 0x133c
testl %eax, %eax
je 0x15c2
movl %eax, 0x18(%rsp)
movq %r12, 0x20(%rsp)
movl %r15d, 0xc(%rsp)
cmpl $0x2, 0x8(%rsp)
jl 0x155c
movl $0x1, %ebp
leaq 0x1c(%rsp), %r12
leaq (%r14,%rbp), %rdi
movl 0x8(%rbx), %esi
subl %ebp, %esi
movq (%rsp), %rax
leaq (%rax,%rbp), %r15
movl %r13d, %ecx
subl %ebp, %ecx
movq %r15, %rdx
movq %r12, %r8
callq 0x133c
cmpl $0x0, 0x1c(%rsp)
jle 0x1789
testl %eax, %eax
je 0x1675
incq %rbp
movslq 0x8(%rsp), %rax
cmpq %rax, %rbp
jl 0x151b
cmpl $0x0, 0x18(%rsp)
js 0x1653
movq (%rsp), %rdi
movq %r13, %rsi
movl 0xc(%rsp), %edx
callq 0x128c
movq %rax, %rcx
movq %rbx, (%rax)
cmpq %rbx, 0x3b64(%rip)      # 0x50e8
je 0x16d2
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x159e
cmpq %rbx, 0x10(%rax)
je 0x171b
movl $0x1, %eax
movq 0x20(%rsp), %rdx
testq %rdx, %rdx
je 0x1771
cmpq %rbx, (%rdx)
jne 0x1771
movq %rcx, (%rdx)
jmp 0x1771
movslq 0x8(%rsp), %rax
cmpl %eax, 0x8(%rbx)
movq 0x10(%rsp), %r14
jbe 0x162b
cmpq %rax, %r13
jne 0x17e6
testq %r14, %r14
je 0x15e9
cmpq %rbx, 0x10(%r14)
jne 0x1843
testq %r14, %r14
sete %bpl
movq (%rsp), %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x128c
movl 0x8(%rsp), %ecx
subl %ecx, 0x8(%rbx)
movq %rbx, 0x10(%rax)
testq %r12, %r12
sete %cl
orb %bpl, %cl
je 0x1805
testq %r14, %r14
je 0x16f6
movq %rax, 0x10(%r14)
jmp 0x176c
subq %rax, %r13
jbe 0x16de
movq 0x10(%rbx), %rcx
testq %rcx, %rcx
je 0x1750
movq (%rsp), %rdi
movq %r13, %rsi
movl %r15d, %edx
movq %rbx, %r8
jmp 0x1746
movq (%rbx), %rcx
testq %rcx, %rcx
movl 0xc(%rsp), %edx
je 0x1701
movq (%rsp), %rdi
movq %r13, %rsi
xorl %r8d, %r8d
movq %rbx, %r9
jmp 0x1749
subq %rbp, %r13
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x128c
movl %ebp, 0x8(%rbx)
movq %rbx, 0x10(%rax)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
sete %cl
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
sete %dl
orb %cl, %dl
je 0x1824
cmpq %rbx, 0x3a37(%rip)      # 0x50e8
movl 0xc(%rsp), %edx
je 0x1712
testq %rdi, %rdi
je 0x1721
cmpq %rbx, 0x10(%rdi)
jne 0x1881
addq $0x10, %rdi
movq %rax, %rcx
movq %rdi, %rsi
jmp 0x172f
movq %rcx, 0x3a0f(%rip)      # 0x50e8
jmp 0x176c
jne 0x1862
xorl %eax, %eax
cmpl $0x0, 0xc(%rbx)
jne 0x1771
movl %r15d, 0xc(%rbx)
jmp 0x176c
testq %r12, %r12
je 0x1765
movq %rax, (%r12)
jmp 0x176c
movq (%rsp), %rdi
movq %r13, %rsi
callq 0x128c
movq %rax, (%rbx)
jmp 0x176c
leaq 0x39cf(%rip), %rsi      # 0x50e8
jmp 0x1726
movq %rcx, 0x10(%rax)
jmp 0x176c
testq %rsi, %rsi
je 0x1780
movq (%rbx), %rcx
movq %rcx, (%rax)
movq %rbx, %rcx
movq $0x0, (%rcx)
movq %rax, (%rsi)
movq (%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %rcx
movq %rax, %r8
xorl %r9d, %r9d
callq 0x14a4
jmp 0x1771
movq (%rsp), %rdi
movq %r13, %rsi
movl %r15d, %edx
callq 0x128c
movq %rax, 0x10(%rbx)
jmp 0x176c
movq %rax, 0x397c(%rip)      # 0x50e8
movl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3961(%rip), %rsi      # 0x50e8
jmp 0x1736
leaq 0x1a86(%rip), %rdi      # 0x3216
leaq 0x186d(%rip), %rsi      # 0x3004
leaq 0x19c5(%rip), %rcx      # 0x3163
movl $0xb6, %edx
callq 0x1090
leaq 0x19a7(%rip), %rdi      # 0x3156
leaq 0x184e(%rip), %rsi      # 0x3004
leaq 0x19a6(%rip), %rcx      # 0x3163
movl $0x7b, %edx
callq 0x1090
leaq 0x1921(%rip), %rdi      # 0x30ef
leaq 0x182f(%rip), %rsi      # 0x3004
leaq 0x1987(%rip), %rcx      # 0x3163
movl $0x7c, %edx
callq 0x1090
leaq 0x19dd(%rip), %rdi      # 0x31ca
leaq 0x1810(%rip), %rsi      # 0x3004
leaq 0x1968(%rip), %rcx      # 0x3163
movl $0x88, %edx
callq 0x1090
leaq 0x19f5(%rip), %rdi      # 0x3201
leaq 0x17f1(%rip), %rsi      # 0x3004
leaq 0x1949(%rip), %rcx      # 0x3163
movl $0x8f, %edx
callq 0x1090
leaq 0x19d6(%rip), %rdi      # 0x3201
leaq 0x17d2(%rip), %rsi      # 0x3004
leaq 0x192a(%rip), %rcx      # 0x3163
movl $0xc4, %edx
callq 0x1090
leaq 0x1991(%rip), %rdi      # 0x31db
leaq 0x17b3(%rip), %rsi      # 0x3004
leaq 0x190b(%rip), %rcx      # 0x3163
movl $0x89, %edx
callq 0x1090
leaq 0x18dc(%rip), %rdi      # 0x3145
leaq 0x1794(%rip), %rsi      # 0x3004
leaq 0x18ec(%rip), %rcx      # 0x3163
movl $0xa7, %edx
callq 0x1090
leaq 0x1960(%rip), %rdi      # 0x31e8
leaq 0x1775(%rip), %rsi      # 0x3004
leaq 0x18cd(%rip), %rcx      # 0x3163
movl $0xcb, %edx
callq 0x1090