// File: /workspace/github_c_makefile_star2_O2/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 0x106fa4
testq %rsi, %rsi
je 0x106fd2
movq (%rdi), %rax
testq %rax, %rax
je 0x106f47
movq %rsi, 0x20(%rsp)
movq %rdi, 0x10(%rsp)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %r15
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
movq %rax, 0x18(%r15)
pushq $0x1
popq %rdi
xorl %r13d, %r13d
xorl %edx, %edx
movq %r15, %r14
movq %rdx, %r12
movl %edi, %eax
movq %rax, 0x8(%rsp)
movq 0x10(%r15,%rax,8), %r15
testq %r15, %r15
je 0x106ee3
movq %r12, 0x28(%rsp)
movq 0x8(%r15), %rdi
movq %r14, %r12
movq %r13, %r14
movq 0x10(%rsp), %r13
movq 0x20(%r13), %rdx
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
callq *0x8(%r13)
movl %eax, %ebp
movl %eax, 0x1c(%rsp)
shrl $0x1f, %ebp
movq 0x8(%r15), %rdi
movq 0x20(%r13), %rdx
movq %rbx, %rsi
callq *0x8(%r13)
movl %ebp, %edi
movq %r14, %r13
testl %eax, %eax
cmoveq %r15, %r13
cmpl $0x1, (%r15)
movq %r12, %rdx
je 0x106d38
movq %r12, %rbx
movl %edi, %eax
movq 0x10(%r15,%rax,8), %rcx
testq %rcx, %rcx
je 0x106dbe
cmpl $0x1, (%rcx)
movq %rbx, %rdx
je 0x106d38
xorl %ecx, %ecx
cmpl $0x0, 0x1c(%rsp)
setns %cl
movq 0x10(%r15,%rcx,8), %rdx
testq %rdx, %rdx
je 0x106dff
cmpl $0x1, (%rdx)
jne 0x106dff
movq 0x10(%rdx,%rax,8), %rsi
movq %rsi, 0x10(%r15,%rcx,8)
movq %r15, 0x10(%rdx,%rax,8)
movl $0x1, (%r15)
andl $0x0, (%rdx)
movq 0x8(%rsp), %rax
movq %rdx, 0x10(%rbx,%rax,8)
jmp 0x106d38
movq 0x8(%rsp), %rcx
xorl $0x1, %ecx
movq 0x10(%rbx,%rcx,8), %rax
movq %rbx, %rdx
testq %rax, %rax
je 0x106d38
movq 0x10(%rax,%rcx,8), %rdx
testq %rdx, %rdx
je 0x106e27
cmpl $0x1, (%rdx)
je 0x106e3b
movq 0x8(%rsp), %rsi
movq 0x10(%rax,%rsi,8), %rsi
testq %rsi, %rsi
je 0x106e76
cmpl $0x1, (%rsi)
jne 0x106e76
movq 0x28(%rsp), %r14
testq %r14, %r14
je 0x106f73
movq 0x18(%r14), %rbp
movq 0x8(%rsp), %rsi
movq 0x10(%rax,%rsi,8), %rsi
testq %rsi, %rsi
je 0x106e89
cmpl $0x1, (%rsi)
jne 0x106e89
movl %edi, %r12d
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
callq 0x107038
movl %r12d, %edi
jmp 0x106eab
andl $0x0, (%rbx)
pushq $0x1
popq %rcx
movl %ecx, (%rax)
movl %ecx, (%r15)
movq %rbx, %rdx
jmp 0x106d38
testq %rdx, %rdx
je 0x106eb8
cmpl $0x1, (%rdx)
jne 0x106eb8
movq %rsi, 0x10(%rbx,%rcx,8)
movq 0x8(%rsp), %rcx
movq %rbx, 0x10(%rax,%rcx,8)
movl $0x1, (%rbx)
andl $0x0, (%rax)
xorl %ecx, %ecx
cmpq %rbx, %rbp
sete %cl
movq %rax, 0x10(%r14,%rcx,8)
xorl %eax, %eax
cmpq %rbx, %rbp
sete %al
movq 0x10(%r14,%rax,8), %rax
pushq $0x1
popq %rcx
movl %ecx, (%rax)
movl %ecx, (%r15)
movq 0x10(%rax), %rcx
andl $0x0, (%rcx)
movq 0x18(%rax), %rax
andl $0x0, (%rax)
movq %rbx, %rdx
jmp 0x106d38
testq %r13, %r13
je 0x106f4c
movq 0x10(%rsp), %rbx
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x106efc
movq 0x8(%r13), %rdi
callq *%rax
movq 0x8(%r14), %rax
movq %rax, 0x8(%r13)
testq %r12, %r12
je 0x107000
xorl %eax, %eax
cmpq $0x0, 0x10(%r14)
sete %al
movq 0x10(%r14,%rax,8), %rax
xorl %ecx, %ecx
cmpq %r14, 0x18(%r12)
sete %cl
movq %rax, 0x10(%r12,%rcx,8)
leaq 0x22798e(%rip), %rsi    # 0x32e8c0
movq %r14, %rdi
movl $0x18e, %edx            # imm = 0x18E
callq 0x936f9
decq 0x18(%rbx)
xorl %eax, %eax
jmp 0x106f54
pushq $-0x1
popq %rax
jmp 0x106f64
pushq $-0x1
popq %rax
movq 0x10(%rsp), %rbx
movq 0x48(%rsp), %rcx
movq %rcx, (%rbx)
testq %rcx, %rcx
je 0x106f64
andl $0x0, (%rcx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x330fee(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1de08f(%rip), %rsi    # 0x2e5013
leaq 0x24cc78(%rip), %rdx    # 0x353c03
leaq 0x2279d7(%rip), %rcx    # 0x32e969
leaq 0x227927(%rip), %r8     # 0x32e8c0
movl $0x175, %r9d            # imm = 0x175
jmp 0x10702c
movq 0x330fbd(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1de05e(%rip), %rsi    # 0x2e5013
leaq 0x27ecac(%rip), %rdx    # 0x385c68
leaq 0x2279a6(%rip), %rcx    # 0x32e969
leaq 0x2278f6(%rip), %r8     # 0x32e8c0
movl $0x149, %r9d            # imm = 0x149
jmp 0x10702c
movq 0x330f8f(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1de030(%rip), %rsi    # 0x2e5013
leaq 0x20b26a(%rip), %rdx    # 0x312254
leaq 0x227978(%rip), %rcx    # 0x32e969
leaq 0x2278c8(%rip), %r8     # 0x32e8c0
movl $0x14a, %r9d            # imm = 0x14A
jmp 0x10702c
movq 0x330f61(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1de002(%rip), %rsi    # 0x2e5013
leaq 0x22eb16(%rip), %rdx    # 0x335b2e
leaq 0x22794a(%rip), %rcx    # 0x32e969
leaq 0x22789a(%rip), %r8     # 0x32e8c0
movl $0x18c, %r9d            # imm = 0x18C
xorl %eax, %eax
callq 0x17a50
callq 0x17390