// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/match/eis-encidxseq.c
// Function: gt_EISVerifyIntegrity
enum EISIntegrityCheckResults
gt_EISVerifyIntegrity(EISeq *seqIdx, const char *projectName,
                      GtUword skip,
                      GtUword tickPrint, FILE *fp, int chkFlags,
                      GtLogger *verbosity, GtError *err)
{
  FILE *bwtFP;
  GtUword pos = 0,
                length = EISLength(seqIdx);
  Suffixarray suffixArray;
  Symbol symOrig;
  unsigned symEnc;
  EISHint hint;
  GtUword rankQueryResult, rankExpect;
  const MRAEnc *alphabet;
  AlphabetRangeSize alphabetSize;
  AlphabetRangeID numRanges;
  enum EISIntegrityCheckResults retval = EIS_INTEGRITY_CHECK_NO_ERROR;
  /* two part process: enumerate all positions of original sequence
   * and verify that the query functions return correct values */
  if (streamsuffixarray(&suffixArray, SARR_BWTTAB, projectName, verbosity, err))
  {
    gt_error_set(err, "Cannot load suffix array project with"
                  " demand for BWT file\n");
    return EIS_INTEGRITY_CHECK_SA_LOAD_ERROR;
  }
  bwtFP = suffixArray.bwttabstream.fp;
  hint = newEISHint(seqIdx);
  alphabet = EISGetAlphabet(seqIdx);
  alphabetSize = gt_MRAEncGetSize(alphabet);
  numRanges = MRAEncGetNumRanges(alphabet);
  do
  {
    GtUword rankTable[alphabetSize], rangeRanks[2][alphabetSize],
      pairRangeRanks[2* alphabetSize], lastRangeRankPos = 0;
    int symRead, rt = 0;
    AlphabetRangeID lastRangeID = 0;
    unsigned rankCmpSym;
    memset(rankTable, 0, sizeof (rankTable));
    memset(rangeRanks, 0, sizeof (rangeRanks));
    if (skip > 0)
    {
      unsigned sym;
      if (skip >= length)
      {
        gt_logger_log(verbosity, "Invalid skip request: "GT_LLD","
                    " too large for sequence length: "GT_WU"",
                    (GtInt64)skip, length);
        return -1;
      }
      fseeko(bwtFP, skip, SEEK_SET);
      for (sym = 0; sym <= (unsigned) GT_MAXALPHABETCHARACTER; ++sym)
        if (MRAEncSymbolHasValidMapping(alphabet, sym))
          rankTable[sym] = EISRank(seqIdx, sym, skip, hint);
      pos = skip;
    }
    while (retval == EIS_INTEGRITY_CHECK_NO_ERROR
           && (symRead = getc(bwtFP)) != EOF)
    {
      symOrig = MRAEncMapSymbol(alphabet, symRead);
      symEnc = EISGetTransformedSym(seqIdx, pos, hint);
      if (symEnc >= alphabetSize)
        verifyIntegrityErrRet(EIS_INTEGRITY_CHECK_INVALID_SYMBOL);
      if (symOrig >= alphabetSize)
        verifyIntegrityErrRet(EIS_INTEGRITY_CHECK_BWT_READ_ERROR);
      if (symEnc != symOrig)
        verifyIntegrityErrRet(EIS_INTEGRITY_CHECK_INVALID_SYMBOL);
      ++rankTable[symOrig];
      if (chkFlags & EIS_VERIFY_EXT_RANK)
      {
        for (rankCmpSym = 0; rankCmpSym < alphabetSize; ++rankCmpSym)
          if ((rankExpect = rankTable[rankCmpSym])
              != (rankQueryResult
                  = EISSymTransformedRank(seqIdx, rankCmpSym, pos + 1, hint)))
            verifyIntegrityErrRet(EIS_INTEGRITY_CHECK_RANK_FAILED);
      }
      else
      {
        rankCmpSym = symEnc;
        if ((rankExpect = rankTable[symEnc])
            != (rankQueryResult = EISSymTransformedRank(seqIdx, symEnc,
                                                        pos + 1, hint)))
          verifyIntegrityErrRet(EIS_INTEGRITY_CHECK_RANK_FAILED);
      }
      /* do rank for full range on some occasions */
      if (!(random() % AVG_RANGE_RANK_INTERVAL))
      {
        unsigned i;
        AlphabetRangeSize rangeSize;
        AlphabetRangeID range = random() % numRanges;
        Symbol rangeBase = MRAEncGetRangeBase(alphabet, range);
        rangeSize = MRAEncGetRangeSize(alphabet, range);
        EISRangeRank(seqIdx, range, pos + 1, rangeRanks[rt], hint);
        for (i = 0; i < rangeSize; ++i)
        {
          rankCmpSym = rangeBase + i;
          if ((rankQueryResult = rangeRanks[rt][i])
              != (rankExpect = rankTable[rankCmpSym]))
            verifyIntegrityErrRet(EIS_INTEGRITY_CHECK_RANK_FAILED);
        }
        if (retval)
          break;
        if (range == lastRangeID)
        {
          EISPosPairRangeRank(seqIdx, range, lastRangeRankPos, pos + 1,
                              pairRangeRanks, hint);
          for (i = 0; i < rangeSize; ++i)
          {
            rankCmpSym = rangeBase + i;
            if ((rankQueryResult = pairRangeRanks[rangeSize + i])
                != (rankExpect = rankTable[rankCmpSym]))
              verifyIntegrityErrRet(EIS_INTEGRITY_CHECK_RANK_FAILED);
            if ((rankQueryResult = pairRangeRanks[i])
                != (rankExpect = rangeRanks[rt ^ 1][i]))
              verifyIntegrityErrRet(EIS_INTEGRITY_CHECK_RANK_FAILED);
          }
          if (retval)
            break;
        }
        lastRangeID = range;
        lastRangeRankPos = pos + 1;
        rt ^= 1;
      }
      ++pos;
      if (tickPrint && !(pos % tickPrint))
        putc('.', fp);
    }
    if (retval)
      break;
    if (tickPrint)
      putc('\n', fp);
    if (ferror(bwtFP))
      verifyIntegrityErrRet(EIS_INTEGRITY_CHECK_BWT_READ_ERROR);
  } while (0);
  deleteEISHint(seqIdx, hint);
  gt_freesuffixarray(&suffixArray);
  return retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1a8, %rsp            # imm = 0x1A8
movl %r9d, -0x90(%rbp)
movq %r8, %r12
movq %rcx, %r15
movq %rdx, -0x40(%rbp)
movq %rsi, %rdx
movq %rdi, %rbx
movq 0x18(%rbp), %r14
movq 0x10(%rbp), %rcx
movq 0x10(%rdi), %r13
leaq -0x1d0(%rbp), %rdi
pushq $0x8
popq %rsi
movq %r14, %r8
callq 0x14d283
testl %eax, %eax
je 0x148468
leaq 0x1fb521(%rip), %rsi    # 0x343976
movq %r14, %rdi
xorl %eax, %eax
callq 0x89dbb
pushq $0x3
popq %r13
jmp 0x148a52
movq %r13, -0x58(%rbp)
movq %r15, -0xc0(%rbp)
movq %r12, -0xa0(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x80(%rbp)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x38(%rax)
movq %rax, -0x30(%rbp)
movq %rbx, -0x48(%rbp)
movq %rbx, %rdi
callq 0x148bb6
movq %rax, %rbx
movq %rax, %rdi
callq 0x14906a
movq %rsp, -0x98(%rbp)
movl 0x4(%rbx), %ecx
movl %ecx, -0x8c(%rbp)
movzwl %ax, %ecx
leal 0xf(,%rcx,8), %eax
andl $-0x10, %eax
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
movq %rsp, %r15
movl %ecx, %r14d
shll $0x4, %r14d
subq %r14, %r15
movq %r15, %rsp
movq %rsp, %rax
subq %r14, %rax
movq %rax, -0xb0(%rbp)
movq %rax, %rsp
movq %rcx, -0x70(%rbp)
leal (,%rcx,8), %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x17380
movq %r15, -0xb8(%rbp)
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %rbx, %r14
callq 0x17380
movq -0x40(%rbp), %rax
movq %rax, %r12
testq %rax, %rax
movq %rbx, -0x88(%rbp)
je 0x1485bf
movq %r12, %rdx
movq -0x58(%rbp), %rcx
cmpq %r12, %rcx
jbe 0x148925
xorl %ebx, %ebx
movq -0x80(%rbp), %rdi
movq %rdx, %rsi
xorl %edx, %edx
callq 0x17c70
cmpq $0x100, %rbx            # imm = 0x100
je 0x1485bf
cmpl $0x1, (%r14)
jne 0x148b51
movq 0x8(%r14), %rax
movl 0x4(%r14), %ecx
decl %ecx
cmpw $0xff, (%rax,%rcx,2)
movq %r12, %r15
je 0x14858a
movq %r14, %rdi
callq 0x148cc1
cmpb $-0x1, 0x18(%r14,%rbx)
je 0x1485ba
movq -0x48(%rbp), %r14
movq 0x8(%r14), %rdi
movzbl %bl, %esi
callq 0x148bf7
movq (%r14), %r8
movzbl %al, %esi
movq %r14, %rdi
movq -0x88(%rbp), %r14
movq %r15, %rdx
movq -0x30(%rbp), %rcx
callq *0x8(%r8)
movq %rax, (%r13,%rbx,8)
incq %rbx
jmp 0x148552
movq %r13, -0xd0(%rbp)
cmpq $0x0, -0x48(%rbp)
setne %al
cmpq $0x0, -0x30(%rbp)
setne %cl
andb %al, %cl
movb %cl, -0x31(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x60(%rbp)
movl $0x0, -0x4c(%rbp)
movq %r12, %r15
xorl %r12d, %r12d
movq %r15, -0x40(%rbp)
testl %r12d, %r12d
movq %r12, %r13
jne 0x148a31
movq -0x80(%rbp), %rdi
callq 0x171d0
cmpl $-0x1, %eax
je 0x148947
movzbl %al, %esi
movq %r14, %rdi
callq 0x148bf7
cmpb $0x0, -0x31(%rbp)
je 0x148b56
movl %eax, %r14d
movq -0x48(%rbp), %rbx
movq (%rbx), %rax
movq %rbx, %rdi
movq -0x40(%rbp), %r15
movq %r15, %rsi
movq -0x30(%rbp), %rdx
callq *0x30(%rax)
movzbl %al, %r12d
movzbl %r14b, %ecx
movq -0x70(%rbp), %rdx
cmpl %edx, %r12d
movq -0xd0(%rbp), %r13
jae 0x148a64
cmpl %edx, %ecx
jae 0x148a9f
cmpb %r14b, %al
jne 0x148a64
movq (%r13,%rcx,8), %r14
incq %r14
incq %r15
movq %r14, (%r13,%rcx,8)
testb $0x1, -0x90(%rbp)
jne 0x148701
movq %rbx, %rdi
movl %ecx, %esi
movq %r15, %rdx
movq -0x30(%rbp), %rcx
callq 0x148c1d
cmpq %rax, %r14
jne 0x148aee
xorl %r12d, %r12d
movb $0x1, %al
movl %eax, -0x58(%rbp)
callq 0xb3a58
testb $0x7f, %al
movq -0x88(%rbp), %r14
jne 0x148873
callq 0xb3a58
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
xorl %edx, %edx
divl -0x8c(%rbp)
cmpl %edx, 0x4(%r14)
jbe 0x148b80
movl %edx, %esi
testl %edx, %edx
movq -0x70(%rbp), %rdi
movq %r12, -0xc8(%rbp)
je 0x148733
movq 0x8(%r14), %rcx
movl %esi, %eax
movzbl -0x2(%rcx,%rax,2), %r15d
jmp 0x148738
xorl %r12d, %r12d
cmpq %r12, %rdx
je 0x1486aa
movq (%r13,%r12,8), %r14
movzbl %r12b, %esi
movq %rbx, %rdi
movq %r15, %rdx
movq -0x30(%rbp), %rcx
callq 0x148c1d
cmpq %rax, %r14
jne 0x1488a8
incq %r12
movq -0x70(%rbp), %rdx
jmp 0x148704
xorl %eax, %eax
xorl %r15d, %r15d
movq 0x10(%r14), %rcx
movzwl (%rcx,%rax,2), %r12d
movq -0x40(%rbp), %rax
leaq 0x1(%rax), %rdx
movl -0x60(%rbp), %eax
imulq %rdi, %rax
movq -0xb8(%rbp), %rcx
leaq (%rcx,%rax,8), %r14
movq (%rbx), %rax
movq %rbx, %rdi
movl %esi, -0x64(%rbp)
movq %rdx, -0xa8(%rbp)
movq %r14, %rcx
movq -0x30(%rbp), %r8
callq *0x18(%rax)
leaq (,%r15,8), %rbx
addq %r13, %rbx
xorl %eax, %eax
movq -0xb0(%rbp), %r9
cmpq %rax, %r12
je 0x1487a3
movq (%r14,%rax,8), %rcx
movq (%rbx,%rax,8), %r8
incq %rax
cmpq %r8, %rcx
je 0x148789
jmp 0x1489b4
cmpb $0x0, -0x58(%rbp)
movq -0x88(%rbp), %r14
movq -0xc8(%rbp), %r13
je 0x148a31
movl -0x4c(%rbp), %esi
movl -0x64(%rbp), %ecx
cmpl %esi, %ecx
jne 0x148842
movq -0x48(%rbp), %rdi
movq (%rdi), %rax
movq -0x78(%rbp), %rdx
movq -0xa8(%rbp), %r13
movq %r13, %rcx
movq %r9, %r8
movq -0x30(%rbp), %r9
callq *0x20(%rax)
movq -0xb0(%rbp), %rdi
movq -0x60(%rbp), %rax
xorl $0x1, %eax
movq %rax, -0x60(%rbp)
imulq -0x70(%rbp), %rax
movq -0xb8(%rbp), %rcx
leaq (%rcx,%rax,8), %rax
shll $0x3, %r12d
leaq (%rdi,%r12), %rdx
negl %r15d
xorl %esi, %esi
cmpq %rsi, %r12
je 0x148863
movq (%rdx,%rsi), %rcx
movq (%rbx,%rsi), %r8
cmpq %r8, %rcx
jne 0x1489d5
movq (%rdi,%rsi), %rcx
movq (%rax,%rsi), %r8
addq $0x8, %rsi
decl %r15d
cmpq %r8, %rcx
je 0x148813
jmp 0x1489da
movq -0x60(%rbp), %rax
xorl $0x1, %eax
movq %rax, -0x60(%rbp)
xorl %r12d, %r12d
movq -0xa8(%rbp), %rax
movq %rax, %r15
movq %rax, -0x78(%rbp)
movl %ecx, -0x4c(%rbp)
jmp 0x148873
xorl %r12d, %r12d
movq %r13, %r15
movq %r13, -0x78(%rbp)
movl -0x64(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0xc0(%rbp), %rcx
testq %rcx, %rcx
je 0x1485f8
movq %r15, %rax
xorl %edx, %edx
divq %rcx
testq %rdx, %rdx
jne 0x1485f8
pushq $0x2e
popq %rdi
movq -0xa0(%rbp), %rsi
callq 0x17ee0
jmp 0x1485f8
movq 0x2ef6b9(%rip), %rcx    # 0x437f68
movq (%rcx), %rdi
movl $0x0, -0x58(%rbp)
leaq 0x1fb1e2(%rip), %rsi    # 0x343aa2
movq -0x40(%rbp), %rdx
movq %rax, %rcx
movq %r14, %r8
movl %r12d, %r9d
xorl %eax, %eax
callq 0x17a50
movq 0x18(%rbp), %rdi
leaq 0x1fb21a(%rip), %rsi    # 0x343af9
xorl %eax, %eax
callq 0x89dbb
movq (%rbx), %rax
movq 0x60(%rax), %rax
pushq $0x4
popq %rcx
movl %ecx, %r12d
testq %rax, %rax
je 0x1486b2
movq 0x2ef665(%rip), %rcx    # 0x437f68
movq (%rcx), %rdx
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rcx
callq *%rax
movl $0x0, -0x58(%rbp)
pushq $0x4
popq %rax
movl %eax, %r12d
jmp 0x1486b2
leaq 0x1fb085(%rip), %rsi    # 0x3439b1
movq 0x10(%rbp), %rdi
xorl %eax, %eax
callq 0x92e71
pushq $-0x1
popq %r13
movq -0x98(%rbp), %rsp
jmp 0x148a52
cmpq $0x0, -0xc0(%rbp)
je 0x148960
pushq $0xa
popq %rdi
movq -0xa0(%rbp), %rsi
callq 0x17ee0
movq -0x80(%rbp), %rdi
callq 0x17e70
xorl %r13d, %r13d
testl %eax, %eax
je 0x148a31
movq 0x2ef5ed(%rip), %r14    # 0x437f68
movq (%r14), %rdi
leaq 0x1fb0d1(%rip), %rsi    # 0x343a56
movq -0x40(%rbp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0x17a50
leaq 0x1fb0e3(%rip), %rsi    # 0x343a7d
movq 0x18(%rbp), %rdi
xorl %eax, %eax
callq 0x89dbb
movq -0x48(%rbp), %rdi
movq (%rdi), %rax
movq 0x60(%rax), %rax
pushq $0x2
jmp 0x148a1e
leal (%r15,%rax), %r9d
decl %r9d
movq 0x2ef5a6(%rip), %r14    # 0x437f68
movq (%r14), %rdi
leaq 0x1fb0d6(%rip), %rsi    # 0x343aa2
movq -0x40(%rbp), %rbx
movq %rbx, %rdx
jmp 0x1489f8
negl %r15d
jmp 0x1489dd
notl %r15d
movq 0x2ef584(%rip), %r14    # 0x437f68
movq (%r14), %rdi
leaq 0x1fb0b4(%rip), %rsi    # 0x343aa2
movq -0x40(%rbp), %rbx
movq %rbx, %rdx
movl %r15d, %r9d
xorl %eax, %eax
callq 0x17a50
leaq 0x1fb0f3(%rip), %rsi    # 0x343af9
movq 0x18(%rbp), %rdi
xorl %eax, %eax
callq 0x89dbb
movq -0x48(%rbp), %rdi
movq (%rdi), %rax
movq 0x60(%rax), %rax
pushq $0x4
popq %r13
testq %rax, %rax
je 0x148a31
movq (%r14), %rdx
movq %rbx, %rsi
movq -0x30(%rbp), %rcx
callq *%rax
movq -0x98(%rbp), %rsp
movq -0x48(%rbp), %rdi
movq (%rdi), %rax
movq -0x30(%rbp), %rsi
callq *0x40(%rax)
leaq -0x1d0(%rbp), %rdi
callq 0x14d148
movl %r13d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2ef4fd(%rip), %r14    # 0x437f68
movq (%r14), %rdi
leaq 0x1faf7b(%rip), %rsi    # 0x3439f0
movq %r15, %rdx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x17a50
leaq 0x1fafb1(%rip), %rsi    # 0x343a3a
movq 0x18(%rbp), %rdi
xorl %eax, %eax
callq 0x89dbb
movq (%rbx), %rax
movq 0x60(%rax), %rax
pushq $0x1
jmp 0x148ad5
movq 0x2ef4c2(%rip), %r14    # 0x437f68
movq (%r14), %rdi
leaq 0x1fafa6(%rip), %rsi    # 0x343a56
movq %r15, %rdx
xorl %eax, %eax
callq 0x17a50
leaq 0x1fafbc(%rip), %rsi    # 0x343a7d
movq 0x18(%rbp), %rdi
xorl %eax, %eax
callq 0x89dbb
movq (%rbx), %rax
movq 0x60(%rax), %rax
pushq $0x2
popq %r13
testq %rax, %rax
je 0x148a31
movq (%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
jmp 0x148a2b
movq 0x2ef473(%rip), %r13    # 0x437f68
movq (%r13), %rdi
leaq 0x1fafa2(%rip), %rsi    # 0x343aa2
movq -0x40(%rbp), %r15
movq %r15, %rdx
movq %rax, %rcx
movq %r14, %r8
movl %r12d, %r9d
xorl %eax, %eax
callq 0x17a50
leaq 0x1fafdb(%rip), %rsi    # 0x343af9
movq 0x18(%rbp), %rdi
xorl %eax, %eax
callq 0x89dbb
movq (%rbx), %rax
movq 0x60(%rax), %rax
pushq $0x4
popq %r14
testq %rax, %rax
je 0x148b49
movq (%r13), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movq -0x30(%rbp), %rcx
callq *%rax
movq %r14, %r13
jmp 0x148a31
callq 0x17390
movq 0x2ef40b(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19c4ac(%rip), %rsi    # 0x2e5013
leaq 0x1f9b55(%rip), %rdx    # 0x3426c3
leaq 0x1f9b5a(%rip), %rcx    # 0x3426cf
leaq 0x1f9b68(%rip), %r8     # 0x3426e4
pushq $0x32
jmp 0x148ba8
movq 0x2ef3e1(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19c482(%rip), %rsi    # 0x2e5013
leaq 0x1f9cd9(%rip), %rdx    # 0x342871
leaq 0x1f9cf8(%rip), %rcx    # 0x342897
leaq 0x1f9bdf(%rip), %r8     # 0x342785
pushq $0x30
popq %r9
xorl %eax, %eax
callq 0x17a50
callq 0x17390