// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
testq %rdi, %rdi
je 0x16e677
testq %rsi, %rsi
je 0x16e67c
movq (%rdi), %rbx
testq %rbx, %rbx
je 0x16e63f
movq %rsi, 0x20(%rsp)
movq %rdi, 0x18(%rsp)
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rax
movaps %xmm0, (%rax)
movq %rax, 0x10(%rsp)
movaps %xmm0, -0x10(%rax)
leaq 0x58(%rsp), %rdx
movq %rbx, (%rdx)
leaq 0x40(%rsp), %r13
movl $0x1, %eax
xorl %r14d, %r14d
movl $0x1, %ebp
xorl %r15d, %r15d
movq %rdx, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movq %r14, 0x28(%rsp)
movl %ebp, 0xc(%rsp)
movq %r13, %r14
movq 0x8(%rbx), %rdi
movq 0x18(%rsp), %r13
movq 0x20(%r13), %rdx
movq %r15, %rbp
movq 0x20(%rsp), %r15
movq %r15, %rsi
callq *0x8(%r13)
movl %eax, %r12d
shrl $0x1f, %eax
movq 0x8(%rbx), %rdi
movq 0x20(%r13), %rdx
movq %r15, %rsi
movq %rbp, %r15
movl %eax, %ebp
callq *0x8(%r13)
movq %rbx, %r13
testl %eax, %eax
cmoveq %rbx, %r15
cmpl $0x1, (%rbx)
movl %ebp, %eax
je 0x16e5c5
movq 0x10(%r13,%rax,8), %rcx
testq %rcx, %rcx
je 0x16e466
cmpl $0x1, (%rcx)
je 0x16e5c5
notl %r12d
shrl $0x1f, %r12d
movq 0x10(%r13,%r12,8), %rcx
testq %rcx, %rcx
je 0x16e4ba
cmpl $0x1, (%rcx)
jne 0x16e4ac
movq 0x10(%r13,%r12,8), %r14
movq 0x10(%r14,%rax,8), %rcx
movq %rcx, 0x10(%r13,%r12,8)
movq %r13, 0x10(%r14,%rax,8)
movl $0x1, (%r13)
movl $0x0, (%r14)
movq 0x30(%rsp), %rcx
movq %r14, (%rcx)
jmp 0x16e5c5
testq %rcx, %rcx
je 0x16e4ba
cmpl $0x1, (%rcx)
je 0x16e5c5
movl 0xc(%rsp), %ecx
xorl $0x1, %ecx
movq 0x10(%rsp), %rdx
movq (%rdx,%rcx,8), %rdi
testq %rdi, %rdi
je 0x16e5c5
movq 0x10(%rdi,%rcx,8), %rsi
testq %rsi, %rsi
movq 0x38(%rsp), %rbx
je 0x16e4e7
cmpl $0x1, (%rsi)
je 0x16e4f6
movq 0x10(%rdi,%rbx,8), %rdx
testq %rdx, %rdx
je 0x16e54e
cmpl $0x1, (%rdx)
jne 0x16e54e
movq 0x28(%rsp), %r11
testq %r11, %r11
je 0x16e672
movq 0x18(%r11), %rdx
movq 0x10(%rdi,%rbx,8), %rdi
testq %rdi, %rdi
je 0x16e562
cmpl $0x1, (%rdi)
jne 0x16e562
movq 0x10(%rsp), %rsi
leaq (%rsi,%rcx,8), %rdi
movq (%rdi), %r8
movl 0xc(%rsp), %r9d
movq 0x10(%r8,%r9,8), %rsi
movq 0x10(%rsi,%rcx,8), %r10
movq %r10, 0x10(%r8,%r9,8)
movq %r8, 0x10(%rsi,%rcx,8)
movl $0x1, (%r8)
movl $0x0, (%rsi)
movq %rsi, (%rdi)
jmp 0x16e578
movl $0x0, (%r14)
movl $0x1, %ecx
movl %ecx, (%rdi)
movl %ecx, (%r13)
jmp 0x16e5c5
testq %rsi, %rsi
je 0x16e59f
cmpl $0x1, (%rsi)
jne 0x16e59f
movq 0x10(%rsp), %rsi
leaq (%rsi,%rcx,8), %rdi
movq (%rdi), %rsi
xorl %ecx, %ecx
cmpq %r14, %rdx
sete %cl
movq 0x10(%rsi,%rbx,8), %r8
movq %r8, (%rdi)
movq %r14, 0x10(%rsi,%rbx,8)
movl $0x1, (%r14)
movl $0x0, (%rsi)
movq %rsi, 0x10(%r11,%rcx,8)
xorl %ecx, %ecx
cmpq %r14, %rdx
sete %cl
movq 0x10(%r11,%rcx,8), %rcx
movl $0x1, %edx
movl %edx, (%rcx)
movl %edx, (%r13)
movq 0x10(%rcx), %rdx
xorl %esi, %esi
movl %esi, (%rdx)
movq 0x18(%rcx), %rcx
movl %esi, (%rcx)
leaq 0x10(%r13), %rcx
movq %rcx, 0x10(%rsp)
leaq 0x10(,%rax,8), %rdx
addq %r13, %rdx
movq (%rdx), %rbx
testq %rbx, %rbx
jne 0x16e3f3
testq %r15, %r15
je 0x16e646
movq 0x18(%rsp), %rbx
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x16e5fe
movq 0x8(%r15), %rdi
callq *%rax
movq 0x8(%r13), %rax
movq %rax, 0x8(%r15)
xorl %eax, %eax
cmpq $0x0, 0x10(%r13)
sete %al
movq 0x10(%r13,%rax,8), %rax
xorl %ecx, %ecx
cmpq %r13, 0x18(%r14)
sete %cl
movq %rax, 0x10(%r14,%rcx,8)
leaq 0x229276(%rip), %rsi    # 0x3978a0
movq %r13, %rdi
movl $0x18e, %edx            # imm = 0x18E
callq 0x109670
decq 0x18(%rbx)
xorl %eax, %eax
jmp 0x16e650
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x16e663
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rbx
movq 0x58(%rsp), %rcx
movq %rcx, (%rbx)
testq %rcx, %rcx
je 0x16e663
movl $0x0, (%rcx)
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4ffb7
callq 0x50029
callq 0x4fff0