// File: /workspace/github_c_makefile_star2_O1/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 0x31e5bd
movq $-0x1, (%rdi)
testq %r9, %r9
je 0x31e5ca
movq (%r9), %rax
testq %rax, %rax
je 0x31e6b6
movq 0x10(%r9), %r11
shlq $0x4, %r11
leaq (%rax,%r11), %r15
addq $-0x10, %r15
xorl %ebx, %ebx
movq $-0x1, %r11
movq %rax, %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 0x31e5a6
movq (%r12), %r11
movq %r13, (%rdi)
cmpl 0x20(%r9), %ebx
jae 0x31e5de
addq $-0x10, %r12
movq %r12, %r15
jmp 0x31e5b9
jae 0x31e614
cmpl 0x20(%r9), %ebx
jae 0x31e640
addq $0x10, %r12
movq %r12, %r14
incl %ebx
jmp 0x31e575
xorl %ebx, %ebx
movq %rdx, (%rdi)
movq %rbx, %rax
jmp 0x31e6ac
decq %rcx
movq $-0x1, %r11
movl $0x1, %ebx
jmp 0x31e6a4
cmpq $-0x1, (%r14)
je 0x31e6bb
movq (%r15), %rcx
cmpq $-0x1, %rcx
je 0x31e6bb
movl $0x1, %ebx
cmpq %rax, %r14
jbe 0x31e60a
movq -0x10(%r14), %rbx
movq -0x8(%r14), %rdx
incq %rbx
testq %rcx, %rcx
jne 0x31e673
callq 0x93098
cmpq $-0x1, (%r12)
je 0x31e6ca
movq %r13, (%rdi)
movq (%r12), %rax
movq $-0x1, %rbx
xorl %r9d, %r9d
movq $-0x1, %rcx
movq $-0x1, %rdx
jmp 0x31e684
movq (%r14), %rbx
cmpq $-0x1, %rbx
je 0x31e6c5
cmpq $-0x1, (%r15)
je 0x31e6c5
incq %rbx
movq 0x8(%r14), %rdx
movq 0x10(%r9), %r9
shlq $0x4, %r9
addq %r9, %rax
addq $-0x10, %rax
cmpq %rax, %r15
jae 0x31e673
movq 0x10(%r15), %rcx
testq %rcx, %rcx
je 0x31e6cf
cmpq $-0x1, %rbx
je 0x31e6c0
testq %rcx, %rcx
je 0x31e6c0
decq %rcx
movb $0x1, %r9b
testb %r9b, %r9b
jne 0x31e6a4
jmp 0x31e6ac
movq %rdx, %rax
movq (%rsi,%rbx,8), %rdx
andq %r8, %rdx
addq %rax, %rdx
cmpq %r10, %rdx
jae 0x31e5bf
incq %rbx
cmpq %rcx, %rbx
jbe 0x31e68b
movq %r11, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
callq 0x9310a
callq 0x930d1
callq 0x9305f
callq 0x93026
callq 0x92fb4
callq 0x92fed