// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/match/randomcodes.c
// Function: gt_randomcodes_find_accu
GtUword gt_randomcodes_find_accu(const GtRandomcodesinfo *fci,
                                       GtUword code)
{
  const GtUword *found = NULL, *leftptr = NULL, *midptr, *rightptr = NULL;

  if (code <= fci->allrandomcodes[0])
  {
    return 0;
  }
  if (fci->binsearchcache.spaceGtIndexwithcodeRC != NULL)
  {
    const GtIndexwithcodeRC *leftic, *midic, *rightic;
    unsigned int depth;

    leftic = fci->binsearchcache.spaceGtIndexwithcodeRC;
    rightic = fci->binsearchcache.spaceGtIndexwithcodeRC +
              fci->binsearchcache.nextfreeGtIndexwithcodeRC - 1;
    for (depth = 0; /* Nothing */; depth++)
    {
      midic = leftic + GT_DIV2((GtUword) (rightic-leftic));
      if (code < midic->code)
      {
        found = midic->ptr;
        if (depth < fci->binsearchcache.depth)
        {
          rightic = midic - 1;
        } else
        {
          gt_assert(leftic->ptr != NULL && rightic->ptr != NULL);
          if (leftic > fci->binsearchcache.spaceGtIndexwithcodeRC)
          {
            leftptr = (leftic-1)->ptr + 1;
          } else
          {
            gt_assert(code > fci->allrandomcodes[0]);
            leftptr = fci->allrandomcodes + 1;
          }
          rightptr = rightic->ptr - 1;
          break;
        }
      } else
      {
        if (code > midic->code)
        {
          if (depth < fci->binsearchcache.depth)
          {
            leftic = midic + 1;
          } else
          {
            gt_assert(leftic->ptr != NULL && rightic->ptr != NULL);
            leftptr = leftic->ptr + 1;
            if (rightic < fci->binsearchcache.spaceGtIndexwithcodeRC +
                          fci->binsearchcache.nextfreeGtIndexwithcodeRC - 1)
            {
              rightptr = (rightic+1)->ptr - 1;
            } else
            {
              rightptr = fci->allrandomcodes + fci->differentcodes - 1;
            }
            break;
          }
        } else
        {
          gt_assert(midic->ptr != NULL);
          return (GtUword) (midic->ptr - fci->allrandomcodes);
        }
      }
    }
    gt_assert(leftptr != NULL && rightptr != NULL);
  } else
  {
    leftptr = fci->allrandomcodes + 1;
    rightptr = fci->allrandomcodes + fci->differentcodes - 1;
  }
  while (leftptr <= rightptr)
  {
    midptr = leftptr + GT_DIV2((GtUword) (rightptr-leftptr));
    if (code < *midptr)
    {
      rightptr = midptr - 1;
      if (code > *rightptr)
      {
        return (GtUword) (midptr - fci->allrandomcodes);
      }
      found = midptr;
    } else
    {
      if (code > *midptr)
      {
        leftptr = midptr + 1;
        if (code <= *leftptr)
        {
          return (GtUword) (leftptr - fci->allrandomcodes);
        }
      } else
      {
        gt_assert(midptr != NULL);
        return (GtUword) (midptr - fci->allrandomcodes);
      }
    }
  }
 return (found != NULL) ? (GtUword) (found - fci->allrandomcodes)
                         : ULONG_MAX;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq 0xa0(%rdi), %rcx
cmpq %rsi, (%rcx)
jae 0x1c5ca3
movq 0x48(%rdi), %rax
testq %rax, %rax
je 0x1c5caa
movq 0x58(%rdi), %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r9
addq $-0x18, %r9
xorl %edx, %edx
movabsq $-0x5555555555555555, %r8 # imm = 0xAAAAAAAAAAAAAAAB
movq %rax, %r11
movq %r9, %r10
xorl %ebx, %ebx
movq %r10, %r14
subq %r11, %r14
sarq $0x3, %r14
imulq %r8, %r14
shrq %r14
leaq (%r14,%r14,2), %r14
leaq (%r11,%r14,8), %r14
cmpq %rsi, 0x8(%r14)
jbe 0x1c5c91
movq (%r14), %rdx
cmpl 0x68(%rdi), %ebx
jae 0x1c5cc1
addq $-0x18, %r14
movq %r14, %r10
jmp 0x1c5c9f
jae 0x1c5ce9
cmpl 0x68(%rdi), %ebx
jae 0x1c5d06
addq $0x18, %r14
movq %r14, %r11
incl %ebx
jmp 0x1c5c61
xorl %eax, %eax
jmp 0x1c5da8
leaq 0x8(%rcx), %r8
movq 0x38(%rdi), %rax
leaq (%rcx,%rax,8), %rdi
addq $-0x8, %rdi
xorl %edx, %edx
jmp 0x1c5d43
cmpq $0x0, (%r11)
je 0x1c5db0
movq (%r10), %rdi
testq %rdi, %rdi
je 0x1c5db0
movq %rcx, %r8
cmpq %rax, %r11
jbe 0x1c5ce3
movq -0x18(%r11), %r8
addq $0x8, %r8
jmp 0x1c5d29
movq (%r14), %rax
testq %rax, %rax
je 0x1c5dba
subq %rcx, %rax
sarq $0x3, %rax
xorl %r8d, %r8d
xorl %edi, %edi
xorl %r9d, %r9d
jmp 0x1c5d3e
movq (%r11), %r8
testq %r8, %r8
je 0x1c5db5
cmpq $0x0, (%r10)
je 0x1c5db5
addq $0x8, %r8
cmpq %r9, %r10
jae 0x1c5d2f
movq 0x18(%r10), %rdi
addq $-0x8, %rdi
jmp 0x1c5d3b
movq 0x38(%rdi), %rax
leaq (%rcx,%rax,8), %rdi
addq $-0x8, %rdi
movb $0x1, %r9b
testb %r9b, %r9b
je 0x1c5da8
cmpq %rdi, %r8
jbe 0x1c5d4d
movq %rdx, %rax
jmp 0x1c5d87
movq %rdi, %r9
subq %r8, %r9
sarq %r9
andq $-0x8, %r9
leaq (%r8,%r9), %rax
cmpq %rsi, (%r8,%r9)
jbe 0x1c5d73
cmpq %rsi, -0x8(%rax)
jb 0x1c5d8c
leaq -0x8(%rax), %rdi
movq %rax, %rdx
jmp 0x1c5d82
jae 0x1c5d8c
leaq 0x8(%rax), %r8
cmpq %rsi, 0x8(%rax)
jae 0x1c5d9e
movq %rdx, %rax
cmpq %rdi, %r8
jbe 0x1c5d4d
testq %rax, %rax
je 0x1c5d95
subq %rcx, %rax
sarq $0x3, %rax
jmp 0x1c5da8
movq $-0x1, %rax
jmp 0x1c5da8
subq %rcx, %r8
sarq $0x3, %r8
movq %r8, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
callq 0x69cae
callq 0x69c75
callq 0x69c3c