// File: /workspace/github_c_makefile_star2_O2/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 0x145497
movq 0xa0(%rsp), %r13
testq %r13, %r13
je 0x145497
movq %r9, %r15
movq %rcx, %rbx
movq %rdx, %r14
movq %rdi, %r12
movl 0x40(%r13), %eax
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x144fbd
cmpq %r15, 0x60(%r13)
jae 0x144fbd
movq 0x68(%r13), %rdi
movq %r15, %rsi
shlq $0x4, %rsi
leaq 0x1fd935(%rip), %rdx    # 0x3428e0
movl $0x190, %ecx            # imm = 0x190
callq 0x93472
movq %rax, 0x68(%r13)
movq %r15, 0x60(%r13)
movq %r12, 0x58(%rsp)
movq %r14, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
cmpq $0x0, 0x50(%r13)
je 0x144ffe
cmpq %r15, 0x70(%r13)
jae 0x144ffe
movq 0x78(%r13), %rdi
leaq (,%r15,8), %rsi
leaq 0x1fd8f4(%rip), %rdx    # 0x3428e0
movl $0x197, %ecx            # imm = 0x197
callq 0x93472
movq %rax, 0x78(%r13)
movq %r15, 0x70(%r13)
leaq -0x1(%r15), %rdi
callq 0x28a939
movl %eax, 0x28(%rsp)
movl 0x44(%r13), %eax
movq %rax, 0x60(%rsp)
movl 0x4c(%r13), %eax
movl %eax, 0x2c(%rsp)
movl 0x58(%r13), %eax
movl %eax, 0x10(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
xorl %ebp, %ebp
movq %r15, 0x48(%rsp)
cmpq %rbp, %r15
je 0x145294
cmpq $0x0, 0x20(%rsp)
je 0x1451ed
movq 0x20(%r13), %rdi
leaq 0x18(%rsp), %rsi
pushq $0x1
popq %rdx
callq *0x28(%r13)
cmpl $0x1, %eax
jne 0x1452b7
testb $0x4, 0x10(%rsp)
jne 0x1450b4
movq %r12, 0x40(%rsp)
movq (%r13), %rdx
movq 0x10(%r13), %r15
movq 0x18(%r13), %r12
movq 0x18(%rsp), %rax
movq 0x30(%r13), %r8
movq 0x38(%r13), %rdi
testq %rax, %rax
sete %cl
leaq -0x1(%rdx), %rsi
cmpq %rax, %rsi
setbe %sil
orb %cl, %sil
jne 0x1450bb
decq %rax
leaq 0xd(%rsp), %rsi
movq %rax, %rdx
pushq $0x2
popq %rcx
callq *%r8
cmpl $0x2, %eax
je 0x1450fa
jmp 0x1453a8
xorl %ecx, %ecx
jmp 0x145147
testq %rax, %rax
je 0x1450df
addq $-0x2, %rdx
leaq 0xd(%rsp), %rsi
pushq $0x1
popq %rcx
callq *%r8
cmpl $0x1, %eax
jne 0x14543b
movb $-0x2, 0xe(%rsp)
jmp 0x1450fa
leaq 0xe(%rsp), %rsi
xorl %edx, %edx
pushq $0x1
popq %rcx
callq *%r8
cmpl $0x1, %eax
jne 0x145469
movb $-0x2, 0xd(%rsp)
movzbl 0xd(%rsp), %esi
movq %r15, %rdi
callq 0x14603f
movzbl %al, %esi
movq %r15, %rdi
callq 0x1460aa
movl %eax, %r14d
movzbl 0xe(%rsp), %esi
movq %r15, %rdi
callq 0x14603f
movzbl %al, %esi
movq %r15, %rdi
callq 0x1460aa
movl %r14d, %ecx
movl (%r12,%rcx,4), %ecx
movl %eax, %eax
cmpl (%r12,%rax,4), %ecx
setne %cl
movq 0x40(%rsp), %r12
movq 0x48(%rsp), %r15
movq 0x18(%rsp), %rax
xorl %edx, %edx
divq 0x20(%rsp)
testq %rdx, %rdx
je 0x145190
testb %cl, %cl
jne 0x145190
testb $0x1, 0x10(%rsp)
je 0x1451ed
movq 0x58(%rsp), %rsi
testq %rsi, %rsi
je 0x1453d9
movq 0x50(%rsp), %rax
leaq (%rax,%rbp), %rcx
movq %rcx, %rax
notb %cl
movb $-0x2, %dl
rolb %cl, %dl
shrq $0x3, %rax
andb %dl, (%rsi,%rax)
jmp 0x1451ed
movq %rbx, %rcx
shlq $0x4, %rcx
movq 0x68(%r13), %rsi
movq %rbp, (%rsi,%rcx)
movq 0x18(%rsp), %rax
testb $0x4, 0x10(%rsp)
je 0x1451b4
movl 0x40(%r13), %edi
xorl %edx, %edx
divq %rdi
incq %rbx
movq %rax, 0x8(%rsi,%rcx)
testb $0x1, 0x10(%rsp)
je 0x1451ed
movq 0x58(%rsp), %rsi
testq %rsi, %rsi
je 0x14540a
movq 0x50(%rsp), %rax
leaq (%rax,%rbp), %rcx
movq %rcx, %rax
notb %cl
andb $0x7, %cl
movb $0x1, %dl
shlb %cl, %dl
shrq $0x3, %rax
orb %dl, (%rsi,%rax)
cmpl $0x0, 0x2c(%rsp)
je 0x145273
movq 0x10(%r13), %r15
movq 0x18(%rsp), %rdx
testq %rdx, %rdx
je 0x14521b
decq %rdx
movq 0x38(%r13), %rdi
leaq 0xf(%rsp), %rsi
pushq $0x1
popq %rcx
callq *0x30(%r13)
movb 0xf(%rsp), %al
jmp 0x145222
movb $-0x2, 0xf(%rsp)
movb $-0x2, %al
movq 0x18(%r13), %r14
movzbl %al, %esi
movq %r15, %rdi
callq 0x14603f
movzbl %al, %esi
movq %r15, %rdi
callq 0x1460aa
movl %eax, %eax
cmpl $0x2, (%r14,%rax,4)
jne 0x14526e
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
movq 0x48(%rsp), %r15
jne 0x145258
movq (%r13), %rsi
movq 0x50(%r13), %rdi
decq %rsi
callq *(%rdi)
movq 0x78(%r13), %rcx
movq %rax, (%rcx,%r12,8)
incq %r12
jmp 0x145273
movq 0x48(%rsp), %r15
movq 0x80(%r13), %rdi
testq %rdi, %rdi
je 0x14528c
leaq 0x18(%rsp), %rsi
pushq $0x1
popq %rdx
callq 0x143b0e
incq %rbp
jmp 0x145030
cmpq $0x0, 0x20(%rsp)
je 0x1452bf
movl 0x58(%r13), %eax
movl %eax, 0x20(%rsp)
testb $0x2, %al
movq %r12, 0x40(%rsp)
jne 0x1452cc
xorl %r14d, %r14d
movq 0x38(%rsp), %rbp
jmp 0x1452f3
pushq $-0x1
popq %rax
jmp 0x145399
xorl %r14d, %r14d
movq 0x38(%rsp), %rbp
jmp 0x145360
movq %r15, %rdi
callq 0x28a939
movl %eax, %ebp
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %r15
movq %r15, %rsi
movl %eax, %edx
movq %rbx, %rcx
callq 0x28dfac
movl %ebp, %r14d
movq %r15, %rbp
movl 0x28(%rsp), %eax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
subq $0x1, %rbx
jb 0x14535b
movq 0x68(%r13), %rax
testb $0x2, 0x20(%rsp)
jne 0x145317
movq 0x30(%rsp), %r15
jmp 0x145339
leaq (%r14,%rbp), %rsi
movq (%rax,%r12), %rcx
movq 0x30(%rsp), %r15
movq %r15, %rdi
movl 0x28(%rsp), %edx
callq 0x28dfac
addq 0x10(%rsp), %r14
movq 0x68(%r13), %rax
leaq (%r14,%rbp), %rsi
movq 0x8(%rax,%r12), %rcx
movq %r15, %rdi
movq 0x60(%rsp), %r15
movl %r15d, %edx
callq 0x28dfac
addq %r15, %r14
addq $0x10, %r12
jmp 0x1452ff
movq 0x40(%rsp), %r12
cmpl $0x0, 0x2c(%rsp)
sete %al
testq %r12, %r12
sete %cl
orb %al, %cl
jne 0x145396
movl 0x4c(%r13), %ebx
addq %r14, %rbp
movq 0x78(%r13), %r8
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
movl %ebx, %edx
movq %r12, %rcx
callq 0x28e640
imulq %rbx, %r12
addq %r12, %r14
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2f2bb9(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19fc5a(%rip), %rsi    # 0x2e5013
leaq 0x1fd8d7(%rip), %rdx    # 0x342c97
leaq 0x1fd8dd(%rip), %rcx    # 0x342ca4
leaq 0x1fd512(%rip), %r8     # 0x3428e0
movl $0x162, %r9d            # imm = 0x162
jmp 0x1454c3
movq 0x2f2b88(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19fc29(%rip), %rsi    # 0x2e5013
leaq 0x1ccc33(%rip), %rdx    # 0x312024
leaq 0x1bc143(%rip), %rcx    # 0x30153b
leaq 0x1bc0d2(%rip), %r8     # 0x3014d1
movl $0x17a, %r9d            # imm = 0x17A
jmp 0x1454c3
movq 0x2f2b57(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19fbf8(%rip), %rsi    # 0x2e5013
leaq 0x1ccc02(%rip), %rdx    # 0x312024
leaq 0x1bc109(%rip), %rcx    # 0x301532
leaq 0x1bc0a1(%rip), %r8     # 0x3014d1
movl $0x171, %r9d            # imm = 0x171
jmp 0x1454c3
movq 0x2f2b26(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19fbc7(%rip), %rsi    # 0x2e5013
leaq 0x1fd866(%rip), %rdx    # 0x342cb9
leaq 0x1fd84a(%rip), %rcx    # 0x342ca4
leaq 0x1fd47f(%rip), %r8     # 0x3428e0
movl $0x173, %r9d            # imm = 0x173
jmp 0x1454c3
movq 0x2f2af8(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19fb99(%rip), %rsi    # 0x2e5013
leaq 0x1fd838(%rip), %rdx    # 0x342cb9
leaq 0x1fd81c(%rip), %rcx    # 0x342ca4
leaq 0x1fd451(%rip), %r8     # 0x3428e0
movl $0x16a, %r9d            # imm = 0x16A
jmp 0x1454c3
movq 0x2f2aca(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19fb6b(%rip), %rsi    # 0x2e5013
leaq 0x1fd7c7(%rip), %rdx    # 0x342c76
leaq 0x1fd7d3(%rip), %rcx    # 0x342c89
leaq 0x1fd423(%rip), %r8     # 0x3428e0
movl $0x18a, %r9d            # imm = 0x18A
xorl %eax, %eax
callq 0x17a50
callq 0x17390