// File: /workspace/github_c_makefile_star2_O3/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 0x16633f
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rbp
movaps %xmm0, (%rbp)
movq $0x0, 0x10(%rbp)
movq %rbx, 0x18(%rbp)
xorl %ecx, %ecx
xorl %eax, %eax
xorl %r12d, %r12d
xorl %r13d, %r13d
movl %eax, %r15d
movq %rcx, %r14
testq %rbx, %rbx
je 0x1661fb
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x166245
cmpl $0x1, (%rax)
movq 0x8(%rsp), %rsi
jne 0x16624a
movq 0x18(%rbx), %rcx
testq %rcx, %rcx
je 0x16624a
cmpl $0x1, (%rcx)
jne 0x16624a
movl $0x1, (%rbx)
xorl %edx, %edx
movl %edx, (%rax)
movl %edx, (%rcx)
jmp 0x16624a
testq %r14, %r14
je 0x166380
movl $0x20, %edi
leaq 0x2282b0(%rip), %rsi    # 0x38e4c0
movl $0x72, %edx
callq 0x104226
movq %rax, %rbx
movl $0x1, (%rax)
movq 0x8(%rsp), %rsi
movq %rsi, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movl %r15d, %eax
movq %rbx, 0x10(%r14,%rax,8)
movq 0x10(%rsp), %rax
movb $0x1, (%rax)
jmp 0x16624a
movq 0x8(%rsp), %rsi
testq %r14, %r14
je 0x1662f2
cmpl $0x1, (%rbx)
jne 0x1662f2
cmpl $0x1, (%r14)
jne 0x1662f2
movq 0x18(%rbp), %rax
movl %r12d, %r8d
xorl %r10d, %r10d
xorl %ecx, %ecx
testl %r12d, %r12d
sete %r10b
setne %cl
movq 0x10(%r13,%rcx,8), %rdx
movq 0x10(%rdx,%r10,8), %rdi
cmpq 0x10(%r14,%r8,8), %rbx
je 0x1662c3
leal (,%rcx,8), %r8d
movq 0x10(%rdi,%r8), %r9
shll $0x3, %r10d
movq %r9, 0x10(%rdx,%r10)
movq %rdx, 0x10(%rdi,%r8)
movl $0x1, (%rdx)
movq %rdi, 0x10(%r13,%r8)
leaq (%rdi,%r10), %r9
addq $0x10, %r9
movq (%r9), %r8
movq %rdi, %rdx
jmp 0x1662ce
leaq (%rdx,%r10,8), %r9
addq $0x10, %r9
movq %rdi, %r8
xorl %edi, %edi
cmpq %r13, %rax
sete %dil
movq %r8, 0x10(%r13,%rcx,8)
movq %r13, (%r9)
movl $0x1, (%r13)
movl $0x0, (%rdx)
movq %rdx, 0x10(%rbp,%rdi,8)
movq 0x8(%rbx), %rdi
movq 0x28(%rsp), %rdx
callq *0x20(%rsp)
testl %eax, %eax
je 0x166320
shrl $0x1f, %eax
testq %r13, %r13
cmovneq %r13, %rbp
movq %rbx, %rcx
movq 0x10(%rbx,%rax,8), %rbx
movl %r15d, %r12d
movq %r14, %r13
jmp 0x1661c1
movq 0x48(%rsp), %rax
movq 0x18(%rsp), %r14
movq %rax, (%r14)
movq 0x10(%rsp), %rcx
testb $0x1, (%rcx)
movl $0x0, (%rax)
jne 0x16636d
jmp 0x166371
leaq 0x22817a(%rip), %rsi    # 0x38e4c0
movl $0x20, %edi
movl $0x72, %edx
callq 0x104226
movq %r12, 0x8(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movq %rax, (%r14)
movb $0x1, (%r15)
movl $0x0, (%rax)
incq 0x18(%r14)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4ee4f