// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x165b
jmp 0x167a
leaq 0x1b34(%rip), %rdi      # 0x3196
leaq 0x19db(%rip), %rsi      # 0x3044
movl $0x7b, %edx
leaq 0x1b2e(%rip), %rcx      # 0x31a3
callq 0x1080
movq -0x28(%rbp), %rax
cmpl $0x40, 0x8(%rax)
jae 0x1686
jmp 0x16a5
leaq 0x1aa2(%rip), %rdi      # 0x312f
leaq 0x19b0(%rip), %rsi      # 0x3044
movl $0x7c, %edx
leaq 0x1b03(%rip), %rcx      # 0x31a3
callq 0x1080
movq -0x28(%rbp), %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x10(%rbp), %rdx
movq -0x18(%rbp), %rax
movl %eax, %ecx
leaq -0x40(%rbp), %r8
callq 0x1390
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jne 0x18ca
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x40(%rbp), %eax
jbe 0x17f5
movslq -0x40(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x16f0
jmp 0x170f
leaq 0x1b13(%rip), %rdi      # 0x320a
leaq 0x1946(%rip), %rsi      # 0x3044
movl $0x88, %edx
leaq 0x1a99(%rip), %rcx      # 0x31a3
callq 0x1080
cmpq $0x0, -0x30(%rbp)
je 0x1724
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x28(%rbp), %rax
jne 0x1726
jmp 0x1745
leaq 0x1aee(%rip), %rdi      # 0x321b
leaq 0x1910(%rip), %rsi      # 0x3044
movl $0x89, %edx
leaq 0x1a63(%rip), %rcx      # 0x31a3
callq 0x1080
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x1290
movq %rax, -0x48(%rbp)
movl -0x40(%rbp), %edx
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
cmpq $0x0, -0x30(%rbp)
je 0x1782
cmpq $0x0, -0x38(%rbp)
jne 0x1784
jmp 0x17a3
leaq 0x1ab6(%rip), %rdi      # 0x3241
leaq 0x18b2(%rip), %rsi      # 0x3044
movl $0x8f, %edx
leaq 0x1a05(%rip), %rcx      # 0x31a3
callq 0x1080
cmpq $0x0, -0x30(%rbp)
je 0x17b8
movq -0x48(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x17e9
cmpq $0x0, -0x38(%rbp)
je 0x17cc
movq -0x48(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
jmp 0x17e7
cmpq $0x0, -0x30(%rbp)
je 0x17da
cmpq $0x0, -0x38(%rbp)
jne 0x17e5
movq -0x48(%rbp), %rax
movq %rax, 0x3903(%rip)      # 0x50e8
jmp 0x17e7
jmp 0x17e9
movl $0x1, -0x4(%rbp)
jmp 0x1bfc
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x1870
movq -0x28(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x1840
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x40(%rbp), %rax
subq %rax, %rsi
movl -0x1c(%rbp), %edx
callq 0x1290
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x1bfc
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movslq -0x40(%rbp), %rax
subq %rax, %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x28(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
callq 0x1630
movl %eax, -0x4(%rbp)
jmp 0x1bfc
movq -0x18(%rbp), %rax
movslq -0x40(%rbp), %rcx
cmpq %rcx, %rax
jne 0x187f
jmp 0x189e
leaq 0x18ff(%rip), %rdi      # 0x3185
leaq 0x17b7(%rip), %rsi      # 0x3044
movl $0xa7, %edx
leaq 0x190a(%rip), %rcx      # 0x31a3
callq 0x1080
movq -0x28(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x18be
movl -0x1c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x1bfc
movl $0x0, -0x4(%rbp)
jmp 0x1bfc
movl $0x0, -0x60(%rbp)
movl $0x1, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x1967
movq -0x28(%rbp), %rdi
addq $0x18, %rdi
movslq -0x54(%rbp), %rax
addq %rax, %rdi
movq -0x28(%rbp), %rax
movl 0x8(%rax), %esi
subl -0x54(%rbp), %esi
movq -0x10(%rbp), %rdx
movslq -0x54(%rbp), %rax
addq %rax, %rdx
movq -0x18(%rbp), %rax
movslq -0x54(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
leaq -0x5c(%rbp), %r8
callq 0x1390
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x5c(%rbp)
jle 0x1929
jmp 0x1948
leaq 0x1926(%rip), %rdi      # 0x3256
leaq 0x170d(%rip), %rsi      # 0x3044
movl $0xb6, %edx
leaq 0x1860(%rip), %rcx      # 0x31a3
callq 0x1080
cmpl $0x0, -0x58(%rbp)
jne 0x1957
movl $0x1, -0x60(%rbp)
jmp 0x1967
jmp 0x1959
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x18d8
cmpl $0x0, -0x60(%rbp)
je 0x1b0f
movq -0x10(%rbp), %rdi
movslq -0x54(%rbp), %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movslq -0x54(%rbp), %rax
subq %rax, %rsi
xorl %edx, %edx
callq 0x1290
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
subl -0x54(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
subl -0x6c(%rbp), %eax
cmpl $0x0, %eax
jbe 0x19b0
jmp 0x19cf
leaq 0x18ab(%rip), %rdi      # 0x3262
leaq 0x1686(%rip), %rsi      # 0x3044
movl $0xc1, %edx
leaq 0x17d9(%rip), %rcx      # 0x31a3
callq 0x1080
movl -0x6c(%rbp), %edx
movq -0x28(%rbp), %rax
movl 0x8(%rax), %ecx
subl %edx, %ecx
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x10(%rax)
cmpq $0x0, -0x30(%rbp)
je 0x19f8
cmpq $0x0, -0x38(%rbp)
jne 0x19fa
jmp 0x1a19
leaq 0x1840(%rip), %rdi      # 0x3241
leaq 0x163c(%rip), %rsi      # 0x3044
movl $0xc4, %edx
leaq 0x178f(%rip), %rcx      # 0x31a3
callq 0x1080
movq -0x28(%rbp), %rax
cmpq 0x36c4(%rip), %rax      # 0x50e8
jne 0x1a4f
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x68(%rbp), %rax
movq %rax, 0x369e(%rip)      # 0x50e8
jmp 0x1aea
cmpq $0x0, -0x30(%rbp)
je 0x1a9e
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x28(%rbp), %rax
jne 0x1a66
jmp 0x1a85
leaq 0x17bb(%rip), %rdi      # 0x3228
leaq 0x15d0(%rip), %rsi      # 0x3044
movl $0xcb, %edx
leaq 0x1723(%rip), %rcx      # 0x31a3
callq 0x1080
movq -0x68(%rbp), %rax
movq $0x0, (%rax)
movq -0x68(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x1ae8
cmpq $0x0, -0x38(%rbp)
je 0x1acb
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x68(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x68(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
jmp 0x1ae6
cmpq $0x0, -0x30(%rbp)
jne 0x1ae4
cmpq $0x0, -0x38(%rbp)
jne 0x1ae4
movq -0x68(%rbp), %rax
movq %rax, 0x3604(%rip)      # 0x50e8
jmp 0x1ae6
jmp 0x1ae8
jmp 0x1aea
movq -0x10(%rbp), %rdi
movslq -0x54(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rcx
movq -0x68(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
callq 0x1630
movl %eax, -0x4(%rbp)
jmp 0x1bfc
cmpl $0x0, -0x3c(%rbp)
jge 0x1b72
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x1b4a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x1290
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movl $0x1, -0x4(%rbp)
jmp 0x1bfc
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x28(%rbp), %r9
xorl %eax, %eax
movl %eax, %r8d
callq 0x1630
movl %eax, -0x4(%rbp)
jmp 0x1bfc
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
callq 0x1290
movq %rax, -0x80(%rbp)
movq -0x28(%rbp), %rcx
movq -0x80(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
cmpq 0x354c(%rip), %rax      # 0x50e8
jne 0x1bab
movq -0x80(%rbp), %rax
movq %rax, 0x353f(%rip)      # 0x50e8
jmp 0x1bf1
cmpq $0x0, -0x30(%rbp)
je 0x1bce
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x28(%rbp), %rax
jne 0x1bce
movq -0x80(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x1bef
cmpq $0x0, -0x38(%rbp)
je 0x1bed
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpq -0x28(%rbp), %rax
jne 0x1bed
movq -0x80(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
jmp 0x1bef
jmp 0x1bf1
jmp 0x1bf3
jmp 0x1bf5
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)