// File: /workspace/github_c_makefile_star2_O2/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 0x2b3806
orq $-0x1, (%rdi)
testq %r9, %r9
je 0x2b3810
movq (%r9), %rbx
testq %rbx, %rbx
je 0x2b3921
movq 0x10(%r9), %rax
shlq $0x4, %rax
leaq (%rbx,%rax), %r14
addq $-0x10, %r14
xorl %eax, %eax
pushq $-0x1
popq %r11
movq %rbx, %r15
movq %r14, %r13
subq %r15, %r13
sarq %r13
andq $-0x10, %r13
leaq (%r15,%r13), %r12
movq 0x8(%r15,%r13), %r13
cmpq %r10, %r13
jbe 0x2b37f3
movq (%r12), %r11
movq %r13, (%rdi)
cmpl 0x20(%r9), %eax
jae 0x2b381c
addq $-0x10, %r12
movq %r12, %r14
jmp 0x2b3802
jae 0x2b384c
cmpl 0x20(%r9), %eax
jae 0x2b3863
addq $0x10, %r12
movq %r12, %r15
incl %eax
jmp 0x2b37c2
movq %rdx, (%rdi)
xorl %eax, %eax
jmp 0x2b3917
pushq $-0x1
popq %r11
pushq $0x1
popq %rax
jmp 0x2b38ee
cmpq $-0x1, (%r15)
je 0x2b3952
movq (%r14), %rcx
cmpq $-0x1, %rcx
je 0x2b3952
cmpq %rbx, %r15
jbe 0x2b38cf
movq -0x10(%r15), %rax
movq -0x8(%r15), %rdx
incq %rax
jmp 0x2b38d2
cmpq $-0x1, (%r12)
je 0x2b39e2
movq %r13, (%rdi)
movq (%r12), %rax
jmp 0x2b3917
movq (%r15), %rax
cmpq $-0x1, %rax
je 0x2b39b4
cmpq $-0x1, (%r14)
je 0x2b39b4
incq %rax
movq 0x8(%r15), %rdx
movq 0x10(%r9), %r9
shlq $0x4, %r9
addq %rbx, %r9
addq $-0x10, %r9
cmpq %r9, %r14
jae 0x2b38db
movq 0x10(%r14), %rcx
testq %rcx, %rcx
jne 0x2b38db
movq 0x1846c3(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x31764(%rip), %rsi     # 0x2e5013
leaq 0xcee01(%rip), %rdx     # 0x3826b7
leaq 0xced8c(%rip), %rcx     # 0x382649
leaq 0xcec6b(%rip), %r8      # 0x38252f
movl $0xd2, %r9d
jmp 0x2b3a3c
pushq $0x1
popq %rax
testq %rcx, %rcx
je 0x2b3a10
cmpq $-0x1, %rax
je 0x2b3983
testq %rcx, %rcx
je 0x2b3983
decq %rcx
cmpq %rcx, %rax
jbe 0x2b38fb
movq %r11, %rax
jmp 0x2b3917
cmpq %rcx, %rax
ja 0x2b38f6
movq (%rsi,%rax,8), %r9
andq %r8, %r9
addq %r9, %rdx
cmpq %r10, %rdx
jae 0x2b3914
incq %rax
jmp 0x2b38fb
movq %rdx, (%rdi)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x184640(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x316e1(%rip), %rsi     # 0x2e5013
leaq 0xcec39(%rip), %rdx     # 0x382572
leaq 0xced09(%rip), %rcx     # 0x382649
leaq 0xcebe8(%rip), %r8      # 0x38252f
movl $0xa2, %r9d
jmp 0x2b3a3c
movq 0x18460f(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x316b0(%rip), %rsi     # 0x2e5013
leaq 0xcecf7(%rip), %rdx     # 0x382661
leaq 0xcecd8(%rip), %rcx     # 0x382649
leaq 0xcebb7(%rip), %r8      # 0x38252f
movl $0xb3, %r9d
jmp 0x2b3a3c
movq 0x1845de(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x3167f(%rip), %rsi     # 0x2e5013
leaq 0xced53(%rip), %rdx     # 0x3826ee
leaq 0xceca7(%rip), %rcx     # 0x382649
leaq 0xceb86(%rip), %r8      # 0x38252f
movl $0xe2, %r9d
jmp 0x2b3a3c
movq 0x1845ad(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x3164e(%rip), %rsi     # 0x2e5013
leaq 0xcec95(%rip), %rdx     # 0x382661
leaq 0xcec76(%rip), %rcx     # 0x382649
leaq 0xceb55(%rip), %r8      # 0x38252f
movl $0xcc, %r9d
jmp 0x2b3a3c
movq 0x18457f(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x31620(%rip), %rsi     # 0x2e5013
leaq 0xcecd7(%rip), %rdx     # 0x3826d1
leaq 0xcec48(%rip), %rcx     # 0x382649
leaq 0xceb27(%rip), %r8      # 0x38252f
movl $0xdc, %r9d
jmp 0x2b3a3c
movq 0x184551(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x315f2(%rip), %rsi     # 0x2e5013
leaq 0xcec79(%rip), %rdx     # 0x3826a1
leaq 0xcec1a(%rip), %rcx     # 0x382649
leaq 0xceaf9(%rip), %r8      # 0x38252f
movl $0xbe, %r9d
xorl %eax, %eax
callq 0x17a50
callq 0x17390