// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/core/encseq.c
// Function: gt_encseq_reader_reinit_with_readmode
void gt_encseq_reader_reinit_with_readmode(GtEncseqReader *esr,
                                           const GtEncseq *encseq,
                                           GtReadmode readmode,
                                           GtUword startpos)
{
  gt_assert(esr != NULL && encseq != NULL);
  if (encseq != esr->encseq) {
    if (esr->encseq != NULL)
      gt_encseq_delete(esr->encseq);
    esr->encseq = gt_encseq_ref((GtEncseq*) encseq);
  }
  gt_assert(esr->encseq);

  /* translate reverse positions into forward positions */
  if (GT_ISDIRREVERSE(readmode))
    startpos = GT_REVERSEPOS(encseq->logicaltotallength, startpos);
  esr->originalreadmode = readmode;

  /* if inside virtual mirror sequence, adjust start position and reading
     direction */
  if (encseq->hasmirror) {
    if (startpos >= encseq->totallength) {
      esr->startedonmiddle = (startpos == encseq->totallength);
      startpos = GT_REVERSEPOS(encseq->totallength,
                               startpos - encseq->totallength - 1);
      switch (readmode) {
        case GT_READMODE_REVERSE:
          if (esr->startedonmiddle)
            readmode = GT_READMODE_REVERSE;
          else
            gt_readmode_invert(readmode);
          break;
        case GT_READMODE_REVCOMPL:
          if (esr->startedonmiddle)
            readmode = GT_READMODE_REVCOMPL;
          else
            gt_readmode_invert(readmode);
          break;
        default:
          gt_readmode_invert(readmode);
          break;
      }
    }
  }
  gt_assert(startpos <= encseq->totallength);
  esr->readmode = readmode;
  esr->currentpos = startpos;
  if (encseq->accesstype_via_utables) {
    /* Do not need this in once all is done by wildcards */
    if (encseq->has_wildcardranges) {
      if (esr->wildcardrangestate == NULL) {
        esr->wildcardrangestate =
          gt_calloc((size_t) 1, sizeof (*esr->wildcardrangestate));
      }
      binpreparenextrangeGtEncseqReader(esr, SWtable_wildcardrange);
#ifdef GT_RANGEDEBUG
      printf("wildcardranges: start advance "
             "at ("GT_WU", "GT_WU") in page "GT_WU"\n",
                       esr->wildcardrangestate->firstcell,
                       esr->wildcardrangestate->lastcell,
                       esr->wildcardrangestate->nextpage);
#endif
      advancerangeGtEncseqReader(esr, SWtable_wildcardrange);
    }
    if (esr->encseq->numofdbsequences > 1UL) {
      gt_assert(esr->encseq->satsep != GT_ACCESS_TYPE_UNDEFINED);
      if (esr->ssptabstate == NULL) {
        esr->ssptabstate =
          gt_calloc((size_t) 1, sizeof (*esr->ssptabstate));
      }
      binpreparenextrangeGtEncseqReader(esr, SWtable_ssptab);
#ifdef GT_RANGEDEBUG
      printf("ssptab: start advance at ("GT_WU", "GT_WU") in page "GT_WU"\n",
                       esr->ssptabstate->firstcell,
                       esr->ssptabstate->lastcell,
                       esr->ssptabstate->nextpage);
#endif
      advancerangeGtEncseqReader(esr, SWtable_ssptab);
    }
  }
  else {
    if (esr->wildcardrangestate != NULL) {
      gt_free(esr->wildcardrangestate);
      esr->wildcardrangestate = NULL;
    }
    if (esr->ssptabstate != NULL) {
      gt_free(esr->ssptabstate);
      esr->ssptabstate = NULL;
    }
    if (encseq->sat == GT_ACCESS_TYPE_EQUALLENGTH) {
      if (issinglepositioninspecialrangeViaequallength(esr->encseq, startpos)) {
        esr->nextseparatorpos = startpos;
      }
      else {
        GtUword seqnum = (startpos + 1)/
                               (encseq->equallength.valueunsignedlong + 1);
        if (!GT_ISDIRREVERSE(esr->readmode)) {
          esr->nextseparatorpos = encseq->equallength.valueunsignedlong +
                                  seqnum *
                                  (encseq->equallength.valueunsignedlong + 1);
        }
        else {
          if (seqnum > 0) {
            esr->nextseparatorpos = encseq->equallength.valueunsignedlong +
                                    (seqnum-1) *
                                    (encseq->equallength.valueunsignedlong + 1);
          }
          else {
            esr->nextseparatorpos = 0;
          }
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0xc14e0
movq %rsi, %r14
testq %rsi, %rsi
je 0xc14e0
movq %rcx, %r12
movl %edx, %ebp
movq %rdi, %rbx
movq (%rdi), %rdi
cmpq %r14, %rdi
je 0xc1311
testq %rdi, %rdi
je 0xc12ec
callq 0xc273d
movq 0x398(%r14), %rdi
callq 0x3d043
incq 0x390(%r14)
movq 0x398(%r14), %rdi
callq 0x3d05e
movq %r14, (%rbx)
movq %r14, %rdi
movl %ebp, %eax
andl $-0x3, %eax
cmpl $0x1, %eax
jne 0xc1322
notq %r12
addq 0x38(%r14), %r12
movl %ebp, 0xc(%rbx)
movq 0x30(%r14), %rax
cmpq %r12, %rax
setbe %cl
andb 0x3a8(%r14), %cl
cmpb $0x1, %cl
jne 0xc1360
movq %rax, %rcx
subq %r12, %rcx
sete 0x20(%rbx)
leaq (%rcx,%rax), %r15
cmpl $0x3, %ebp
je 0xc1365
cmpl $0x1, %ebp
jne 0xc1372
xorl %ebp, %ebp
cmpq %r12, %rax
setne %bpl
incl %ebp
jmp 0xc137b
movq %r12, %r15
jmp 0xc137b
xorl %ecx, %ecx
cmpq %r12, %rax
sete %cl
leal (%rcx,%rcx,2), %ebp
jmp 0xc137b
movl $0x3, %ecx
subl %ebp, %ecx
movl %ecx, %ebp
cmpq %rax, %r15
ja 0xc14e5
movl %ebp, 0x8(%rbx)
movq %r15, 0x10(%rbx)
cmpb $0x1, 0x3a9(%r14)
jne 0xc143a
cmpb $0x1, 0x29(%r14)
jne 0xc13dd
cmpq $0x0, 0x28(%rbx)
jne 0xc13c6
leaq 0x4156c(%rip), %rdx     # 0x10291a
movl $0x1, %edi
movl $0x40, %esi
movl $0xc1a, %ecx            # imm = 0xC1A
callq 0x359a6
movq %rax, 0x28(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xc06cb
movq %rbx, %rdi
xorl %esi, %esi
callq 0xc0ec5
movq (%rbx), %rdi
cmpq $0x2, 0x40(%rdi)
jb 0xc14d7
cmpl $0x7, 0x4(%rdi)
je 0xc14ea
cmpq $0x0, 0x30(%rbx)
jne 0xc1418
leaq 0x4151a(%rip), %rdx     # 0x10291a
movl $0x1, %edi
movl $0x40, %esi
movl $0xc2a, %ecx            # imm = 0xC2A
callq 0x359a6
movq %rax, 0x30(%rbx)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xc06cb
movq %rbx, %rdi
movl $0x1, %esi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xc0ec5
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0xc145c
leaq 0x414d0(%rip), %rsi     # 0x10291a
movl $0xc38, %edx            # imm = 0xC38
callq 0x35c27
movq $0x0, 0x28(%rbx)
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0xc147e
leaq 0x414ae(%rip), %rsi     # 0x10291a
movl $0xc3c, %edx            # imm = 0xC3C
callq 0x35c27
movq $0x0, 0x30(%rbx)
cmpl $0x2, (%r14)
jne 0xc14d7
movq (%rbx), %rdi
movq %r15, %rsi
callq 0xc0168
testb %al, %al
je 0xc1499
movq %r15, 0x18(%rbx)
jmp 0xc14d7
incq %r15
movq 0x1f0(%r14), %rcx
leaq 0x1(%rcx), %rsi
movq %r15, %rax
xorl %edx, %edx
divq %rsi
movl 0x8(%rbx), %edx
orl $0x2, %edx
cmpl $0x3, %edx
jne 0xc14cc
cmpq %r15, %rsi
jbe 0xc14c9
movq $0x0, 0x18(%rbx)
jmp 0xc14d7
decq %rax
imulq %rsi, %rax
addq %rcx, %rax
movq %rax, 0x18(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x2a8ae
callq 0x2a920
callq 0x2a8e7