// File: /workspace/github_c_makefile_star2_O1/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 0x1a3497
testb $0x2, %cl
je 0x1a35f2
movq (%r15), %rax
movq 0x10(%rax), %rax
decq %rax
testb $0x4, %cl
je 0x1a3451
movl 0x20(%r15), %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rdi
callq 0x2f9d41
movl %eax, %ebp
xorl %r12d, %r12d
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1a32ff
testq %rax, %rax
jne 0x1a35bd
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1a35f7
movq %rax, %r14
incl %r12d
movq (%r15), %rax
cmpq %r12, 0x10(%rax)
jae 0x1a345e
callq 0x604ca
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1a327c
xorl %ebp, %ebp
testl %eax, %eax
jne 0x1a34d2
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x1a35f7
movq %rax, %r14
incl %ebp
movq %r15, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x1a327c
testl %eax, %eax
je 0x1a34ab
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 0x1a350a
movl 0x20(%r15), %ecx
movq %r12, %rax
xorl %edx, %edx
divq %rcx
movq %rax, %r12
movq 0x18(%rbx), %rdi
callq 0x2f9d41
movl %eax, 0xc(%rsp)
movq 0x18(%rbx), %rdi
decq %rdi
callq 0x2f9d41
movl %eax, %r13d
movq %r12, %rdi
callq 0x2f9d41
movq %rax, 0x10(%rsp)
movq (%rbx), %rsi
movq 0x20(%rbx), %rdi
movq %r14, %rdx
subq 0x10(%rbx), %rdx
callq 0x2fa5fa
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 0x2fcc2c
movq %rax, %r13
movl 0x40(%r15), %eax
testb $0x4, %al
je 0x1a3594
movl 0x20(%r15), %ecx
imulq %rcx, %r13
addq %rbp, %r13
testb $0x2, %al
je 0x1a35e0
movq 0x28(%rbx), %rdi
addq 0x8(%rbx), %r12
movq %r12, %rsi
movl 0x8(%rsp), %edx
callq 0x2fcc2c
subq 0x10(%rbx), %r14
cmpq %r14, %rax
je 0x1a35e0
callq 0x60491
movq 0x28(%rbx), %rdi
movq %rax, %rsi
movl %ebp, %edx
callq 0x2fcc2c
testb $0x4, 0x40(%r15)
je 0x1a35da
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