// File: /workspace/github_c_makefile_star2_O3/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 0x19af12
testb $0x2, %cl
je 0x19b06d
movq (%r15), %rax
movq 0x10(%rax), %rax
decq %rax
testb $0x4, %cl
je 0x19aecc
movl 0x20(%r15), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rdi
callq 0x2f09dd
movl %eax, %ebp
xorl %r12d, %r12d
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x19adbf
testq %rax, %rax
jne 0x19b038
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x19b072
movq %rax, %r14
incl %r12d
movq (%r15), %rax
cmpq %r12, 0x10(%rax)
jae 0x19aed9
callq 0x5f056
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x19ad3c
xorl %ebp, %ebp
testl %eax, %eax
jne 0x19af4d
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x19b072
movq %rax, %r14
incl %ebp
movq %r15, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x19ad3c
testl %eax, %eax
je 0x19af26
movl %ebp, %ebp
movq (%r15), %rdi
movq 0x18(%r15), %r8
movq (%rdi), %rax
movq %r14, %rsi
movl $0x2, %edx
movq %rbx, %rcx
callq *0x50(%rax)
movq (%r15), %rax
movq 0x10(%rax), %r12
decq %r12
testb $0x4, 0x40(%r15)
je 0x19af85
movl 0x20(%r15), %ecx
movq %r12, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r12
movq 0x18(%rbx), %rdi
callq 0x2f09dd
movl %eax, 0xc(%rsp)
movq 0x18(%rbx), %rdi
decq %rdi
callq 0x2f09dd
movl %eax, %r13d
movq %r12, %rdi
callq 0x2f09dd
movq %rax, 0x10(%rsp)
movq (%rbx), %rsi
movq 0x20(%rbx), %rdi
movq %r14, %rdx
subq 0x10(%rbx), %rdx
callq 0x2f1242
movl 0x40(%r15), %r12d
shll $0x1e, %r12d
sarl $0x1f, %r12d
movl %r12d, %esi
movl %r13d, 0x8(%rsp)
andl %r13d, %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 0x2f37dc
movq %rax, %r13
movl 0x40(%r15), %eax
testb $0x4, %al
je 0x19b00f
movl 0x20(%r15), %ecx
imulq %rcx, %r13
addq %rbp, %r13
testb $0x2, %al
je 0x19b05b
movq 0x28(%rbx), %rdi
addq 0x8(%rbx), %r12
movq %r12, %rsi
movl 0x8(%rsp), %edx
callq 0x2f37dc
subq 0x10(%rbx), %r14
cmpq %r14, %rax
je 0x19b05b
callq 0x5f01d
movq 0x28(%rbx), %rdi
movq %rax, %rsi
movl %ebp, %edx
callq 0x2f37dc
testb $0x4, 0x40(%r15)
je 0x19b055
movl 0x20(%r15), %ecx
imulq %rcx, %rax
movl %r12d, %r13d
addq %rax, %r13
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x173b0