// File: /workspace/github_c_makefile_star2_O0/stevenmherring[P]DNS/sequential-trie.c
// Function: delete
struct trie_node *
        _delete (struct trie_node *node, const char *string,
          size_t strlen) {
            int keylen, cmp;

            // First things first, check if we are NULL
            if (node == NULL) return NULL;

            assert(node->strlen < 64);

            // See if this key is a substring of the string passed in
            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, the key isn't here
              if (node->strlen > keylen) {
                return NULL;
              } else if (strlen > keylen) {
                struct trie_node *found =  _delete(node->children, string, strlen - keylen);
                if (found) {
                  /* If the node doesn't have children, delete it.
                  * Otherwise, keep it around to find the kids */
                  if (found->children == NULL && found->ip4_address == 0) {
                    assert(node->children == found);
                    node->children = found->next;
                    free(found);
                  }

                  /* Delete the root node if we empty the tree */
                  if (node == root && node->children == NULL && node->ip4_address == 0) {
                    root = node->next;
                    free(node);
                  }

                  return node; /* Recursively delete needless interior nodes */
                } else
                return NULL;
              } else {
                assert (strlen == keylen);

                /* We found it! Clear the ip4 address and return. */
                if (node->ip4_address) {
                  node->ip4_address = 0;

                  /* Delete the root node if we empty the tree */
                  if (node == root && node->children == NULL && node->ip4_address == 0) {
                    root = node->next;
                    free(node);
                    return (struct trie_node *) 0x100100; /* XXX: Don't use this pointer for anything except
                    * comparison with NULL, since the memory is freed.
                    * Return a "poison" pointer that will probably
                    * segfault if used.
                    */
                  }
                  return node;
                } else {
                  /* Just an interior node with no value */
                  return NULL;
                }
              }

            } else if (cmp < 0) {
              // No, look right (the node's key is "less" than  the search key)
              struct trie_node *found = _delete(node->next, string, strlen);
              if (found) {
                /* If the node doesn't have children, delete it.
                * Otherwise, keep it around to find the kids */
                if (found->children == NULL && found->ip4_address == 0) {
                  assert(node->next == found);
                  node->next = found->next;
                  free(found);
                }

                return node; /* Recursively delete needless interior nodes */
              }
              return NULL;
            } else {
              // Quit early
              return NULL;
            }

          }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x1d08
movq $0x0, -0x8(%rbp)
jmp 0x1fa9
movq -0x10(%rbp), %rax
cmpl $0x40, 0x8(%rax)
jae 0x1d14
jmp 0x1d33
leaq 0x1414(%rip), %rdi      # 0x312f
leaq 0x1322(%rip), %rsi      # 0x3044
movl $0x113, %edx            # imm = 0x113
leaq 0x157a(%rip), %rcx      # 0x32a8
callq 0x1080
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x10(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rax
movl %eax, %ecx
leaq -0x24(%rbp), %r8
callq 0x1390
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x1f0a
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x24(%rbp), %eax
jbe 0x1d7b
movq $0x0, -0x8(%rbp)
jmp 0x1fa9
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x1e66
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movslq -0x24(%rbp), %rax
subq %rax, %rdx
callq 0x1ce0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1e59
movq -0x30(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x1e13
movq -0x30(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x1e13
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
cmpq -0x30(%rbp), %rax
jne 0x1ddc
jmp 0x1dfb
leaq 0x1509(%rip), %rdi      # 0x32ec
leaq 0x125a(%rip), %rsi      # 0x3044
movl $0x123, %edx            # imm = 0x123
leaq 0x14b2(%rip), %rcx      # 0x32a8
callq 0x1080
movq -0x30(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rdi
callq 0x1030
movq -0x10(%rbp), %rax
cmpq 0x32ca(%rip), %rax      # 0x50e8
jne 0x1e4c
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x1e4c
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x1e4c
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x32a5(%rip)      # 0x50e8
movq -0x10(%rbp), %rdi
callq 0x1030
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1fa9
movq $0x0, -0x8(%rbp)
jmp 0x1fa9
movq -0x20(%rbp), %rax
movslq -0x24(%rbp), %rcx
cmpq %rcx, %rax
jne 0x1e75
jmp 0x1e94
leaq 0x1309(%rip), %rdi      # 0x3185
leaq 0x11c1(%rip), %rsi      # 0x3044
movl $0x132, %edx            # imm = 0x132
leaq 0x1419(%rip), %rcx      # 0x32a8
callq 0x1080
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x1efd
movq -0x10(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x10(%rbp), %rax
cmpq 0x3234(%rip), %rax      # 0x50e8
jne 0x1ef0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x1ef0
movq -0x10(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x1ef0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x320f(%rip)      # 0x50e8
movq -0x10(%rbp), %rdi
callq 0x1030
movl $0x100100, %eax         # imm = 0x100100
movq %rax, -0x8(%rbp)
jmp 0x1fa9
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1fa9
movq $0x0, -0x8(%rbp)
jmp 0x1fa9
cmpl $0x0, -0x28(%rbp)
jge 0x1fa1
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x1ce0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x1f97
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x1f8d
movq -0x38(%rbp), %rax
cmpl $0x0, 0xc(%rax)
jne 0x1f8d
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq -0x38(%rbp), %rax
jne 0x1f57
jmp 0x1f76
leaq 0x13a6(%rip), %rdi      # 0x3304
leaq 0x10df(%rip), %rsi      # 0x3044
movl $0x150, %edx            # imm = 0x150
leaq 0x1337(%rip), %rcx      # 0x32a8
callq 0x1080
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rdi
callq 0x1030
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x1fa9
movq $0x0, -0x8(%rbp)
jmp 0x1fa9
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)