// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/rbtree.c
// Function: nrbt_mangle_tree
static bool nrbt_mangle_tree(GtRBTreeSearchOrder how, GtRBTreeDoAction what,
                             GtRBTree *tree, GtUword lag, GtError *err)
{
  GtUword i;
  bool nodecreated, haserr = false;

  if (how == GT_RBTREE_RANDOMORDER) {
    for (i = 0; i < (GtUword) GT_RBTREE_SIZE; ++i) {
      gt_rbtree_ytab[i] = i;
    }
    gt_rbtree_permuteintarray (gt_rbtree_ytab);
  }
  for (i = 0; i < GT_RBTREE_SIZE + lag; ++i) {
    void *elem;
    GtUword j, k;

    switch (how) {
      case GT_RBTREE_RANDOMORDER:
        if (i >= lag) {
          k = gt_rbtree_ytab[i - lag];
        } else {
          k = gt_rbtree_ytab[GT_RBTREE_SIZE - i - 1 + lag];
        }
        j = gt_rbtree_ytab[i];
        break;

      case GT_RBTREE_ASCENDING:
        k = i - lag;
        j = i;
        break;

      case GT_RBTREE_DESCENDING:
        k = GT_RBTREE_SIZE - i - 1 + lag;
        j = GT_RBTREE_SIZE - i - 1;
        break;

      default:
        abort ();
    }

    switch (what) {
      case GtRBTreeBuildDelete:
      case GtRBTreeBuild:
        if (i < (GtUword) GT_RBTREE_SIZE) {
          if (gt_rbtree_find (tree, gt_rbtree_xtab + j) != NULL) {
            gt_error_set(err,"Found element which is not in tree yet");
            haserr = true;
          }
          if (!haserr) {
            elem = gt_rbtree_search(tree, gt_rbtree_xtab + j, &nodecreated);
            if (elem == NULL || gt_rbtree_find(tree,
                                               gt_rbtree_xtab + j) == NULL) {
              gt_error_set(err,"Couldn't find element after it was added");
              haserr = true;
            }
          }
        }
        if (haserr || what ==GtRBTreeBuild || i < lag)
          break;
        j = k;
        /*@fallthrough@*/
      case GtRBTreeDelete:
        elem = gt_rbtree_find (tree, gt_rbtree_xtab + j);
        if (elem == NULL || gt_rbtree_erase (tree, gt_rbtree_xtab + j) != 0) {
          gt_error_set(err,"Error deleting element");
          haserr = true;
        }
        break;

      case GtRBTreeFind:
        if (gt_rbtree_find (tree, gt_rbtree_xtab + j) == NULL) {
          gt_error_set(err,"Couldn't find element after it was added");
          haserr = true;
        }
        break;
    }
  }
  return haserr;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, 0x30(%rsp)
movq %rcx, %r12
movq %rdx, 0x8(%rsp)
movl %esi, 0x14(%rsp)
movl %edi, 0x2c(%rsp)
cmpl $0x2, %edi
jne 0x167e1d
movdqa 0x1f0c63(%rip), %xmm0   # 0x358a20
movq 0x356a4c(%rip), %rbx    # 0x4be810
xorl %eax, %eax
movdqa 0x1f0c72(%rip), %xmm1   # 0x358a40
movdqu %xmm0, (%rbx,%rax,8)
addq $0x2, %rax
paddq %xmm1, %xmm0
cmpq $0x64, %rax
jne 0x167dce
xorl %r14d, %r14d
callq 0x11fe0c
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
imulq $0x51eb851f, %rcx, %rcx # imm = 0x51EB851F
shrq $0x25, %rcx
imull $0x64, %ecx, %ecx
subl %ecx, %eax
movq (%rbx,%r14,8), %rcx
shll $0x3, %eax
movq (%rbx,%rax), %rdx
movq %rdx, (%rbx,%r14,8)
movq %rcx, (%rbx,%rax)
incq %r14
cmpq $0x64, %r14
jne 0x167de4
cmpq $-0x64, %r12
je 0x167fdb
movq %r12, %r15
negq %r15
leaq (,%r12,8), %rbp
negq %rbp
movq %r12, 0x20(%rsp)
leaq 0x318(,%r12,8), %r13
movq $0x0, 0x18(%rsp)
xorl %r12d, %r12d
movl 0x2c(%rsp), %eax
testl %eax, %eax
je 0x167e71
cmpl $0x1, %eax
jne 0x167e7a
movl $0x63, %ebx
subq %r12, %rbx
movq 0x20(%rsp), %rax
leaq (%rbx,%rax), %r14
jmp 0x167e95
leaq (%r15,%r12), %r14
movq %r12, %rbx
jmp 0x167e95
cmpq 0x20(%rsp), %r12
movq 0x35698a(%rip), %rax    # 0x4be810
movq %rbp, %rcx
cmovbq %r13, %rcx
movq (%rax,%rcx), %r14
movq (%rax,%r12,8), %rbx
cmpl $0x2, 0x14(%rsp)
jae 0x167f12
cmpq $0x64, %r12
jae 0x167f1d
shlq $0x3, %rbx
movq 0x35695b(%rip), %rsi    # 0x4be808
addq %rbx, %rsi
movq 0x8(%rsp), %rdi
callq 0x1660cc
leaq 0x226c1e(%rip), %rsi    # 0x38eadf
testq %rax, %rax
jne 0x167f7d
testb $0x1, 0x18(%rsp)
jne 0x167f90
movq 0x35692c(%rip), %rsi    # 0x4be808
addq %rbx, %rsi
movq 0x8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x1663b6
addq 0x356913(%rip), %rbx    # 0x4be808
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x1660cc
leaq 0x226bfd(%rip), %rsi    # 0x38eb06
testq %rax, %rax
je 0x167f7d
xorl %eax, %eax
jmp 0x167f22
jne 0x167fae
movq %rbx, %r14
jmp 0x167f3a
movq 0x18(%rsp), %rax
cmpl $0x0, 0x14(%rsp)
sete %cl
orb %al, %cl
cmpq 0x20(%rsp), %r12
setb %al
orb %cl, %al
testb $0x1, %al
jne 0x167f90
shlq $0x3, %r14
movq 0x3568c3(%rip), %rsi    # 0x4be808
addq %r14, %rsi
movq 0x8(%rsp), %rdi
callq 0x1660cc
leaq 0x226bd6(%rip), %rsi    # 0x38eb2f
testq %rax, %rax
je 0x167f7d
addq 0x3568a3(%rip), %r14    # 0x4be808
movq 0x8(%rsp), %rdi
movq %r14, %rsi
callq 0x166432
leaq 0x226bb6(%rip), %rsi    # 0x38eb2f
testl %eax, %eax
je 0x167f90
movq 0x30(%rsp), %rdi
xorl %eax, %eax
callq 0xfcb67
movb $0x1, %al
movq %rax, 0x18(%rsp)
leaq (%r15,%r12), %rax
incq %rax
incq %r12
addq $0x8, %rbp
addq $-0x8, %r13
cmpq $0x64, %rax
jne 0x167e51
jmp 0x167fd4
shlq $0x3, %rbx
addq 0x35684f(%rip), %rbx    # 0x4be808
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x1660cc
leaq 0x226b39(%rip), %rsi    # 0x38eb06
testq %rax, %rax
jne 0x167f90
jmp 0x167f7d
movq 0x18(%rsp), %rax
jmp 0x167fdd
xorl %eax, %eax
andb $0x1, %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq