// File: /workspace/github_c_makefile_star2_O3/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
testq %rcx, %rcx
je 0x17a9
movq %rcx, %rbx
movq %rsi, %r13
movl 0x8(%rcx), %esi
cmpl $0x40, %esi
jae 0x17c8
movq %r9, %r15
movq %r8, %rbp
movl %edx, %r14d
movq %rdi, %r12
leaq 0x18(%rbx), %rdi
movq %rsp, %r8
movq %r12, %rdx
movl %r13d, %ecx
callq 0x133a
testl %eax, %eax
je 0x15d1
movl %eax, 0x18(%rsp)
movq %rbp, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x20(%rsp)
movl %r14d, 0x4(%rsp)
cmpl $0x2, (%rsp)
jl 0x156a
movq 0x8(%rsp), %rax
leaq 0x1(%rax), %r15
leaq 0x19(%rbx), %r14
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %ebp, %ebp
leaq (%r14,%rbp), %rdi
leal (%r12,%r13), %ecx
movl 0x8(%rbx), %esi
addl %r12d, %esi
leaq (%r15,%rbp), %rdx
leaq 0x1c(%rsp), %r8
callq 0x133a
cmpl $0x0, 0x1c(%rsp)
jle 0x178a
testl %eax, %eax
je 0x167e
movslq (%rsp), %rax
leaq 0x1(%rbp), %rcx
addq $0x2, %rbp
decq %r12
cmpq %rax, %rbp
movq %rcx, %rbp
jl 0x1524
cmpl $0x0, 0x18(%rsp)
js 0x165b
movq 0x8(%rsp), %rdi
movq %r13, %rsi
movl 0x4(%rsp), %edx
callq 0x128c
movq %rax, %rcx
movq %rbx, (%rax)
cmpq %rbx, 0x3b55(%rip)      # 0x50e8
je 0x16ed
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x15ad
cmpq %rbx, 0x10(%rax)
je 0x1727
movl $0x1, %eax
movq 0x20(%rsp), %rdx
testq %rdx, %rdx
je 0x1772
cmpq %rbx, (%rdx)
jne 0x1772
movq %rcx, (%rdx)
jmp 0x1772
movslq (%rsp), %rax
cmpl %eax, 0x8(%rbx)
jbe 0x1634
cmpq %rax, %r13
jne 0x17e7
testq %rbp, %rbp
je 0x15f2
cmpq %rbx, 0x10(%rbp)
jne 0x1844
testq %rbp, %rbp
sete 0x8(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
callq 0x128c
movl (%rsp), %ecx
subl %ecx, 0x8(%rbx)
movq %rbx, 0x10(%rax)
testq %r15, %r15
sete %cl
orb 0x8(%rsp), %cl
je 0x1806
testq %rbp, %rbp
je 0x170a
movq %rax, 0x10(%rbp)
jmp 0x176d
subq %rax, %r13
jbe 0x16f6
movq 0x10(%rbx), %rcx
movq %r12, %rdi
movq %r13, %rsi
movl %r14d, %edx
testq %rcx, %rcx
je 0x175b
movq %rbx, %r8
jmp 0x1751
movq (%rbx), %rcx
testq %rcx, %rcx
movl 0x4(%rsp), %edx
movq 0x8(%rsp), %rdi
movq %r13, %rsi
je 0x1714
xorl %r8d, %r8d
movq %rbx, %r9
jmp 0x1754
movq %rbp, %rsi
notq %rsi
addq %r13, %rsi
movq 0x8(%rsp), %r14
leaq (%r14,%rbp), %rdi
incq %rdi
xorl %edx, %edx
callq 0x128c
incq %rbp
movl %ebp, 0x8(%rbx)
movq %rbx, 0x10(%rax)
cmpq $0x0, 0x10(%rsp)
sete %cl
movq 0x20(%rsp), %rsi
testq %rsi, %rsi
sete %dl
orb %cl, %dl
je 0x1825
cmpq %rbx, 0x3a21(%rip)      # 0x50e8
movl 0x4(%rsp), %edx
je 0x171e
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x172d
cmpq %rbx, 0x10(%rdi)
jne 0x1882
addq $0x10, %rdi
movq %rax, %rcx
movq %rdi, %rsi
jmp 0x173b
movq %rcx, 0x39f4(%rip)      # 0x50e8
jmp 0x176d
jne 0x1863
xorl %eax, %eax
cmpl $0x0, 0xc(%rbx)
jne 0x1772
movl %r14d, 0xc(%rbx)
jmp 0x176d
testq %r15, %r15
je 0x1766
movq %rax, (%r15)
jmp 0x176d
callq 0x128c
movq %rax, (%rbx)
jmp 0x176d
leaq 0x39c3(%rip), %rsi      # 0x50e8
jmp 0x1732
movq %rcx, 0x10(%rax)
jmp 0x176d
testq %rsi, %rsi
je 0x1781
movq (%rbx), %rcx
movq %rcx, (%rax)
movq %rbx, %rcx
movq $0x0, (%rcx)
movq %rax, (%rsi)
movq %r14, %rdi
movq %rbp, %rsi
movq %rbx, %rcx
movq %rax, %r8
xorl %r9d, %r9d
callq 0x14a2
jmp 0x1772
callq 0x128c
movq %rax, 0x10(%rbx)
jmp 0x176d
movq %rax, 0x397b(%rip)      # 0x50e8
movl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3960(%rip), %rsi      # 0x50e8
jmp 0x1742
leaq 0x1a85(%rip), %rdi      # 0x3216
leaq 0x186c(%rip), %rsi      # 0x3004
leaq 0x19c4(%rip), %rcx      # 0x3163
movl $0xb6, %edx
callq 0x1090
leaq 0x19a6(%rip), %rdi      # 0x3156
leaq 0x184d(%rip), %rsi      # 0x3004
leaq 0x19a5(%rip), %rcx      # 0x3163
movl $0x7b, %edx
callq 0x1090
leaq 0x1920(%rip), %rdi      # 0x30ef
leaq 0x182e(%rip), %rsi      # 0x3004
leaq 0x1986(%rip), %rcx      # 0x3163
movl $0x7c, %edx
callq 0x1090
leaq 0x19dc(%rip), %rdi      # 0x31ca
leaq 0x180f(%rip), %rsi      # 0x3004
leaq 0x1967(%rip), %rcx      # 0x3163
movl $0x88, %edx
callq 0x1090
leaq 0x19f4(%rip), %rdi      # 0x3201
leaq 0x17f0(%rip), %rsi      # 0x3004
leaq 0x1948(%rip), %rcx      # 0x3163
movl $0x8f, %edx
callq 0x1090
leaq 0x19d5(%rip), %rdi      # 0x3201
leaq 0x17d1(%rip), %rsi      # 0x3004
leaq 0x1929(%rip), %rcx      # 0x3163
movl $0xc4, %edx
callq 0x1090
leaq 0x1990(%rip), %rdi      # 0x31db
leaq 0x17b2(%rip), %rsi      # 0x3004
leaq 0x190a(%rip), %rcx      # 0x3163
movl $0x89, %edx
callq 0x1090
leaq 0x18db(%rip), %rdi      # 0x3145
leaq 0x1793(%rip), %rsi      # 0x3004
leaq 0x18eb(%rip), %rcx      # 0x3163
movl $0xa7, %edx
callq 0x1090
leaq 0x195f(%rip), %rdi      # 0x31e8
leaq 0x1774(%rip), %rsi      # 0x3004
leaq 0x18cc(%rip), %rcx      # 0x3163
movl $0xcb, %edx
callq 0x1090