// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdx, 0x60(%rsp)
movq %rcx, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movq 0x60(%rsp), %rax
movb $0x0, (%rax)
movq 0x70(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x1b83e2
movq 0x68(%rsp), %rdi
callq 0x1bc070
movq %rax, %rcx
movq 0x70(%rsp), %rax
movq %rcx, (%rax)
movq 0x60(%rsp), %rax
movb $0x1, (%rax)
jmp 0x1b8652
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x19360
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rcx
movq %rax, 0x18(%rcx)
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x1b84ac
jmp 0x1b843f
cmpq $0x0, 0x18(%rsp)
jne 0x1b847f
movq 0x483b52(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x35dbbb(%rip), %rsi    # 0x516013
leaq 0x396566(%rip), %rdx    # 0x54e9c5
leaq 0x3a8ed6(%rip), %rcx    # 0x56133c
leaq 0x3a88c3(%rip), %r8     # 0x560d30
movl $0xec, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x1b8481
movq 0x68(%rsp), %rdi
callq 0x1bc070
movq %rax, %rdx
movq %rdx, 0x10(%rsp)
movq 0x18(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq %rdx, 0x10(%rax,%rcx,8)
movq 0x60(%rsp), %rax
movb $0x1, (%rax)
jmp 0x1b850b
movq 0x10(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x1b8509
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
cmpl $0x1, (%rax)
jne 0x1b8509
movq 0x10(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x1b8509
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
cmpl $0x1, (%rax)
jne 0x1b8509
movq 0x10(%rsp), %rax
movl $0x1, (%rax)
movq 0x10(%rsp), %rax
movq 0x10(%rax), %rax
movl $0x0, (%rax)
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl $0x0, (%rax)
jmp 0x1b850b
cmpq $0x0, 0x10(%rsp)
je 0x1b85c6
movq 0x10(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x1b85c6
cmpq $0x0, 0x18(%rsp)
je 0x1b85c6
movq 0x18(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x1b85c6
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
cmpq 0x28(%rsp), %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, (%rsp)
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movslq 0x8(%rsp), %rdx
cmpq 0x10(%rcx,%rdx,8), %rax
jne 0x1b859a
movq 0x28(%rsp), %rdi
cmpl $0x0, 0x8(%rsp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %esi
callq 0x1b8fd0
movq %rax, %rdx
movq 0x20(%rsp), %rax
movslq (%rsp), %rcx
movq %rdx, 0x10(%rax,%rcx,8)
jmp 0x1b85c4
movq 0x28(%rsp), %rdi
cmpl $0x0, 0x8(%rsp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %esi
callq 0x1b9060
movq %rax, %rdx
movq 0x20(%rsp), %rax
movslq (%rsp), %rcx
movq %rdx, 0x10(%rax,%rcx,8)
jmp 0x1b85c6
movq 0x58(%rsp), %rax
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rdi
movq 0x68(%rsp), %rsi
movq 0x50(%rsp), %rdx
callq *%rax
movl %eax, 0x4(%rsp)
cmpl $0x0, 0x4(%rsp)
jne 0x1b85ed
jmp 0x1b8645
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rsp)
cmpl $0x0, 0x4(%rsp)
setl %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, 0xc(%rsp)
cmpq $0x0, 0x28(%rsp)
je 0x1b8618
movq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x10(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq 0x10(%rax,%rcx,8), %rax
movq %rax, 0x10(%rsp)
jmp 0x1b8435
movq 0x48(%rsp), %rcx
movq 0x70(%rsp), %rax
movq %rcx, (%rax)
movq 0x70(%rsp), %rax
movq (%rax), %rax
movl $0x0, (%rax)
movq 0x60(%rsp), %rax
testb $0x1, (%rax)
je 0x1b867b
movq 0x70(%rsp), %rax
movq 0x18(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rax)
addq $0x78, %rsp
retq