// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rsi, 0x8(%rsp)
testq %rcx, %rcx
je 0x17af
movq %rcx, %r14
movl 0x8(%rcx), %esi
cmpl $0x40, %esi
jae 0x17c8
movq %r9, %r15
movq %r8, %r12
movl %edx, %ebp
movq %rdi, %rbx
leaq 0x18(%r14), %rdi
leaq 0x14(%rsp), %r8
movq %rbx, %rdx
movq 0x8(%rsp), %rcx
callq 0x1330
testl %eax, %eax
je 0x1553
movl %eax, 0x20(%rsp)
movq %r12, 0x30(%rsp)
movq %r15, 0x28(%rsp)
movl %ebp, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
leaq 0x1(%rbx), %r15
movq %r14, %r13
addq $0x19, %r14
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
leaq 0x1(%r12), %rbp
movslq 0x14(%rsp), %rax
cmpq %rax, %rbp
jge 0x15bf
leaq (%r14,%r12), %rdi
movl 0x8(%r13), %esi
addl %ebx, %esi
leaq (%r15,%r12), %rdx
movq 0x8(%rsp), %rax
leal (%rax,%rbx), %ecx
leaq 0x24(%rsp), %r8
callq 0x1330
cmpl $0x0, 0x24(%rsp)
jle 0x1790
testl %eax, %eax
je 0x1626
decq %rbx
movq %rbp, %r12
jmp 0x1505
movslq 0x14(%rsp), %rax
cmpl %eax, 0x8(%r14)
jbe 0x1697
cmpq %rax, 0x8(%rsp)
jne 0x1804
movq %rbx, %rdi
testq %r12, %r12
je 0x1580
cmpq %r14, 0x10(%r12)
jne 0x1861
testq %r12, %r12
sete %bl
movq 0x8(%rsp), %rsi
movl %ebp, %edx
callq 0x128c
movl 0x14(%rsp), %ecx
subl %ecx, 0x8(%r14)
movq %r14, 0x10(%rax)
testq %r15, %r15
sete %cl
orb %bl, %cl
je 0x1823
testq %r12, %r12
je 0x1737
movq %rax, 0x10(%r12)
jmp 0x177e
cmpl $0x0, 0x20(%rsp)
js 0x16ba
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x10(%rsp), %edx
callq 0x128c
movq %rax, %rcx
movq %r13, (%rax)
cmpq %r13, 0x4afe(%rip)      # 0x60e8
je 0x16fe
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x1604
cmpq %r13, 0x10(%rax)
je 0x1768
pushq $0x1
popq %rax
movq 0x28(%rsp), %rdx
testq %rdx, %rdx
je 0x1781
cmpq %r13, (%rdx)
jne 0x1781
movq %rcx, (%rdx)
jmp 0x1781
movq %r12, %rsi
notq %rsi
addq 0x8(%rsp), %rsi
movq 0x18(%rsp), %rbx
leaq (%r12,%rbx), %rdi
incq %rdi
xorl %edx, %edx
callq 0x128c
incq %r12
movl %r12d, 0x8(%r13)
movq %r13, 0x10(%rax)
movq 0x30(%rsp), %r8
testq %r8, %r8
sete %sil
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
sete %dl
orb %sil, %dl
je 0x17e5
cmpq %r13, 0x4a72(%rip)      # 0x60e8
je 0x16d9
testq %r8, %r8
je 0x1707
cmpq %r13, 0x10(%r8)
jne 0x1842
addq $0x10, %r8
movq %rax, %rdx
movq %r8, %rdi
jmp 0x1716
subq %rax, 0x8(%rsp)
jbe 0x16e2
movq 0x10(%r14), %rcx
movq %rbx, %rdi
testq %rcx, %rcx
je 0x1756
movq 0x8(%rsp), %rsi
movl %ebp, %edx
movq %r14, %r8
jmp 0x172d
movq (%r13), %rcx
testq %rcx, %rcx
movl 0x10(%rsp), %edx
je 0x1741
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
xorl %r8d, %r8d
movq %r13, %r9
jmp 0x1730
leaq 0x4a08(%rip), %rdi      # 0x60e8
jmp 0x170c
jne 0x1880
xorl %eax, %eax
cmpl $0x0, 0xc(%r14)
jne 0x1781
movl %ebp, 0xc(%r14)
jmp 0x177e
movq %rcx, 0x49e3(%rip)      # 0x60e8
jmp 0x177e
testq %rdi, %rdi
je 0x176e
movq (%r13), %rdx
movq %rdx, (%rax)
movq %r13, %rdx
andq $0x0, (%rdx)
movq %rax, (%rdi)
movq %rbx, %rdi
movq %r12, %rsi
movl 0x10(%rsp), %edx
movq %r13, %rcx
movq %rax, %r8
xorl %r9d, %r9d
callq 0x148b
jmp 0x1781
testq %r15, %r15
je 0x1777
movq %rax, (%r15)
jmp 0x177e
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x128c
movq %rax, (%r13)
jmp 0x177e
movq 0x8(%rsp), %rsi
movl %ebp, %edx
callq 0x128c
movq %rax, 0x10(%r14)
jmp 0x177e
movq %rcx, 0x10(%rax)
jmp 0x177e
leaq 0x4973(%rip), %rdi      # 0x60e8
jmp 0x171a
movq %rax, 0x496a(%rip)      # 0x60e8
pushq $0x1
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1a7f(%rip), %rdi      # 0x3216
leaq 0x1866(%rip), %rsi      # 0x3004
leaq 0x19be(%rip), %rcx      # 0x3163
movl $0xb6, %edx
callq 0x1090
leaq 0x19a0(%rip), %rdi      # 0x3156
leaq 0x1847(%rip), %rsi      # 0x3004
leaq 0x199f(%rip), %rcx      # 0x3163
pushq $0x7b
jmp 0x17df
leaq 0x1920(%rip), %rdi      # 0x30ef
leaq 0x182e(%rip), %rsi      # 0x3004
leaq 0x1986(%rip), %rcx      # 0x3163
pushq $0x7c
popq %rdx
callq 0x1090
leaq 0x1a15(%rip), %rdi      # 0x3201
leaq 0x1811(%rip), %rsi      # 0x3004
leaq 0x1969(%rip), %rcx      # 0x3163
movl $0xc4, %edx
callq 0x1090
leaq 0x19bf(%rip), %rdi      # 0x31ca
leaq 0x17f2(%rip), %rsi      # 0x3004
leaq 0x194a(%rip), %rcx      # 0x3163
movl $0x88, %edx
callq 0x1090
leaq 0x19d7(%rip), %rdi      # 0x3201
leaq 0x17d3(%rip), %rsi      # 0x3004
leaq 0x192b(%rip), %rcx      # 0x3163
movl $0x8f, %edx
callq 0x1090
leaq 0x199f(%rip), %rdi      # 0x31e8
leaq 0x17b4(%rip), %rsi      # 0x3004
leaq 0x190c(%rip), %rcx      # 0x3163
movl $0xcb, %edx
callq 0x1090
leaq 0x1973(%rip), %rdi      # 0x31db
leaq 0x1795(%rip), %rsi      # 0x3004
leaq 0x18ed(%rip), %rcx      # 0x3163
movl $0x89, %edx
callq 0x1090
leaq 0x18be(%rip), %rdi      # 0x3145
leaq 0x1776(%rip), %rsi      # 0x3004
leaq 0x18ce(%rip), %rcx      # 0x3163
movl $0xa7, %edx
callq 0x1090