// File: /workspace/github_c_makefile_star2_O1/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, %r15
movq %rsi, %r12
movq %rdi, %r14
movb $0x0, (%rdx)
movq (%rdi), %rbx
testq %rbx, %rbx
je 0x16e28a
movq %r12, 0x10(%rsp)
movq %r15, 0x8(%rsp)
movq %r14, 0x18(%rsp)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rbp
movaps %xmm0, 0x10(%rbp)
movaps %xmm0, (%rbp)
movq %rbx, 0x18(%rbp)
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %r15d, %r15d
xorl %r12d, %r12d
testq %rbx, %rbx
je 0x16e138
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x16e180
cmpl $0x1, (%rax)
jne 0x16e180
movq 0x18(%rbx), %rcx
testq %rcx, %rcx
je 0x16e180
cmpl $0x1, (%rcx)
jne 0x16e180
movl $0x1, (%rbx)
xorl %edx, %edx
movl %edx, (%rax)
movl %edx, (%rcx)
jmp 0x16e180
testq %r14, %r14
je 0x16e2da
movl $0x20, %edi
leaq 0x229753(%rip), %rsi    # 0x3978a0
movl $0x72, %edx
callq 0x1092b2
movq %rax, %rbx
movl $0x1, (%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movl %r13d, %eax
movq %rbx, 0x10(%r14,%rax,8)
movq 0x8(%rsp), %rax
movb $0x1, (%rax)
cmpl $0x1, (%rbx)
sete %al
testq %r14, %r14
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x16e233
cmpl $0x1, (%r14)
jne 0x16e233
movq 0x18(%rbp), %rax
movl %r15d, %r8d
xorl %edx, %edx
xorl %ecx, %ecx
testl %r15d, %r15d
sete %dl
setne %cl
movq 0x10(%r12,%rcx,8), %rdi
leaq (%rdi,%rdx,8), %rsi
addq $0x10, %rsi
movq (%rsi), %rdx
cmpq 0x10(%r14,%r8,8), %rbx
je 0x16e209
xorl %r8d, %r8d
testl %r15d, %r15d
sete %r8b
leal (,%rcx,8), %r9d
movq 0x10(%rdx,%r9), %r10
movq %r10, (%rsi)
movq %rdi, 0x10(%rdx,%r9)
movl $0x1, (%rdi)
movl $0x0, (%rdx)
movq %rdx, 0x10(%r12,%r9)
leaq (%rdx,%r8,8), %rsi
addq $0x10, %rsi
movq (%rsi), %r8
jmp 0x16e20f
movq %rdx, %r8
movq %rdi, %rdx
xorl %edi, %edi
cmpq %r12, %rax
sete %dil
movq %r8, 0x10(%r12,%rcx,8)
movq %r12, (%rsi)
movl $0x1, (%r12)
movl $0x0, (%rdx)
movq %rdx, 0x10(%rbp,%rdi,8)
movq 0x8(%rbx), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rdx
callq *0x20(%rsp)
testl %eax, %eax
je 0x16e268
movl %eax, %ecx
shrl $0x1f, %ecx
testq %r12, %r12
cmovneq %r12, %rbp
movq 0x10(%rbx,%rcx,8), %rdx
movq %r14, %r12
movq %rbx, %r14
movq %rdx, %rbx
movl %r13d, %r15d
jmp 0x16e26b
movl %r13d, %ecx
movl %ecx, %r13d
testl %eax, %eax
jne 0x16e109
movq 0x48(%rsp), %rax
movq 0x18(%rsp), %r14
movq %rax, (%r14)
movq 0x8(%rsp), %r15
jmp 0x16e2b8
leaq 0x22960f(%rip), %rsi    # 0x3978a0
movl $0x20, %edi
movl $0x72, %edx
callq 0x1092b2
movl $0x1, (%rax)
movq %r12, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq %rax, (%r14)
movb $0x1, (%r15)
movq (%r14), %rax
movl $0x0, (%rax)
cmpb $0x1, (%r15)
jne 0x16e2cb
incq 0x18(%r14)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4fd44