// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/match/eis-bwtseq-extinfo.c
// Function: gt_BWTSeqLocateMatch
GtUword
gt_BWTSeqLocateMatch(const BWTSeq *bwtSeq, GtUword pos,
                  struct extBitsRetrieval *extBits)
{
  if (bwtSeq->featureToggles & BWTLocateBitmap)
  {
    GtUword nextLocate = pos;
    unsigned locateOffset = 0;
    while (!gt_BWTSeqPosHasLocateInfo(bwtSeq, nextLocate, extBits))
      nextLocate = BWTSeqLFMap(bwtSeq, nextLocate, extBits), ++locateOffset;
    EISRetrieveExtraBits(bwtSeq->seqIdx, nextLocate,
                         EBRF_RETRIEVE_CWBITS | EBRF_RETRIEVE_VARBITS,
                         extBits, bwtSeq->hint);
    {
      GtUword maxPosVal = ((bwtSeq->featureToggles & BWTReversiblySorted)?
                          (BWTSeqLength(bwtSeq) - 1)
                          /bwtSeq->locateSampleInterval:
                          BWTSeqLength(bwtSeq) - 1);
      unsigned bitsPerCount = requiredUlongBits(extBits->len),
        bitsPerBWTPos = requiredUlongBits(extBits->len - 1),
        bitsPerOrigPos = requiredUlongBits(maxPosVal);
      BitOffset locateRecordIndex =
        gt_bs1BitsCount(extBits->cwPart, extBits->cwOffset,
                     nextLocate - extBits->start),
        locateRecordOffset = ((bwtSeq->featureToggles & BWTLocateCount?
                               bitsPerBWTPos:0) + bitsPerOrigPos)
        * locateRecordIndex
        + ((bwtSeq->featureToggles & BWTLocateCount)?bitsPerCount:0);
      GtUword matchPos =
        gt_bsGetUlong(
          extBits->varPart, extBits->varOffset + locateRecordOffset
          + ((bwtSeq->featureToggles & BWTLocateCount)?bitsPerBWTPos:0),
          bitsPerOrigPos);
      if (bwtSeq->featureToggles & BWTReversiblySorted)
        matchPos = matchPos * bwtSeq->locateSampleInterval;
      matchPos += locateOffset;
      gt_assert(!(bwtSeq->featureToggles & BWTLocateCount)
             || gt_bsGetUlong(extBits->varPart,
                            extBits->varOffset + locateRecordOffset,
                            bitsPerBWTPos)
             == nextLocate - extBits->start);
      return matchPos;
    }
  }
  else if (bwtSeq->featureToggles & BWTLocateCount)
  {
    BitOffset markOffset;
    GtUword nextLocate = pos, matchPos;
    unsigned locateOffset = 0;  /* mark is at most locateInterval
                                 * positions away */
    unsigned bitsPerOrigPos
      = requiredUlongBits(((bwtSeq->featureToggles & BWTReversiblySorted)?
                            (BWTSeqLength(bwtSeq) - 1)
                            /bwtSeq->locateSampleInterval:
                            BWTSeqLength(bwtSeq) - 1));
    while ((markOffset = searchLocateCountMark(bwtSeq, nextLocate,
                                               extBits)) == 0)
    {
      nextLocate = BWTSeqLFMap(bwtSeq, nextLocate, extBits);
      ++locateOffset;
      gt_assert(locateOffset <= BWTSeqLength(bwtSeq));
    }
    matchPos = gt_bsGetUlong(extBits->varPart, markOffset, bitsPerOrigPos);
    if (bwtSeq->featureToggles & BWTReversiblySorted)
        matchPos = matchPos * bwtSeq->locateSampleInterval;
    matchPos += locateOffset;
    return matchPos;
  }
  /* Internal error: Trying to locate in BWT sequence index without locate
     information. */
   abort();
   return 0; /* shut up compiler */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movl 0x40(%rdi), %ecx
testb $0x1, %cl
jne 0x14587b
testb $0x2, %cl
je 0x1459ef
movq (%r15), %rax
movq 0x10(%rax), %rax
decq %rax
testb $0x4, %cl
je 0x145802
movl 0x20(%r15), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rdi
callq 0x28a939
movl %eax, %ebp
xorl %r12d, %r12d
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1456f2
testq %rax, %rax
jne 0x1459ba
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1459f4
movq %rax, %r14
incl %r12d
movq (%r15), %rax
cmpq %r12, 0x10(%rax)
jae 0x14580f
movq 0x2f271e(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19f7bf(%rip), %rsi    # 0x2e5013
leaq 0x1fd22e(%rip), %rdx    # 0x342a89
leaq 0x1fd212(%rip), %rcx    # 0x342a74
leaq 0x1fd077(%rip), %r8     # 0x3428e0
movl $0x2f9, %r9d            # imm = 0x2F9
xorl %eax, %eax
callq 0x17a50
callq 0x17390
xorl %r13d, %r13d
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x145626
testl %eax, %eax
jne 0x1458a6
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1459f4
movq %rax, %r14
incl %r13d
jmp 0x14587e
movq (%r15), %rdi
movq 0x18(%r15), %r8
movq (%rdi), %rax
pushq $0x2
popq %rdx
movq %r14, %rsi
movq %rbx, %rcx
callq *0x50(%rax)
movq (%r15), %rax
movq 0x10(%rax), %r12
decq %r12
testb $0x4, 0x40(%r15)
je 0x1458dc
movl 0x20(%r15), %ecx
movq %r12, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r12
movq 0x18(%rbx), %rdi
callq 0x28a939
movl %eax, 0xc(%rsp)
movq 0x18(%rbx), %rdi
decq %rdi
callq 0x28a939
movl %eax, %ebp
movq %r12, %rdi
callq 0x28a939
movq %rax, 0x10(%rsp)
movq (%rbx), %rsi
movq 0x20(%rbx), %rdi
movq %r14, %rdx
subq 0x10(%rbx), %rdx
callq 0x28b16e
movl 0x40(%r15), %r12d
shll $0x1e, %r12d
sarl $0x1f, %r12d
movl %r12d, %esi
movl %ebp, 0x8(%rsp)
andl %ebp, %esi
movq 0x10(%rsp), %rdx
leal (%rsi,%rdx), %ecx
imulq %rax, %rcx
andl 0xc(%rsp), %r12d
addq %rcx, %r12
movq 0x28(%rbx), %rdi
addq 0x8(%rbx), %rsi
addq %r12, %rsi
callq 0x28deac
movl 0x40(%r15), %ecx
testb $0x4, %cl
je 0x145961
movl 0x20(%r15), %edx
imulq %rdx, %rax
movl %r13d, %r15d
addq %rax, %r15
testb $0x2, %cl
je 0x1459dd
movq 0x28(%rbx), %rdi
addq 0x8(%rbx), %r12
movq %r12, %rsi
movl 0x8(%rsp), %edx
callq 0x28deac
subq 0x10(%rbx), %r14
cmpq %r14, %rax
je 0x1459dd
movq 0x2f25d8(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19f679(%rip), %rsi    # 0x2e5013
leaq 0x1fd02e(%rip), %rdx    # 0x3429cf
leaq 0x1fd0cc(%rip), %rcx    # 0x342a74
leaq 0x1fcf31(%rip), %r8     # 0x3428e0
movl $0x2e5, %r9d            # imm = 0x2E5
jmp 0x14586f
movq 0x28(%rbx), %rdi
movq %rax, %rsi
movl %ebp, %edx
callq 0x28deac
testb $0x4, 0x40(%r15)
je 0x1459d7
movl 0x20(%r15), %ecx
imulq %rcx, %rax
movl %r12d, %r15d
addq %rax, %r15
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x17390