// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/match/eis-bwtseq-extinfo.c
// Function: addLocateInfo
static BitOffset
addLocateInfo(BitString cwDest, BitOffset cwOffset,
              BitString varDest, BitOffset varOffset,
              GT_UNUSED GtUword start, GtUword len, void *cbState)
{
  BitOffset bitsWritten = 0;
  struct addLocateInfoState *state = cbState;
  unsigned bitsPerBWTPos, bitsPerOrigPos, bitsPerOrigRank;
  int retcode;
  unsigned locateInterval;
  gt_assert(varDest && cbState);
  locateInterval = state->locateInterval;
  /* 0. resize caches if necessary */
  if (locateInterval && len > state->revMapQueueSize)
  {
    state->revMapQueue = gt_realloc(state->revMapQueue,
                                    len * sizeof (state->revMapQueue[0]));
    state->revMapQueueSize = len;
  }
  if (state->sprTable && len > state->origRanksQueueSize)
  {
    state->origRanksQueue = gt_realloc(state->origRanksQueue,
                                          len *
                                          sizeof (state->origRanksQueue[0]));
    state->origRanksQueueSize = len;
  }
  bitsPerBWTPos = requiredUlongBits(len - 1);
  bitsPerOrigPos = state->bitsPerOrigPos;
  bitsPerOrigRank = state->bitsPerOrigRank;
  {
    GtUword i, mapVal;
    size_t revMapQueueLen = 0, origRanksQueueLen = 0;
    int reversiblySorted = state->featureToggles & BWTReversiblySorted,
      locateBitmap = state->featureToggles & BWTLocateBitmap;
    /* read len suffix array indices from suftab */
    /* TODO: decide  on reasonable buffering of mapVal */
    for (i = 0; i < len; ++i)
    {
      /* add locate data if necessary */
      if (locateInterval)
      {
        int insertExtraLocateMark = 0;
        /* 1.a read array index*/
        if ((retcode = SDRRead(state->readUlong, &mapVal, 1)) != 1)
          return (BitOffset)-1;
        /* 1.b find current symbol and compare to special ranges */
        insertExtraLocateMark = !reversiblySorted &&
          isSortModeTransition(state->origSeqAccess, state->seqLen,
                               state->alphabet, state->rangeSort,
                               mapVal);
        /* 1.c check wether the index into the original sequence is an
         * even multiple of the sampling interval, or a not-reversible
         * sort mode transition occurred */
        if (!(mapVal % locateInterval) || insertExtraLocateMark)
        {
          /* 1.c.1 enter index into cache */
          state->revMapQueue[revMapQueueLen].bwtPos = i;
          state->revMapQueue[revMapQueueLen].origPos
            = reversiblySorted ? mapVal/state->locateInterval : mapVal;
          ++revMapQueueLen;
          /* 1.c.2 mark position in bwt sequence */
          if (locateBitmap)
            bsSetBit(cwDest, cwOffset + i);
        }
        else
          if (locateBitmap)
            gt_bsClearBit(cwDest, cwOffset + i);
      }
      /* and add data for extra sort information */
      if (bitsPerOrigRank)
      {
        Symbol BWTSym;
        const MRAEnc *alphabet = state->alphabet;
        if (mapVal != 0)
          accessSequence(state->origSeqAccess, &BWTSym, mapVal - 1, 1);
        else
          BWTSym = GT_UNDEFBWTCHAR;
        if (state->rangeSort[MRAEncGetRangeOfSymbol(
                alphabet, MRAEncMapSymbol(alphabet, BWTSym))]
            == SORTMODE_RANK)
        {
          state->origRanksQueue[origRanksQueueLen++] =
            specialsRank(state->sprTable,
                         mapVal != 0 ? mapVal - 1 : state->seqLen - 1);
        }
      }
      if (state->ctxFactory)
      {
        gt_BWTSCRFMapAdvance(state->ctxFactory, &mapVal, 1);
      }
    }
    /* 2. copy revMapQueue into output */
    if (locateInterval)
    {
      int locateCount = state->featureToggles & BWTLocateCount;
      if (locateCount)
      {
        unsigned bitsPerCount = requiredUlongBits(len);
        gt_bsStoreUlong(varDest, varOffset + bitsWritten, bitsPerCount,
                      revMapQueueLen);
        bitsWritten += bitsPerCount;
      }
      for (i = 0; i < revMapQueueLen; ++i)
      {
        if (locateCount)
        {
          gt_bsStoreUlong(varDest, varOffset + bitsWritten, bitsPerBWTPos,
                        state->revMapQueue[i].bwtPos);
          bitsWritten += bitsPerBWTPos;
        }
        gt_bsStoreUlong(varDest, varOffset + bitsWritten, bitsPerOrigPos,
                      state->revMapQueue[i].origPos);
        bitsWritten += bitsPerOrigPos;
      }
    }
    if (bitsPerOrigRank)
    {
      unsigned bitsPerOrigRank = state->bitsPerOrigRank;
      if (origRanksQueueLen)
      {
        gt_bsStoreUniformUlongArray(varDest, varOffset + bitsWritten,
                                  bitsPerOrigRank, origRanksQueueLen,
#if defined (_LP64) || defined (_WIN64)
                             (uint64_t*) state->origRanksQueue);
#else
                             (uint32_t*) state->origRanksQueue);
#endif
        bitsWritten += bitsPerOrigRank * origRanksQueueLen;
      }
    }
  }
  return bitsWritten;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, 0x50(%rsp)
