// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/match/eis-bwtseq.c
// Function: gt_BWTSeqVerifyIntegrity
enum verifyBWTSeqErrCode
gt_BWTSeqVerifyIntegrity(BWTSeq *bwtSeq, const char *projectName,
                      int checkFlags,
                      GtUword tickPrint, FILE *fp,
                      GtLogger *verbosity, GtError *err)
{
  Suffixarray suffixArray;
  struct extBitsRetrieval extBits;
  bool suffixArrayIsInitialized = false, extBitsAreInitialized = false;
  enum verifyBWTSeqErrCode retval = VERIFY_BWTSEQ_NO_ERROR;
  do
  {
    GtUword seqLen;
    gt_assert(bwtSeq && projectName && err);
    gt_error_check(err);

    initExtBitsRetrieval(&extBits);
    extBitsAreInitialized = true;

    if (gt_mapsuffixarray(&suffixArray,
                       SARR_SUFTAB | SARR_ESQTAB, projectName, verbosity, err))
    {
      gt_error_set(err, "Cannot load reference suffix array project with"
                    " demand for suffix table file and encoded sequence"
                    " for project: %s", projectName);
      retval = VERIFY_BWTSEQ_REFLOAD_ERROR;
      break;
    }
    suffixArrayIsInitialized = true;
    seqLen = gt_encseq_total_length(suffixArray.encseq) + 1;
    if (BWTSeqLength(bwtSeq) != seqLen)
    {
      gt_error_set(err, "length mismatch for suffix array project %s and "
                "bwt sequence index", projectName);
      retval = VERIFY_BWTSEQ_LENCOMPARE_ERROR;
      break;
    }

    if (checkFlags & VERIFY_BWTSEQ_SUFVAL
        && BWTSeqHasLocateInformation(bwtSeq))
    {
      GtUword i;
      for (i = 0; i < seqLen && retval == VERIFY_BWTSEQ_NO_ERROR; ++i)
      {
        if (gt_BWTSeqPosHasLocateInfo(bwtSeq, i, &extBits))
        {
          GtUword sfxArrayValue = gt_BWTSeqLocateMatch(bwtSeq, i,
                                                             &extBits);
          if (sfxArrayValue != ESASUFFIXPTRGET(suffixArray.suftab,i))
          {
            gt_error_set(err, "Failed suffix array value comparison"
                          " at position "GT_WU": "GT_WU" != "GT_WU"",
                          i, sfxArrayValue,
                          ESASUFFIXPTRGET(suffixArray.suftab,i));
            retval = VERIFY_BWTSEQ_SUFVAL_ERROR;
            break;
          }
        }
        if (tickPrint && !((i + 1) % tickPrint))
          putc('.', fp);
      }
      if (tickPrint)
        putc('\n', fp);
      if (retval != VERIFY_BWTSEQ_NO_ERROR)
        break;
    }
    else if (checkFlags & VERIFY_BWTSEQ_SUFVAL)
    {
      gt_error_set(err, "check of suffix array values was requested,"
                " but index contains no  locate information!");
      retval = VERIFY_BWTSEQ_SUFVAL_ERROR;
      break;
    }
    else if (!(checkFlags & VERIFY_BWTSEQ_SUFVAL)
             && BWTSeqHasLocateInformation(bwtSeq))
    {
      fputs("Not checking suftab values.\n", stderr);
    }
    if (BWTSeqHasLocateInformation(bwtSeq))
    {
      GtUword nextLocate = BWTSeqTerminatorPos(bwtSeq);
      if (suffixArray.longest.defined &&
          suffixArray.longest.valueunsignedlong != nextLocate)
      {
        gt_error_set(err, "terminator/0-rotation position mismatch "GT_WU""
                  " vs. "GT_WU"", suffixArray.longest.valueunsignedlong,
                  nextLocate);
        retval = VERIFY_BWTSEQ_TERMPOS_ERROR;
        break;
      }
      if ((checkFlags & VERIFY_BWTSEQ_LFMAPWALK)
          && (bwtSeq->featureToggles & BWTReversiblySorted))
      {
        GtUword i = seqLen;
        /* handle first symbol specially because the encseq
         * will not return the terminator symbol */
        {
          Symbol sym = BWTSeqGetSym(bwtSeq, nextLocate);
          if (sym != GT_UNDEFBWTCHAR)
          {
            gt_error_set(err, "symbol mismatch at position "GT_WU": "
                      "%d vs. reference symbol %d", i - 1, (int)sym,
                      (int)GT_UNDEFBWTCHAR);
            retval = VERIFY_BWTSEQ_LFMAPWALK_ERROR;
            break;
          }
          --i;
          nextLocate = BWTSeqLFMap(bwtSeq, nextLocate, &extBits);
        }
        while (i > 0)
        {
          Symbol symRef =
                         gt_encseq_get_encoded_char(suffixArray.encseq,
                                                          --i,
                                                          suffixArray.readmode);
          Symbol symCmp = BWTSeqGetSym(bwtSeq, nextLocate);
          if (symCmp != symRef)
          {
            gt_error_set(err, "symbol mismatch at position "GT_WU": "
                      "%d vs. reference symbol %d", i, symCmp, symRef);
            retval = VERIFY_BWTSEQ_LFMAPWALK_ERROR;
            break;
          }
          nextLocate = BWTSeqLFMap(bwtSeq, nextLocate, &extBits);
        }
        if (retval != VERIFY_BWTSEQ_NO_ERROR)
          break;
      }
      else if ((checkFlags & VERIFY_BWTSEQ_LFMAPWALK)
               && !(bwtSeq->featureToggles & BWTReversiblySorted))
      {
        gt_error_set(err, "requested complete backwards regeneration in index"
                  " without regeneration capability");
        retval = VERIFY_BWTSEQ_LFMAPWALK_IMP_ERROR;
        break;
      }
    }
    if (checkFlags & VERIFY_BWTSEQ_CONTEXT)
    {
      BWTSeqContextRetriever *bwtSeqCR =
        gt_BWTSeqCRLoad(bwtSeq, projectName, CTX_MAP_ILOG_AUTOSIZE);
      if (!bwtSeqCR)
      {
        gt_error_set(err, "cannot load BWT sequence context access table"
                  " for project %s", projectName);
        retval = VERIFY_BWTSEQ_CONTEXT_LOADFAIL;
        break;
      }
      fputs("Checking context regeneration.\n", stderr);
      {
        GtUword i, start, subSeqLen,
          maxSubSeqLen = GT_MIN(GT_MAX(MIN_CONTEXT_LEN,
                                seqLen/CONTEXT_FRACTION),
                                MAX_CONTEXT_LEN),
          numTries = GT_MIN(MAX_NUM_CONTEXT_CHECKS,
                         GT_MAX(2, seqLen/CONTEXT_INTERVAL));
        Symbol *contextBuf = gt_malloc(sizeof (Symbol) * MAX_CONTEXT_LEN);
        GtEncseqReader *esr =
           gt_encseq_create_reader_with_readmode(suffixArray.encseq,
                                                 suffixArray.readmode,
                                                 0);
        for (i = 0; i < numTries && retval == VERIFY_BWTSEQ_NO_ERROR; ++i)
        {
          GtUword j, end, inSubSeqLen;
          subSeqLen = random()%maxSubSeqLen + 1;
          start = random()%(seqLen - subSeqLen + 1);
          end = start + subSeqLen;
          inSubSeqLen = subSeqLen - ((end==seqLen)?1:0);
          gt_BWTSeqCRAccessSubseq(bwtSeqCR, start, subSeqLen, contextBuf);
          gt_encseq_reader_reinit_with_readmode(esr, suffixArray.encseq,
                                                suffixArray.readmode, start);
          for (j = 0; j < inSubSeqLen; ++j)
          {
            Symbol symRef = gt_encseq_reader_next_encoded_char(esr);
            Symbol symCmp = contextBuf[j];
            if (symCmp != symRef)
            {
              gt_error_set(err, "symbol mismatch at position "GT_WU": "
                        "%d vs. reference symbol %d", start + j, (int)symCmp,
                        (int)symRef);
              retval = VERIFY_BWTSEQ_CONTEXT_SYMFAIL;
              break;
            }
          }
          while (j < subSeqLen)
          {
            Symbol symRef = GT_UNDEFBWTCHAR;
            Symbol symCmp = contextBuf[j];
            if (symCmp != symRef)
            {
              gt_error_set(err, "symbol mismatch at position "GT_WU": "
                        "%d vs. reference symbol %d", start + j, (int)symCmp,
                        (int)symRef);
              retval = VERIFY_BWTSEQ_CONTEXT_SYMFAIL;
              break;
            }
            ++j;
          }
        }
        if (retval == VERIFY_BWTSEQ_NO_ERROR)
          fputs("Context regeneration completed successfully.\n", stderr);
        gt_encseq_reader_delete(esr);
        gt_free(contextBuf);
      }
      gt_deleteBWTSeqCR(bwtSeqCR);
    }
  } while (0);
  if (suffixArrayIsInitialized) gt_freesuffixarray(&suffixArray);
  if (extBitsAreInitialized) destructExtBitsRetrieval(&extBits);
  return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %r8, 0x10(%rsp)
testq %rdi, %rdi
je 0x1479c3
movq %rsi, %r14
testq %rsi, %rsi
je 0x1479c3
movq 0x1a0(%rsp), %r13
testq %r13, %r13
je 0x1479c3
movq %r9, %r12
movq %rcx, %rbx
movl %edx, %ebp
movq %rdi, %r15
movq %r13, %rdi
callq 0x89eb7
testb %al, %al
jne 0x1479f1
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
pushq $0x3
popq %rsi
movq %r14, %rdx
movq %r12, %rcx
movq %r13, %r8
callq 0x14de4e
testl %eax, %eax
je 0x1474e7
leaq 0x1fbe33(%rip), %rsi    # 0x343307
movq %r13, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x89dbb
pushq $-0x1
popq %r13
jmp 0x147558
movq 0x68(%rsp), %rdi
callq 0x7055e
leaq 0x1(%rax), %rcx
movq (%r15), %rdx
movq %rcx, 0x18(%rsp)
cmpq %rcx, 0x10(%rdx)
jne 0x147536
movl 0x20(%r15), %ecx
testb $0x1, %bpl
jne 0x147577
testl %ecx, %ecx
je 0x147656
movq 0x2f0a4c(%rip), %rcx    # 0x437f68
movq %rax, %rbx
movq (%rcx), %rsi
leaq 0x1fbf2b(%rip), %rdi    # 0x343454
callq 0x17870
movq %rbx, %rax
jmp 0x147656
leaq 0x1fbe3c(%rip), %rsi    # 0x343379
movq %r13, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x89dbb
pushq $-0x2
popq %r13
leaq 0x68(%rsp), %rdi
callq 0x14d148
leaq 0x30(%rsp), %rdi
callq 0x14734f
movl %r13d, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %ecx, %ecx
je 0x1475ef
movq %rax, 0x20(%rsp)
movl %ebp, 0x8(%rsp)
xorl %r13d, %r13d
leaq 0x30(%rsp), %rbp
xorl %r12d, %r12d
cmpq %r12, 0x18(%rsp)
je 0x1475eb
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x145626
testl %eax, %eax
je 0x1475c7
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x1457be
movq 0xc0(%rsp), %rcx
movq (%rcx,%r12,8), %r8
cmpq %r8, %rax
jne 0x147607
incq %r12
testq %rbx, %rbx
je 0x14758f
movq %r12, %rax
xorl %edx, %edx
divq %rbx
testq %rdx, %rdx
jne 0x14758f
pushq $0x2e
popq %rdi
movq 0x10(%rsp), %rsi
callq 0x17ee0
jmp 0x14758f
xorl %ebp, %ebp
jmp 0x147632
leaq 0x1fbe07(%rip), %rsi    # 0x3433fd
movq %r13, %rdi
xorl %eax, %eax
callq 0x89dbb
pushq $-0x3
jmp 0x14754c
cmpq 0x18(%rsp), %r12
setb %bpl
leaq 0x1fbda5(%rip), %rsi    # 0x3433bc
movq 0x1a0(%rsp), %rdi
movq %r12, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x89dbb
pushq $-0x3
popq %rax
movl %eax, %r13d
testq %rbx, %rbx
je 0x147644
pushq $0xa
popq %rdi
movq 0x10(%rsp), %rsi
callq 0x17ee0
testb %bpl, %bpl
movl 0x8(%rsp), %ebp
movq 0x20(%rsp), %rax
jne 0x14754e
cmpl $0x0, 0x20(%r15)
je 0x14767e
movq 0x30(%r15), %r12
cmpb $0x1, 0xa0(%rsp)
jne 0x147678
movq 0xa8(%rsp), %rdx
cmpq %r12, %rdx
jne 0x1476e6
testb $0x2, %bpl
jne 0x1476c2
xorl %r13d, %r13d
testb $0x4, %bpl
je 0x14754e
pushq $-0x1
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x14403c
testq %rax, %rax
jne 0x1477be
leaq 0x1fbe8b(%rip), %rsi    # 0x343534
movq 0x1a0(%rsp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x89dbb
pushq $-0x8
jmp 0x14754c
testb $0x4, 0x40(%r15)
jne 0x147706
leaq 0x1fbe11(%rip), %rsi    # 0x3434e1
movq 0x1a0(%rsp), %rdi
xorl %eax, %eax
callq 0x89dbb
pushq $-0x5
jmp 0x14754c
leaq 0x1fbd84(%rip), %rsi    # 0x343471
movq 0x1a0(%rsp), %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x89dbb
pushq $-0x6
jmp 0x14754c
movq %rax, %r13
movq %r15, %rdi
movq %r12, %rsi
callq 0x147a29
cmpb $-0x2, %al
jne 0x14777a
leaq 0x30(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x147aa1
movq %rax, %r12
decq %r13
cmpq $-0x1, %r13
je 0x14767e
movl %ebp, %ebx
movq 0x68(%rsp), %rdi
movl 0xb0(%rsp), %edx
movq %r13, %rsi
callq 0x705e4
movl %eax, %ebp
movq %r15, %rdi
movq %r12, %rsi
callq 0x147a29
cmpb %bpl, %al
jne 0x147797
movq %r15, %rdi
movq %r12, %rsi
leaq 0x30(%rsp), %rdx
callq 0x147aa1
movq %rax, %r12
decq %r13
movl %ebx, %ebp
jmp 0x14772e
movzbl %al, %ecx
leaq 0x1fbd21(%rip), %rsi    # 0x3434a5
movq 0x1a0(%rsp), %rdi
movq %r13, %rdx
movl $0xfe, %r8d
jmp 0x1477b0
movzbl %bpl, %r8d
movzbl %al, %ecx
leaq 0x1fbd00(%rip), %rsi    # 0x3434a5
movq 0x1a0(%rsp), %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x89dbb
pushq $-0x4
jmp 0x14754c
movq %rax, 0x8(%rsp)
movq 0x2f079e(%rip), %rax    # 0x437f68
movq (%rax), %rsi
leaq 0x1fbd9d(%rip), %rdi    # 0x343571
callq 0x17870
movq 0x18(%rsp), %rsi
movq %rsi, %rax
shrq $0x7, %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cmpq %rcx, %rax
movl $0x3e8, %edx            # imm = 0x3E8
cmovbq %rax, %rdx
cmpq $0x80, %rsi
pushq $0x1
popq %rdi
cmovaeq %rdx, %rdi
movq %rdi, 0x28(%rsp)
cmpq $0x3, %rax
pushq $0x2
popq %rdx
cmovaeq %rax, %rdx
cmpq $0x1f480, %rsi          # imm = 0x1F480
cmovaeq %rcx, %rdx
movq %rdx, 0x20(%rsp)
leaq 0x1fb935(%rip), %rsi    # 0x343160
movl $0x3e8, %edi            # imm = 0x3E8
movl $0x278, %edx            # imm = 0x278
callq 0x93160
movq %rax, %r14
movq 0x68(%rsp), %rdi
movl 0xb0(%rsp), %esi
xorl %edx, %edx
callq 0x72260
movq %rax, %r12
xorl %eax, %eax
xorl %r13d, %r13d
cmpq 0x20(%rsp), %rax
jae 0x14797b
testl %r13d, %r13d
jne 0x14797b
movq %rax, 0x10(%rsp)
callq 0xb3a58
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andl %ebx, %eax
xorl %edx, %edx
divq 0x28(%rsp)
movq %rdx, %rbp
leaq 0x1(%rdx), %r15
callq 0xb3a58
andl %ebx, %eax
movq 0x18(%rsp), %rsi
movq %rsi, %rcx
subq %rbp, %rcx
xorl %edx, %edx
divq %rcx
movq %rdx, %rbx
leaq (%rdx,%rbp), %rax
incq %rax
xorl %ecx, %ecx
cmpq %rsi, %rax
sete %cl
negq %rcx
leaq (%rcx,%rbp), %r13
incq %r13
movq 0x8(%rsp), %rdi
movq %rdx, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x1441da
movq 0x68(%rsp), %rsi
movl 0xb0(%rsp), %edx
movq %r12, %rdi
movq %rbx, %rcx
callq 0x71f38
xorl %r15d, %r15d
cmpq %r13, %r15
jae 0x147906
movq %r12, %rdi
callq 0x70f55
movzbl (%r14,%r15), %ecx
cmpb %al, %cl
jne 0x14790b
incq %r15
jmp 0x1478eb
xorl %r13d, %r13d
jmp 0x14792f
movzbl %al, %r8d
leaq (%r15,%rbx), %rdx
movq 0x1a0(%rsp), %rdi
leaq 0x1fbb83(%rip), %rsi    # 0x3434a5
xorl %eax, %eax
callq 0x89dbb
pushq $-0x7
popq %rax
movl %eax, %r13d
cmpq %rbp, %r15
ja 0x14796e
movzbl (%r14,%r15), %ecx
cmpl $0xfe, %ecx
jne 0x147946
incq %r15
jmp 0x14792f
addq %rbx, %r15
movq 0x1a0(%rsp), %rdi
leaq 0x1fbb4d(%rip), %rsi    # 0x3434a5
movq %r15, %rdx
movl $0xfe, %r8d
xorl %eax, %eax
callq 0x89dbb
pushq $-0x7
popq %rax
movl %eax, %r13d
movq 0x10(%rsp), %rax
incq %rax
jmp 0x147858
testl %r13d, %r13d
je 0x1479ab
movq %r12, %rdi
callq 0x722ae
leaq 0x1fb7d1(%rip), %rsi    # 0x343160
movq %r14, %rdi
movl $0x2a6, %edx            # imm = 0x2A6
callq 0x936f9
movq 0x8(%rsp), %rdi
callq 0x14417b
jmp 0x14754e
movq 0x2f05b6(%rip), %rax    # 0x437f68
movq (%rax), %rsi
leaq 0x1fbbd5(%rip), %rdi    # 0x343591
callq 0x17870
jmp 0x147980
movq 0x2f059e(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19d63f(%rip), %rsi    # 0x2e5013
leaq 0x1fb8f6(%rip), %rdx    # 0x3432d1
leaq 0x1fb90c(%rip), %rcx    # 0x3432ee
leaq 0x1fb777(%rip), %r8     # 0x343160
movl $0x1e9, %r9d            # imm = 0x1E9
jmp 0x147a1d
movq 0x2f0570(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x19d611(%rip), %rsi    # 0x2e5013
leaq 0x19d7b6(%rip), %rdx    # 0x2e51bf
leaq 0x1fb8de(%rip), %rcx    # 0x3432ee
leaq 0x1fb749(%rip), %r8     # 0x343160
movl $0x1ea, %r9d            # imm = 0x1EA
xorl %eax, %eax
callq 0x17a50
callq 0x17390