// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/match/firstcodes-cache.c
// Function: gt_firstcodes_find_accu
GtUword gt_firstcodes_find_accu(GtUword *foundcode,
                                      const GtUword *differences,
                                      GtUword allfirstcodes0,
                                      GtUword differentcodes,
                                      GtUword differencemask,
                                      const GtArrayGtIndexwithcode
                                         *binsearchcache,
                                      GtUword code)
{
  GtUword leftptr = ULONG_MAX, rightptr = ULONG_MAX,
                foundindex = ULONG_MAX, previouscode = ULONG_MAX;

  if (code <= allfirstcodes0)
  {
    *foundcode = allfirstcodes0;
    return 0;
  }
  *foundcode = ULONG_MAX;
  if (binsearchcache != NULL)
  {
    const GtIndexwithcode *leftic, *midic, *rightic;
    unsigned int depth;

    gt_assert(binsearchcache->spaceGtIndexwithcode != NULL);
    leftic = binsearchcache->spaceGtIndexwithcode;
    rightic = binsearchcache->spaceGtIndexwithcode +
              binsearchcache->nextfreeGtIndexwithcode - 1;
    for (depth = 0; /* Nothing */; depth++)
    {
      midic = leftic + GT_DIV2((GtUword) (rightic-leftic));
      if (code < midic->code)
      {
        foundindex = midic->afcindex;
        *foundcode = midic->code;
        if (depth < binsearchcache->depth)
        {
          rightic = midic - 1;
        } else
        {
          gt_assert(leftic->afcindex != ULONG_MAX &&
                    rightic->afcindex != ULONG_MAX);
          if (leftic > binsearchcache->spaceGtIndexwithcode)
          {
            leftptr = (leftic-1)->afcindex + 1;
            previouscode = (leftic-1)->code;
          } else
          {
            gt_assert(code > allfirstcodes0);
            leftptr = 1UL;
            previouscode = allfirstcodes0;
          }
          gt_assert(rightic->afcindex > 0);
          rightptr = rightic->afcindex - 1;
          break;
        }
      } else
      {
        if (code > midic->code)
        {
          if (depth < binsearchcache->depth)
          {
            leftic = midic + 1;
          } else
          {
            gt_assert(leftic->afcindex != ULONG_MAX &&
                      rightic->afcindex != ULONG_MAX);
            leftptr = leftic->afcindex + 1;
            previouscode = leftic->code;
            if (rightic < binsearchcache->spaceGtIndexwithcode +
                          binsearchcache->nextfreeGtIndexwithcode - 1)
            {
              gt_assert((rightic+1)->afcindex > 0);
              rightptr = (rightic+1)->afcindex - 1;
            } else
            {
              rightptr = differentcodes - 1;
            }
            break;
          }
        } else
        {
          gt_assert(midic->afcindex != ULONG_MAX);
          *foundcode = midic->code;
          return midic->afcindex;
        }
      }
    }
    gt_assert(leftptr != ULONG_MAX && rightptr != ULONG_MAX);
  } else
  {
    leftptr = 1UL;
    previouscode = allfirstcodes0;
    rightptr = differentcodes - 1;
  }
  if (leftptr <= rightptr)
  {
    GtUword idx;

    for (idx = leftptr; idx <= rightptr; idx++)
    {
      previouscode += (differences[idx] & differencemask); /* extract diff */
      if (code <= previouscode)
      {
        *foundcode = previouscode;
        foundindex = idx;
        break;
      }
    }
  }
  return foundindex;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq 0x30(%rsp), %r10
cmpq %rdx, %r10
jbe 0x314261
movq $-0x1, (%rdi)
testq %r9, %r9
je 0x31426b
movq (%r9), %rbx
testq %rbx, %rbx
je 0x314335
movq 0x10(%r9), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %r15
addq $-0x10, %r15
xorl %eax, %eax
movq $-0x1, %r11
movq %rbx, %r14
movq %r15, %r13
subq %r14, %r13
sarq %r13
andq $-0x10, %r13
leaq (%r14,%r13), %r12
movq 0x8(%r14,%r13), %r13
cmpq %r10, %r13
jbe 0x31424e
movq (%r12), %r11
movq %r13, (%rdi)
cmpl 0x20(%r9), %eax
jae 0x31427c
addq $-0x10, %r12
movq %r12, %r15
jmp 0x31425d
jae 0x3142b2
cmpl 0x20(%r9), %eax
jae 0x3142c6
addq $0x10, %r12
movq %r12, %r14
incl %eax
jmp 0x31421d
movq %rdx, (%rdi)
xorl %eax, %eax
jmp 0x31432b
movq $-0x1, %r11
movl $0x1, %eax
jmp 0x314304
cmpq $-0x1, (%r14)
je 0x31433a
movq (%r15), %rcx
cmpq $-0x1, %rcx
je 0x31433a
movl $0x1, %eax
cmpq %rbx, %r14
jbe 0x3142a8
movq -0x10(%r14), %rax
movq -0x8(%r14), %rdx
incq %rax
testq %rcx, %rcx
jne 0x3142f9
callq 0x911f7
cmpq $-0x1, (%r12)
je 0x314349
movq %r13, (%rdi)
movq (%r12), %rax
jmp 0x31432b
movq (%r14), %rax
cmpq $-0x1, %rax
je 0x314344
cmpq $-0x1, (%r15)
je 0x314344
incq %rax
movq 0x8(%r14), %rdx
movq 0x10(%r9), %r9
shlq $0x4, %r9
addq %rbx, %r9
addq $-0x10, %r9
cmpq %r9, %r15
jae 0x3142f9
movq 0x10(%r15), %rcx
testq %rcx, %rcx
je 0x31434e
cmpq $-0x1, %rax
je 0x31433f
testq %rcx, %rcx
je 0x31433f
decq %rcx
cmpq %rcx, %rax
ja 0x314323
movq %rdx, %r9
movq (%rsi,%rax,8), %rdx
andq %r8, %rdx
addq %r9, %rdx
cmpq %r10, %rdx
jae 0x314328
incq %rax
jmp 0x314307
movq %r11, %rax
jmp 0x31432b
movq %rdx, (%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
callq 0x91269
callq 0x91230
callq 0x911be
callq 0x91185
callq 0x91113
callq 0x9114c
nop