testq %rdx, %rdx
je 0x19abdd
movq 0xa0(%rsp), %rbx
testq %rbx, %rbx
je 0x19abdd
movq %r9, %r12
movq %rcx, %r14
movq %rdx, %r15
movq %rdi, %r13
movl 0x40(%rbx), %eax
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x19a748
cmpq %r12, 0x60(%rbx)
jae 0x19a748
movq 0x68(%rbx), %rdi
movq %r12, %rsi
shlq $0x4, %rsi
leaq 0x207eda(%rip), %rdx    # 0x3a2610
movl $0x190, %ecx            # imm = 0x190
callq 0x104461
movq %rax, 0x68(%rbx)
movq %r12, 0x60(%rbx)
cmpq $0x0, 0x50(%rbx)
je 0x19a77a
cmpq %r12, 0x70(%rbx)
jae 0x19a77a
movq 0x78(%rbx), %rdi
leaq (,%r12,8), %rsi
leaq 0x207ea8(%rip), %rdx    # 0x3a2610
movl $0x197, %ecx            # imm = 0x197
callq 0x104461
movq %rax, 0x78(%rbx)
movq %r12, 0x70(%rbx)
movq %r15, 0x38(%rsp)
movq %r14, 0x30(%rsp)
leaq -0x1(%r12), %rdi
callq 0x2f09dd
movl %eax, 0x20(%rsp)
movl 0x44(%rbx), %eax
movq %rax, 0x60(%rsp)
movl 0x4c(%rbx), %eax
movl %eax, 0x24(%rsp)
cmpq $0x1, %r12
jae 0x19a7b7
movq $0x0, 0x28(%rsp)
xorl %ebp, %ebp
jmp 0x19aaa1
movq %r13, 0x48(%rsp)
movl 0x58(%rbx), %eax
movl %eax, 0x8(%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
movq $0x0, 0x28(%rsp)
movq %r12, 0x40(%rsp)
cmpq $0x0, 0x18(%rsp)
je 0x19a9cc
movq 0x20(%rbx), %rdi
movl $0x1, %edx
leaq 0x10(%rsp), %rsi
callq *0x28(%rbx)
cmpl $0x1, %eax
jne 0x19aba1
testb $0x4, 0x8(%rsp)
jne 0x19a84e
movq (%rbx), %rdx
movq 0x10(%rbx), %r15
movq 0x18(%rbx), %r14
movq 0x10(%rsp), %rax
movq 0x30(%rbx), %r8
movq 0x38(%rbx), %rdi
testq %rax, %rax
sete %cl
leaq -0x1(%rdx), %rsi
cmpq %rax, %rsi
setbe %sil
orb %cl, %sil
jne 0x19a855
decq %rax
movl $0x2, %ecx
leaq 0x5(%rsp), %rsi
movq %rax, %rdx
callq *%r8
cmpl $0x2, %eax
je 0x19a898
jmp 0x19abce
xorl %ecx, %ecx
jmp 0x19a927
testq %rax, %rax
je 0x19a87b
addq $-0x2, %rdx
movl $0x1, %ecx
leaq 0x5(%rsp), %rsi
callq *%r8
cmpl $0x1, %eax
jne 0x19abe2
movb $-0x2, 0x6(%rsp)
jmp 0x19a898
movl $0x1, %ecx
leaq 0x6(%rsp), %rsi
xorl %edx, %edx
callq *%r8
cmpl $0x1, %eax
jne 0x19abe7
movb $-0x2, 0x5(%rsp)
movq %rbp, 0x58(%rsp)
cmpl $0x1, (%r15)
jne 0x19abba
movq %r14, %rbp
movzbl 0x5(%rsp), %eax
movzbl 0x18(%r15,%rax), %r14d
movq %r15, %rdi
callq 0x19e077
cmpw %r14w, %ax
jbe 0x19abc4
movq 0x8(%r15), %rax
xorl %ecx, %ecx
movl %ecx, %r12d
incl %ecx
cmpw %r14w, (%rax,%r12,2)
jbe 0x19a8cd
cmpl $0x1, (%r15)
jne 0x19abba
movzbl 0x6(%rsp), %eax
movzbl 0x18(%r15,%rax), %r14d
movq %r15, %rdi
callq 0x19e077
cmpw %r14w, %ax
jbe 0x19abc9
movq 0x8(%r15), %rax
xorl %ecx, %ecx
movl %ecx, %edx
incl %ecx
cmpw %r14w, (%rax,%rdx,2)
jbe 0x19a906
movl (%rbp,%r12,4), %eax
cmpl (%rbp,%rdx,4), %eax
setne %cl
movq 0x40(%rsp), %r12
movq 0x58(%rsp), %rbp
movq 0x10(%rsp), %rax
xorl %edx, %edx
divq 0x18(%rsp)
testq %rdx, %rdx
je 0x19a970
testb %cl, %cl
jne 0x19a970
testb $0x1, 0x8(%rsp)
je 0x19a9cc
movq 0x48(%rsp), %rsi
testq %rsi, %rsi
je 0x19abd3
movq 0x50(%rsp), %rax
leaq (%rax,%r13), %rcx
movq %rcx, %rax
notb %cl
movb $-0x2, %dl
rolb %cl, %dl
shrq $0x3, %rax
andb %dl, (%rsi,%rax)
jmp 0x19a9cc
movq %rbp, %rcx
shlq $0x4, %rcx
movq 0x68(%rbx), %rsi
movq %r13, (%rsi,%rcx)
movq 0x10(%rsp), %rax
testb $0x4, 0x8(%rsp)
je 0x19a993
movl 0x40(%rbx), %edi
xorl %edx, %edx
divq %rdi
incq %rbp
movq %rax, 0x8(%rsi,%rcx)
testb $0x1, 0x8(%rsp)
je 0x19a9cc
movq 0x48(%rsp), %rsi
testq %rsi, %rsi
je 0x19abd8
movq 0x50(%rsp), %rax
leaq (%rax,%r13), %rcx
movq %rcx, %rax
notb %cl
andb $0x7, %cl
movb $0x1, %dl
shlb %cl, %dl
shrq $0x3, %rax
orb %dl, (%rsi,%rax)
cmpl $0x0, 0x24(%rsp)
je 0x19aa7a
movq 0x10(%rbx), %r15
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
je 0x19a9fb
decq %rdx
movq 0x38(%rbx), %rdi
movl $0x1, %ecx
leaq 0x7(%rsp), %rsi
callq *0x30(%rbx)
jmp 0x19aa00
movb $-0x2, 0x7(%rsp)
cmpl $0x1, (%r15)
jne 0x19abba
movq 0x18(%rbx), %r14
movzbl 0x7(%rsp), %eax
movzbl 0x18(%r15,%rax), %r12d
movq %r15, %rdi
callq 0x19e077
cmpw %r12w, %ax
jbe 0x19abbf
movq 0x8(%r15), %rax
xorl %ecx, %ecx
movl %ecx, %edx
incl %ecx
cmpw %r12w, (%rax,%rdx,2)
jbe 0x19aa31
cmpl $0x2, (%r14,%rdx,4)
jne 0x19aa75
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
movq 0x40(%rsp), %r12
jne 0x19aa55
movq (%rbx), %rsi
movq 0x50(%rbx), %rdi
decq %rsi
callq *(%rdi)
movq 0x78(%rbx), %rcx
movq 0x28(%rsp), %rdx
movq %rax, (%rcx,%rdx,8)
incq %rdx
movq %rdx, 0x28(%rsp)
jmp 0x19aa7a
movq 0x40(%rsp), %r12
movq 0x80(%rbx), %rdi
testq %rdi, %rdi
je 0x19aa95
movl $0x1, %edx
leaq 0x10(%rsp), %rsi
callq 0x199642
incq %r13
cmpq %r12, %r13
jne 0x19a7d6
cmpq $0x0, 0x18(%rsp)
je 0x19aabe
movl 0x58(%rbx), %eax
movl %eax, 0x18(%rsp)
testb $0x2, %al
movq 0x38(%rsp), %r13
jne 0x19aacb
xorl %r15d, %r15d
jmp 0x19aaeb
xorl %r15d, %r15d
movq 0x38(%rsp), %r13
jmp 0x19ab69
movq %r12, %rdi
callq 0x2f09dd
movl %eax, %r15d
movq %r13, %rdi
movq 0x30(%rsp), %rsi
movl %eax, %edx
movq %rbp, %rcx
callq 0x2f388c
movl %r15d, %r15d
testq %rbp, %rbp
je 0x19ab69
movl 0x20(%rsp), %eax
movq %rax, 0x8(%rsp)
xorl %r12d, %r12d
movq 0x68(%rbx), %rax
testb $0x2, 0x18(%rsp)
jne 0x19ab13
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r13
jmp 0x19ab3d
movq %rbx, %r14
movq 0x30(%rsp), %rbx
leaq (%r15,%rbx), %rsi
movq (%rax,%r12), %rcx
movq 0x38(%rsp), %r13
movq %r13, %rdi
movl 0x20(%rsp), %edx
callq 0x2f388c
addq 0x8(%rsp), %r15
movq 0x68(%r14), %rax
leaq (%r15,%rbx), %rsi
movq 0x8(%rax,%r12), %rcx
movq %r13, %rdi
movq 0x60(%rsp), %rbx
movl %ebx, %edx
callq 0x2f388c
addq %rbx, %r15
addq $0x10, %r12
decq %rbp
movq 0xa0(%rsp), %rbx
jne 0x19aafc
cmpl $0x0, 0x24(%rsp)
je 0x19aba8
movq 0x28(%rsp), %r14
testq %r14, %r14
je 0x19aba8
movl 0x4c(%rbx), %r12d
movq 0x30(%rsp), %rsi
addq %r15, %rsi
movq 0x78(%rbx), %r8
movq %r13, %rdi
movl %r12d, %edx
movq %r14, %rcx
callq 0x2f3d9c
imulq %r12, %r14
addq %r14, %r15
jmp 0x19aba8
movq $-0x1, %r15
movq %r15, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x173b0
callq 0x5ef58
callq 0x5ee78
callq 0x5eeaf
callq 0x5ee3f
callq 0x5eee6
callq 0x5ef1f
callq 0x5ed94
callq 0x5edcd
callq 0x5ee06