// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %rsi, 0x58(%rsp)
testq %rdx, %rdx
je 0x1a3114
movq 0xb0(%rsp), %rbx
testq %rbx, %rbx
je 0x1a3114
movq %r9, %r12
movq %rcx, %r14
movq %rdx, %r15
movq %rdi, %r13
movl 0x40(%rbx), %eax
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x1a2c80
cmpq %r12, 0x60(%rbx)
jae 0x1a2c80
movq 0x68(%rbx), %rdi
movq %r12, %rsi
shlq $0x4, %rsi
leaq 0x208f02(%rip), %rdx    # 0x3abb70
movl $0x190, %ecx            # imm = 0x190
callq 0x1094e6
movq %rax, 0x68(%rbx)
movq %r12, 0x60(%rbx)
cmpq $0x0, 0x50(%rbx)
je 0x1a2cb2
cmpq %r12, 0x70(%rbx)
jae 0x1a2cb2
movq 0x78(%rbx), %rdi
leaq (,%r12,8), %rsi
leaq 0x208ed0(%rip), %rdx    # 0x3abb70
movl $0x197, %ecx            # imm = 0x197
callq 0x1094e6
movq %rax, 0x78(%rbx)
movq %r12, 0x70(%rbx)
movq %r15, 0x40(%rsp)
movq %r14, 0x38(%rsp)
leaq -0x1(%r12), %rdi
callq 0x2f9d41
movl %eax, 0x28(%rsp)
movl 0x44(%rbx), %eax
movq %rax, 0x70(%rsp)
movl 0x4c(%rbx), %eax
movl %eax, 0x2c(%rsp)
cmpq $0x1, %r12
jae 0x1a2cef
movq $0x0, 0x30(%rsp)
xorl %ebp, %ebp
jmp 0x1a2fec
movq %r13, 0x50(%rsp)
movl 0x58(%rbx), %eax
movl %eax, 0x10(%rsp)
xorl %r13d, %r13d
xorl %ebp, %ebp
movq $0x0, 0x30(%rsp)
movq %r12, 0x48(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x1a2f17
movq 0x20(%rbx), %rdi
movl $0x1, %edx
leaq 0x18(%rsp), %rsi
callq *0x28(%rbx)
movl %eax, %r14d
cmpq $0x1, %r14
jne 0x1a2f0d
testb $0x4, 0x10(%rsp)
jne 0x1a2d8a
movq (%rbx), %rdx
movq 0x10(%rbx), %r15
movq 0x18(%rbx), %r12
movq 0x18(%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 0x1a2d91
decq %rax
movl $0x2, %ecx
leaq 0xd(%rsp), %rsi
movq %rax, %rdx
callq *%r8
cmpl $0x2, %eax
je 0x1a2dd4
jmp 0x1a3119
xorl %ecx, %ecx
jmp 0x1a2e68
testq %rax, %rax
je 0x1a2db7
addq $-0x2, %rdx
movl $0x1, %ecx
leaq 0xd(%rsp), %rsi
callq *%r8
cmpl $0x1, %eax
jne 0x1a3128
movb $-0x2, 0xe(%rsp)
jmp 0x1a2dd4
movl $0x1, %ecx
leaq 0xe(%rsp), %rsi
xorl %edx, %edx
callq *%r8
cmpl $0x1, %eax
jne 0x1a312d
movb $-0x2, 0xd(%rsp)
movq %r14, 0x68(%rsp)
cmpl $0x1, (%r15)
jne 0x1a3100
movq %r12, 0x60(%rsp)
movzbl 0xd(%rsp), %eax
movzbl 0x18(%r15,%rax), %r14d
movq %r15, %rdi
callq 0x1a67a7
cmpw %r14w, %ax
jbe 0x1a310a
movq 0x8(%r15), %rax
xorl %ecx, %ecx
movl %ecx, %r12d
incl %ecx
cmpw %r14w, (%rax,%r12,2)
jbe 0x1a2e0b
cmpl $0x1, (%r15)
jne 0x1a3100
movzbl 0xe(%rsp), %eax
movzbl 0x18(%r15,%rax), %r14d
movq %r15, %rdi
callq 0x1a67a7
cmpw %r14w, %ax
jbe 0x1a310f
movq 0x8(%r15), %rax
xorl %ecx, %ecx
movl %ecx, %edx
incl %ecx
cmpw %r14w, (%rax,%rdx,2)
jbe 0x1a2e44
movq 0x60(%rsp), %rcx
movl (%rcx,%r12,4), %eax
cmpl (%rcx,%rdx,4), %eax
setne %cl
movq 0x48(%rsp), %r12
movq 0x68(%rsp), %r14
movq 0x18(%rsp), %rax
xorl %edx, %edx
divq 0x20(%rsp)
testq %rdx, %rdx
je 0x1a2eb1
testb %cl, %cl
jne 0x1a2eb1
testb $0x1, 0x10(%rsp)
je 0x1a2f0d
movq 0x50(%rsp), %rsi
testq %rsi, %rsi
je 0x1a311e
movq 0x58(%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 0x1a2f0d
movq %rbp, %rcx
shlq $0x4, %rcx
movq 0x68(%rbx), %rsi
movq %r13, (%rsi,%rcx)
movq 0x18(%rsp), %rax
testb $0x4, 0x10(%rsp)
je 0x1a2ed4
movl 0x40(%rbx), %edi
xorl %edx, %edx
divq %rdi
incq %rbp
movq %rax, 0x8(%rsi,%rcx)
testb $0x1, 0x10(%rsp)
je 0x1a2f0d
movq 0x50(%rsp), %rsi
testq %rsi, %rsi
je 0x1a3123
movq 0x58(%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 $0x1, %r14d
jne 0x1a30e7
cmpl $0x0, 0x2c(%rsp)
je 0x1a2fc5
movq 0x10(%rbx), %r15
movq 0x18(%rsp), %rdx
testq %rdx, %rdx
je 0x1a2f46
decq %rdx
movq 0x38(%rbx), %rdi
movl $0x1, %ecx
leaq 0xf(%rsp), %rsi
callq *0x30(%rbx)
jmp 0x1a2f4b
movb $-0x2, 0xf(%rsp)
cmpl $0x1, (%r15)
jne 0x1a3100
movq 0x18(%rbx), %r14
movzbl 0xf(%rsp), %eax
movzbl 0x18(%r15,%rax), %r12d
movq %r15, %rdi
callq 0x1a67a7
cmpw %r12w, %ax
jbe 0x1a3105
movq 0x8(%r15), %rax
xorl %ecx, %ecx
movl %ecx, %edx
incl %ecx
cmpw %r12w, (%rax,%rdx,2)
jbe 0x1a2f7c
cmpl $0x2, (%r14,%rdx,4)
jne 0x1a2fc0
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
movq 0x48(%rsp), %r12
jne 0x1a2fa0
movq (%rbx), %rsi
movq 0x50(%rbx), %rdi
decq %rsi
callq *(%rdi)
movq 0x78(%rbx), %rcx
movq 0x30(%rsp), %rdx
movq %rax, (%rcx,%rdx,8)
incq %rdx
movq %rdx, 0x30(%rsp)
jmp 0x1a2fc5
movq 0x48(%rsp), %r12
movq 0x80(%rbx), %rdi
testq %rdi, %rdi
je 0x1a2fe0
movl $0x1, %edx
leaq 0x18(%rsp), %rsi
callq 0x1a1b60
incq %r13
cmpq %r12, %r13
jne 0x1a2d0e
cmpq $0x0, 0x20(%rsp)
je 0x1a3009
movl 0x58(%rbx), %eax
movl %eax, 0x20(%rsp)
testb $0x2, %al
movq 0x40(%rsp), %r13
jne 0x1a3016
xorl %r15d, %r15d
jmp 0x1a3036
xorl %r15d, %r15d
movq 0x40(%rsp), %r13
jmp 0x1a30af
movq %r12, %rdi
callq 0x2f9d41
movl %eax, %r15d
movq %r13, %rdi
movq 0x38(%rsp), %rsi
movl %eax, %edx
movq %rbp, %rcx
callq 0x2fcd13
movl %r15d, %r15d
testq %rbp, %rbp
je 0x1a30af
movl 0x28(%rsp), %eax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
movq %rbx, %r14
testb $0x2, 0x20(%rsp)
jne 0x1a305d
movq 0x38(%rsp), %rbx
movq 0x40(%rsp), %r13
jmp 0x1a3084
movq 0x38(%rsp), %rbx
leaq (%r15,%rbx), %rsi
movq 0x68(%r14), %rax
movq (%rax,%r12), %rcx
movq 0x40(%rsp), %r13
movq %r13, %rdi
movl 0x28(%rsp), %edx
callq 0x2fcd13
addq 0x10(%rsp), %r15
leaq (%r15,%rbx), %rsi
movq 0x68(%r14), %rax
movq 0x8(%rax,%r12), %rcx
movq %r13, %rdi
movq 0x70(%rsp), %rbx
movl %ebx, %edx
callq 0x2fcd13
addq %rbx, %r15
addq $0x10, %r12
decq %rbp
movq %r14, %rbx
jne 0x1a3047
cmpl $0x0, 0x2c(%rsp)
je 0x1a30ee
movq 0x30(%rsp), %r14
testq %r14, %r14
je 0x1a30ee
movl 0x4c(%rbx), %r12d
movq 0x38(%rsp), %rsi
addq %r15, %rsi
movq 0x78(%rbx), %r8
movq %r13, %rdi
movl %r12d, %edx
movq %r14, %rcx
callq 0x2fd259
imulq %r12, %r14
addq %r14, %r15
jmp 0x1a30ee
movq $-0x1, %r15
movq %r15, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x173b0
callq 0x603cc
callq 0x602ec
callq 0x60323
callq 0x60208
callq 0x602b3
callq 0x6035a
callq 0x60393
callq 0x60241
callq 0x6027a