// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/rbtree.c
// Function: gt_rbtree_insert_g
static inline void gt_rbtree_insert_g(GtRBTree *tree, void *key,
                                      bool *nodecreated,
                                      GtCompareWithData cmpfunc,
                                      void *info)
{
  *nodecreated = false;
  if (tree->root == NULL) {
    /* We have an empty tree; attach the new node directly to the root */
    tree->root = gt_rbtree_new_node(key);
    *nodecreated = true;

  } else {
    GtRBTreeNode head = {0,0,{NULL, NULL}}; /* False tree root */
    GtRBTreeNode *g, *t;     /* Grandparent & parent */
    GtRBTreeNode *p, *q;     /* Iterator & parent */
    int dir = 0, last = 0;

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

    /* Search down the tree for a place to insert */
    while (true) {
      int cmp;
      if (q == NULL) {
        /* Insert a new node at the first null link */
        gt_assert(p != NULL);
        p->link[dir] = q = gt_rbtree_new_node(key);
        *nodecreated = true;

      } else if (GT_RBTREE_NODE_IS_RED(q->link[0] )
                 && GT_RBTREE_NODE_IS_RED(q->link[1])) {
        /* Simple red violation: color flip */
        q->red = 1;
        q->link[0]->red = 0;
        q->link[1]->red = 0;
      }

      if ( GT_RBTREE_NODE_IS_RED(q) && GT_RBTREE_NODE_IS_RED(p)) {
        /* Hard red violation: rotations necessary */
        int dir2 = (int) (t->link[1] == g);

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

      cmp = cmpfunc(q->key, key, info);

      /* Stop working if we inserted a node. This check also disallows
         duplicates in the tree */
      if (cmp == 0)
        break;

      last = dir;
      dir = (int) (cmp < 0);

      /* Move the helpers down */
      if (g != NULL)
        t = g;

      g = p;
      p = q;
      q = q->link[dir];
    }

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

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, 0x28(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, %r14
movq %rdi, %rbx
movb $0x0, (%rdx)
movq (%rdi), %rbp
testq %rbp, %rbp
je 0x106a1c
movq %rsi, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %r14
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
movq %rbp, 0x18(%r14)
xorl %ecx, %ecx
xorl %eax, %eax
xorl %r12d, %r12d
xorl %r15d, %r15d
movl %eax, %r13d
movq %rcx, %rbx
testq %rbp, %rbp
je 0x10692d
movq 0x10(%rbp), %rax
testq %rax, %rax
je 0x106958
cmpl $0x1, (%rax)
jne 0x106958
movq 0x18(%rbp), %rcx
testq %rcx, %rcx
je 0x106958
cmpl $0x1, (%rcx)
jne 0x106958
movl $0x1, (%rbp)
andl $0x0, (%rax)
andl $0x0, (%rcx)
jmp 0x106958
testq %rbx, %rbx
je 0x106a41
movq 0x8(%rsp), %rdi
callq 0x108e10
movq %rax, %rbp
movl %r13d, %eax
movq %rbp, 0x10(%rbx,%rax,8)
movq 0x10(%rsp), %rax
movb $0x1, (%rax)
testq %rbp, %rbp
je 0x10698f
testq %rbx, %rbx
je 0x1069cb
cmpl $0x1, (%rbp)
jne 0x1069cb
cmpl $0x1, (%rbx)
jne 0x1069cb
movq 0x18(%r14), %rdi
movl %r12d, %eax
cmpq 0x10(%rbx,%rax,8), %rbp
je 0x106993
xorl %esi, %esi
testl %r12d, %r12d
sete %sil
movq %rdi, %r12
movq %r15, %rdi
callq 0x107038
movq %r12, %rdi
jmp 0x1069be
xorl %ebp, %ebp
jmp 0x1069cb
xorl %ecx, %ecx
xorl %edx, %edx
testl %r12d, %r12d
sete %cl
setne %dl
movq 0x10(%r15,%rdx,8), %rax
movq 0x10(%rax,%rcx,8), %rsi
movq %rsi, 0x10(%r15,%rdx,8)
movq %r15, 0x10(%rax,%rcx,8)
movl $0x1, (%r15)
andl $0x0, (%rax)
xorl %ecx, %ecx
cmpq %r15, %rdi
sete %cl
movq %rax, 0x10(%r14,%rcx,8)
movq 0x8(%rsp), %rsi
movq 0x8(%rbp), %rdi
movq 0x28(%rsp), %rdx
callq *0x20(%rsp)
testl %eax, %eax
je 0x1069fe
shrl $0x1f, %eax
testq %r15, %r15
cmovneq %r15, %r14
movq %rbp, %rcx
movq 0x10(%rbp,%rax,8), %rbp
movl %r13d, %r12d
movq %rbx, %r15
jmp 0x1068f7
movq 0x48(%rsp), %rax
movq 0x18(%rsp), %rbx
movq %rax, (%rbx)
movq 0x10(%rsp), %rcx
movb (%rcx), %cl
andl $0x0, (%rax)
testb $0x1, %cl
jne 0x106a2e
jmp 0x106a32
movq %rsi, %rdi
callq 0x108e10
movq %rax, (%rbx)
movb $0x1, (%r14)
andl $0x0, (%rax)
incq 0x18(%rbx)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x331520(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1de5c1(%rip), %rsi    # 0x2e5013
leaq 0x215dcc(%rip), %rdx    # 0x31c825
leaq 0x22846c(%rip), %rcx    # 0x32eecc
leaq 0x227e59(%rip), %r8     # 0x32e8c0
movl $0xec, %r9d
xorl %eax, %eax
callq 0x17a50
callq 0x17390