// File: /workspace/github_c_makefile_star2_O1/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 0xc0450
movq %rsi, %r14
testq %rsi, %rsi
je 0xc0450
movq %rcx, %r12
movl %edx, %ebp
movq %rdi, %rbx
movq (%rdi), %rdi
cmpq %r14, %rdi
je 0xc026b
testq %rdi, %rdi
je 0xc0249
callq 0xc1690
movq 0x398(%r14), %rdi
callq 0x3d9b7
incq 0x390(%r14)
movq 0x398(%r14), %rdi
callq 0x3d9d2
movq %r14, (%rbx)
cmpq $0x0, (%rbx)
je 0xc0455
movl %ebp, %eax
andl $-0x3, %eax
cmpl $0x1, %eax
jne 0xc0286
notq %r12
addq 0x38(%r14), %r12
movl %ebp, 0xc(%rbx)
cmpb $0x1, 0x3a8(%r14)
jne 0xc02a3
movq 0x30(%r14), %rax
movq %rax, %rcx
subq %r12, %rcx
jbe 0xc03c9
movq %r12, %r15
cmpq 0x30(%r14), %r15
ja 0xc045a
movl %ebp, 0x8(%rbx)
movq %r15, 0x10(%rbx)
cmpb $0x1, 0x3a9(%r14)
jne 0xc0366
cmpb $0x1, 0x29(%r14)
jne 0xc0306
cmpq $0x0, 0x28(%rbx)
jne 0xc02f2
leaq 0x42750(%rip), %rdx     # 0x102a2a
movl $0x1, %edi
movl $0x40, %esi
movl $0xc1a, %ecx            # imm = 0xC1A
callq 0x3601f
movq %rax, 0x28(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xbf6bb
movq %rbx, %rdi
xorl %esi, %esi
callq 0xbfe27
movq (%rbx), %rax
cmpq $0x2, 0x40(%rax)
jb 0xc0447
cmpl $0x7, 0x4(%rax)
je 0xc045f
cmpq $0x0, 0x30(%rbx)
jne 0xc0344
leaq 0x426fe(%rip), %rdx     # 0x102a2a
movl $0x1, %edi
movl $0x40, %esi
movl $0xc2a, %ecx            # imm = 0xC2A
callq 0x3601f
movq %rax, 0x30(%rbx)
movq %rbx, %rdi
movl $0x1, %esi
callq 0xbf6bb
movq %rbx, %rdi
movl $0x1, %esi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xbfe27
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0xc0388
leaq 0x426b4(%rip), %rsi     # 0x102a2a
movl $0xc38, %edx            # imm = 0xC38
callq 0x362a0
movq $0x0, 0x28(%rbx)
movq 0x30(%rbx), %rdi
testq %rdi, %rdi
je 0xc03aa
leaq 0x42692(%rip), %rsi     # 0x102a2a
movl $0xc3c, %edx            # imm = 0xC3C
callq 0x362a0
movq $0x0, 0x30(%rbx)
cmpl $0x2, (%r14)
jne 0xc0447
movq (%rbx), %rdi
movq %r15, %rsi
callq 0xbf160
testb %al, %al
je 0xc03eb
movq %r15, 0x18(%rbx)
jmp 0xc0447
sete 0x20(%rbx)
leaq (%rcx,%rax), %r15
cmpl $0x3, %ebp
je 0xc041b
cmpl $0x1, %ebp
jne 0xc042b
xorl %ebp, %ebp
cmpq %r12, %rax
setne %bpl
incl %ebp
jmp 0xc02a6
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 0xc043c
cmpq %r15, %rsi
jbe 0xc0439
movq $0x0, 0x18(%rbx)
jmp 0xc0447
xorl %ecx, %ecx
cmpq %r12, %rax
sete %cl
leal (%rcx,%rcx,2), %ebp
jmp 0xc02a6
movl $0x3, %eax
subl %ebp, %eax
movl %eax, %ebp
jmp 0xc02a6
decq %rax
imulq %rsi, %rax
addq %rcx, %rax
movq %rax, 0x18(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
callq 0x2aaa9
callq 0x2ab54
callq 0x2ab1b
callq 0x2aae2