// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/rbtree.c
// Function: gt_rbtree_erase
int gt_rbtree_erase(GtRBTree *tree, void *key)
{
  int rv = -1;
  gt_assert(tree);
  gt_assert(key);
  if (tree->root != NULL) {
    GtRBTreeNode head = {0,0,{NULL, NULL}}; /* False tree root */
    GtRBTreeNode *q, *p, *g; /* Helpers */
    GtRBTreeNode *f = NULL;  /* Found item */
    int dir = 1;

    /* Set up our helpers */
    q = &head;
    p = NULL;
    q->link[1] = tree->root;

    /* Search and push a red node down to fix red violations as we go */
    while (q->link[dir] != NULL) {
      int last = dir;

      /* Move the helpers down */
      g = p, p = q;
      q = q->link[dir];
      dir = (int) (tree->cmp(q->key, key, tree->info) < 0);

      /* Save the node with matching key and keep going; we'll do removal
         tasks at the end */
      if (tree->cmp(q->key, key, tree->info) == 0)
        f = q;

      /* Push the red node down with rotations and color flips */
      if (!GT_RBTREE_NODE_IS_RED(q)
            && !GT_RBTREE_NODE_IS_RED(q->link[dir])) {
        if (GT_RBTREE_NODE_IS_RED(q->link[(int) !dir])) {
          p = p->link[last] = gt_rbtree_single(q, dir);
        } else if (!GT_RBTREE_NODE_IS_RED(q->link[(int) !dir])) {
          GtRBTreeNode *s = p->link[(int) !last];

          if (s != NULL) {
            if (!GT_RBTREE_NODE_IS_RED(s->link[(int) !last])
                  && !GT_RBTREE_NODE_IS_RED(s->link[last])) {
              /* Color flip */
              p->red = 0;
              s->red = 1;
              q->red = 1;
            } else {
              int dir2;
              gt_assert(g != NULL);
              dir2 = (int) (g->link[1] == p);

              if (GT_RBTREE_NODE_IS_RED(s->link[last]))
                g->link[dir2] = gt_rbtree_double(p, last);
              else if (GT_RBTREE_NODE_IS_RED(s->link[(int) !last]))
                g->link[dir2] = gt_rbtree_single(p, last);

              /* Ensure correct coloring */
              q->red = g->link[dir2]->red = 1;
              g->link[dir2]->link[0]->red = 0;
              g->link[dir2]->link[1]->red = 0;
            }
          }
        }
      }
    }

    /* Replace and remove the saved node */
    if (f != NULL) {
      if (tree->free != NULL)
        tree->free(f->key);
      f->key = q->key;
      gt_assert(p);
      p->link[(int) (p->link[1] == q)] = q->link[(int) (q->link[0] == NULL)];
      gt_free(q);
      rv = 0;
      --tree->size;
    }

    /* Update the root (it may be different) */
    tree->root = head.link[1];

    /* Make the root black for simplified logic */
    if (tree->root != NULL)
      tree->root->red = 0;
  }

  return rv;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
testq %rdi, %rdi
je 0x1666f3
testq %rsi, %rsi
je 0x1666f8
movq %rdi, %rbx
movq (%rdi), %r15
testq %r15, %r15
je 0x1666c0
movq %rsi, 0x10(%rsp)
xorps %xmm0, %xmm0
leaq 0x48(%rsp), %rdx
movaps %xmm0, -0x18(%rdx)
movq $0x0, -0x8(%rdx)
movq %r15, (%rdx)
leaq 0x30(%rsp), %r11
movl $0x1, %eax
xorl %r13d, %r13d
movl $0x1, %ebp
xorl %r12d, %r12d
movq %rdx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
movq %r13, 0x18(%rsp)
movl %ebp, 0x4(%rsp)
movq %r11, 0x8(%rsp)
movq 0x8(%r15), %rdi
movq 0x20(%rbx), %rdx
movq %r12, %r13
movq 0x10(%rsp), %r12
movq %r12, %rsi
callq *0x8(%rbx)
movl %eax, %r14d
movl %eax, %ebp
shrl $0x1f, %ebp
movq 0x8(%r15), %rdi
movq 0x20(%rbx), %rdx
movq %r12, %rsi
movq %r13, %r12
callq *0x8(%rbx)
movq %r15, %r11
testl %eax, %eax
cmoveq %r15, %r12
cmpl $0x1, (%r15)
movl %ebp, %eax
jne 0x1664f4
movq 0x8(%rsp), %r13
jmp 0x16664f
movq 0x8(%rsp), %r13
movq 0x10(%r11,%rax,8), %rcx
testq %rcx, %rcx
je 0x16650c
cmpl $0x1, (%rcx)
je 0x16664f
xorl %ecx, %ecx
testl %r14d, %r14d
setns %cl
movq 0x10(%r11,%rcx,8), %rdx
testq %rdx, %rdx
je 0x16654f
cmpl $0x1, (%rdx)
jne 0x16654f
movq 0x10(%rdx,%rax,8), %rsi
movq %rsi, 0x10(%r11,%rcx,8)
movq %r11, 0x10(%rdx,%rax,8)
movl $0x1, (%r11)
movl $0x0, (%rdx)
movq 0x20(%rsp), %rcx
movq %rdx, (%rcx)
movq %rdx, %r13
jmp 0x16664f
movl 0x4(%rsp), %r15d
movl %r15d, %edx
xorl $0x1, %edx
movq 0x10(%r13,%rdx,8), %rcx
testq %rcx, %rcx
je 0x16664f
leaq 0x10(%rcx), %rdi
movq 0x10(%rcx,%rdx,8), %r8
testq %r8, %r8
movq 0x28(%rsp), %r14
je 0x166581
cmpl $0x1, (%r8)
je 0x16658f
movq (%rdi,%r14,8), %rsi
testq %rsi, %rsi
je 0x1665e2
cmpl $0x1, (%rsi)
jne 0x1665e2
movq 0x18(%rsp), %r10
testq %r10, %r10
je 0x1666ee
movq 0x18(%r10), %rsi
movq (%rdi,%r14,8), %r9
testq %r9, %r9
je 0x1665f6
cmpl $0x1, (%r9)
jne 0x1665f6
movl %r15d, %edi
movq 0x10(%rcx,%rdi,8), %r8
movq 0x10(%r8,%rdx,8), %r9
movq %r9, 0x10(%rcx,%rdi,8)
movq %rcx, 0x10(%r8,%rdx,8)
movl $0x1, (%rcx)
movq %r8, 0x10(%r13,%rdx,8)
leaq (%r8,%r14,8), %rdi
addq $0x10, %rdi
movq (%rdi), %r9
movq %r8, %rcx
jmp 0x166605
movl $0x0, (%r13)
movl $0x1, %edx
movl %edx, (%rcx)
movl %edx, (%r11)
jmp 0x16664f
testq %r8, %r8
je 0x16662a
cmpl $0x1, (%r8)
jne 0x16662a
leaq (%rdi,%r14,8), %rdi
xorl %r8d, %r8d
cmpq %r13, %rsi
sete %r8b
movq %r9, 0x10(%r13,%rdx,8)
movq %r13, (%rdi)
movl $0x1, (%r13)
movl $0x0, (%rcx)
movq %rcx, 0x10(%r10,%r8,8)
xorl %ecx, %ecx
cmpq %r13, %rsi
sete %cl
movq 0x10(%r10,%rcx,8), %rcx
movl $0x1, %edx
movl %edx, (%rcx)
movl %edx, (%r11)
movq 0x10(%rcx), %rdx
xorl %esi, %esi
movl %esi, (%rdx)
movq 0x18(%rcx), %rcx
movl %esi, (%rcx)
leaq (%r11,%rax,8), %rdx
addq $0x10, %rdx
movq (%rdx), %r15
testq %r15, %r15
jne 0x166492
testq %r12, %r12
je 0x1666c7
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x16667e
movq 0x8(%r12), %rdi
movq %r11, %r14
callq *%rax
movq %r14, %r11
movq 0x8(%r11), %rax
movq %rax, 0x8(%r12)
xorl %eax, %eax
cmpq $0x0, 0x10(%r11)
sete %al
movq 0x10(%r11,%rax,8), %rax
xorl %ecx, %ecx
cmpq %r11, 0x18(%r13)
sete %cl
movq %rax, 0x10(%r13,%rcx,8)
leaq 0x227e15(%rip), %rsi    # 0x38e4c0
movq %r11, %rdi
movl $0x18e, %edx            # imm = 0x18E
callq 0x1045eb
decq 0x18(%rbx)
xorl %eax, %eax
jmp 0x1666cc
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x1666df
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x48(%rsp), %rcx
movq %rcx, (%rbx)
testq %rcx, %rcx
je 0x1666df
movl $0x0, (%rcx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4f0c2
callq 0x4f134
callq 0x4f0fb