// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %r8, 0x20(%rsp)
movq %rcx, %r12
movq %rdx, 0x10(%rsp)
movl %esi, 0x1c(%rsp)
movl %edi, 0x34(%rsp)
cmpl $0x2, %edi
jne 0x16fd44
movdqa 0x1f1d93(%rip), %xmm0   # 0x361a70
movq 0x359b2c(%rip), %rax    # 0x4c9810
xorl %ecx, %ecx
movdqa 0x1f1da2(%rip), %xmm1   # 0x361a90
movdqu %xmm0, (%rax,%rcx,8)
addq $0x2, %rcx
paddq %xmm1, %xmm0
cmpq $0x64, %rcx
jne 0x16fcee
movq 0x359b08(%rip), %rbx    # 0x4c9810
xorl %r14d, %r14d
callq 0x125bcc
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 0x16fd0b
cmpq $-0x64, %r12
je 0x16ff27
movq %r12, %rax
negq %rax
movq %rax, 0x38(%rsp)
leaq (,%r12,8), %r15
negq %r15
movq %r12, 0x28(%rsp)
leaq 0x318(,%r12,8), %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
movl 0x34(%rsp), %eax
testl %eax, %eax
je 0x16fd96
cmpl $0x1, %eax
jne 0x16fda4
movl $0x63, %ebx
subq %rbp, %rbx
movq 0x28(%rsp), %rax
leaq (%rbx,%rax), %r14
jmp 0x16fdbf
movq 0x38(%rsp), %rax
leaq (%rax,%rbp), %r14
movq %rbp, %rbx
jmp 0x16fdbf
cmpq 0x28(%rsp), %rbp
movq 0x359a60(%rip), %rax    # 0x4c9810
movq %r15, %rcx
cmovbq %r12, %rcx
movq (%rax,%rcx), %r14
movq (%rax,%rbp,8), %rbx
cmpl $0x2, 0x1c(%rsp)
jae 0x16fe61
cmpq $0x63, %rbp
ja 0x16fe68
shlq $0x3, %rbx
movq 0x359a29(%rip), %rsi    # 0x4c9808
addq %rbx, %rsi
movq 0x10(%rsp), %rdi
callq 0x16e015
testq %rax, %rax
movq %r13, %rax
je 0x16fe09
movq 0x20(%rsp), %rdi
leaq 0x2280bf(%rip), %rsi    # 0x397ebf
xorl %eax, %eax
callq 0x1019cf
movb $0x1, %al
testb $0x1, %al
jne 0x16fe6b
movq 0x3599f4(%rip), %rsi    # 0x4c9808
addq %rbx, %rsi
movq 0x10(%rsp), %r13
movq %r13, %rdi
leaq 0xf(%rsp), %rdx
movq %rax, 0x40(%rsp)
callq 0x16e310
addq 0x3599d3(%rip), %rbx    # 0x4c9808
movq %r13, %rdi
movq %rbx, %rsi
callq 0x16e015
testq %rax, %rax
movq 0x40(%rsp), %rax
jne 0x16fe6b
movq 0x20(%rsp), %rdi
leaq 0x228090(%rip), %rsi    # 0x397ee6
xorl %eax, %eax
callq 0x1019cf
movb $0x1, %al
jmp 0x16fe6b
jne 0x16fecd
movq %rbx, %r14
jmp 0x16fe88
movq %r13, %rax
cmpq 0x28(%rsp), %rbp
jb 0x16ff02
cmpl $0x0, 0x1c(%rsp)
je 0x16ff02
movq %rax, %r13
testb $0x1, %al
jne 0x16ff05
shlq $0x3, %r14
movq 0x359975(%rip), %rsi    # 0x4c9808
addq %r14, %rsi
movq 0x10(%rsp), %rdi
callq 0x16e015
leaq 0x228068(%rip), %rsi    # 0x397f0f
testq %rax, %rax
je 0x16fef1
addq 0x359955(%rip), %r14    # 0x4c9808
movq 0x10(%rsp), %rdi
movq %r14, %rsi
callq 0x16e38c
leaq 0x228048(%rip), %rsi    # 0x397f0f
testl %eax, %eax
jne 0x16fef1
jmp 0x16ff05
shlq $0x3, %rbx
addq 0x359930(%rip), %rbx    # 0x4c9808
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0x16e015
leaq 0x227ffa(%rip), %rsi    # 0x397ee6
testq %rax, %rax
jne 0x16ff05
movq 0x20(%rsp), %rdi
xorl %eax, %eax
callq 0x1019cf
movb $0x1, %r13b
jmp 0x16ff05
movq %rax, %r13
movq 0x38(%rsp), %rax
addq %rbp, %rax
incq %rax
incq %rbp
addq $0x8, %r15
addq $-0x8, %r12
cmpq $0x64, %rax
jne 0x16fd76
jmp 0x16ff2a
xorl %r13d, %r13d
andb $0x1, %r13b
movl %r13d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq