// File: /workspace/github_c_makefile_star2_O3/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 $0x178, %rsp            # imm = 0x178
movq %r8, 0x10(%rsp)
testq %rdi, %rdi
je 0x19ca29
movq %rsi, %r14
testq %rsi, %rsi
je 0x19ca29
movq 0x1b0(%rsp), %r13
testq %r13, %r13
je 0x19ca29
movq %r9, %r12
movq %rcx, %rbx
movl %edx, %ebp
movq %rdi, %r15
movq %r13, %rdi
callq 0xfcc32
testb %al, %al
jne 0x19ca2e
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
movl $0x3, %esi
movq %r14, %rdx
movq %r12, %rcx
movq %r13, %r8
callq 0x1a2288
testl %eax, %eax
je 0x19c487
leaq 0x206b1e(%rip), %rsi    # 0x3a2f90
movq %r13, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xfcb67
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jmp 0x19c4ea
movq 0x78(%rsp), %rdi
callq 0xe7b9c
movq %rax, %r12
leaq 0x1(%rax), %rcx
movq (%r15), %rax
movq %rcx, 0x20(%rsp)
cmpq %rcx, 0x10(%rax)
jne 0x19c4c6
movl 0x20(%r15), %eax
testb $0x1, %bpl
jne 0x19c545
testl %eax, %eax
je 0x19c640
callq 0x5fbf1
jmp 0x19c640
leaq 0x206b35(%rip), %rsi    # 0x3a3002
movq %r13, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xfcb67
movl $0xfffffffe, %r13d      # imm = 0xFFFFFFFE
leaq 0x78(%rsp), %rdi
callq 0x1a1540
movl 0x70(%rsp), %eax
testb $0x1, %al
je 0x19c511
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x19c511
leaq 0x205f11(%rip), %rsi    # 0x3a2414
movl $0x87, %edx
callq 0x1045eb
movl 0x70(%rsp), %eax
testb $0x4, %al
je 0x19c530
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x19c530
leaq 0x205eee(%rip), %rsi    # 0x3a2414
movl $0x89, %edx
callq 0x1045eb
movl %r13d, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %eax, %eax
je 0x19c5d4
movl %ebp, 0x8(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x19c5f0
movq %r12, 0x18(%rsp)
movb $0x1, %bpl
xorl %r13d, %r13d
leaq 0x40(%rsp), %r12
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x19ad3c
testl %eax, %eax
je 0x19c59e
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x19ae8c
movq 0xd0(%rsp), %rcx
movq (%rcx,%r13,8), %r8
cmpq %r8, %rax
jne 0x19c5f7
incq %r13
testq %rbx, %rbx
je 0x19c5c2
movq %r13, %rax
xorl %edx, %edx
divq %rbx
testq %rdx, %rdx
jne 0x19c5c2
movl $0x2e, %edi
movq 0x10(%rsp), %rsi
callq 0x17f80
cmpq 0x20(%rsp), %r13
setb %bpl
jne 0x19c56d
xorl %ebp, %ebp
xorl %r13d, %r13d
jmp 0x19c619
leaq 0x206aab(%rip), %rsi    # 0x3a3086
movq %r13, %rdi
xorl %eax, %eax
callq 0xfcb67
movl $0xfffffffd, %r13d      # imm = 0xFFFFFFFD
jmp 0x19c4e0
xorl %ebp, %ebp
xorl %r13d, %r13d
jmp 0x19c61e
leaq 0x206a47(%rip), %rsi    # 0x3a3045
movq 0x1b0(%rsp), %rdi
movq %r13, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xfcb67
movl $0xfffffffd, %r13d      # imm = 0xFFFFFFFD
movq 0x18(%rsp), %r12
testq %rbx, %rbx
je 0x19c632
movl $0xa, %edi
movq 0x10(%rsp), %rsi
callq 0x17f80
testb $0x1, %bpl
movl 0x8(%rsp), %ebp
jne 0x19c4e0
cmpl $0x0, 0x20(%r15)
je 0x19c668
movq 0x30(%r15), %rbx
cmpb $0x1, 0xb0(%rsp)
jne 0x19c662
movq 0xb8(%rsp), %rdx
cmpq %rbx, %rdx
jne 0x19c6da
testb $0x2, %bpl
jne 0x19c6b2
xorl %r13d, %r13d
testb $0x4, %bpl
je 0x19c4e0
movq %r15, %rdi
movq %r14, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x199b63
testq %rax, %rax
jne 0x19c7dc
leaq 0x206b28(%rip), %rsi    # 0x3a31bd
movq 0x1b0(%rsp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0xfcb67
movl $0xfffffff8, %r13d      # imm = 0xFFFFFFF8
jmp 0x19c4e0
testb $0x4, 0x40(%r15)
jne 0x19c6fe
leaq 0x206aaa(%rip), %rsi    # 0x3a316a
movq 0x1b0(%rsp), %rdi
xorl %eax, %eax
callq 0xfcb67
movl $0xfffffffb, %r13d      # imm = 0xFFFFFFFB
jmp 0x19c4e0
leaq 0x206a19(%rip), %rsi    # 0x3a30fa
movq 0x1b0(%rsp), %rdi
movq %rbx, %rcx
xorl %eax, %eax
callq 0xfcb67
movl $0xfffffffa, %r13d      # imm = 0xFFFFFFFA
jmp 0x19c4e0
movq (%r15), %rdi
movq 0x18(%r15), %rsi
movq %rbx, %rdx
callq 0x19ca3d
cmpb $-0x2, %al
jne 0x19c7bc
leaq 0x40(%rsp), %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x19ca76
testq %r12, %r12
je 0x19c668
movq %rax, %rbx
decq %r12
movl %ebp, 0x8(%rsp)
movq 0x78(%rsp), %rdi
movl 0xc0(%rsp), %edx
movq %r12, %r13
movq %r12, %rsi
callq 0xe7bbc
movq (%r15), %rdi
testq %rdi, %rdi
je 0x19ca38
movq 0x18(%r15), %rdx
testq %rdx, %rdx
je 0x19ca38
movl %eax, %ebp
movq (%rdi), %rax
movq 0x8(%rdi), %r12
movq %rbx, %rsi
callq *0x30(%rax)
cmpl $0x1, (%r12)
jne 0x19ca33
movzbl %al, %eax
movzbl 0x118(%r12,%rax), %ecx
cmpb %bpl, %cl
jne 0x19c9a7
movq %r15, %rdi
movq %rbx, %rsi
leaq 0x40(%rsp), %rdx
callq 0x19ca76
movq %rax, %rbx
movq %r13, %r12
addq $-0x1, %r12
movl 0x8(%rsp), %ebp
jb 0x19c738
jmp 0x19c668
movzbl %al, %ecx
leaq 0x206968(%rip), %rsi    # 0x3a312e
movq 0x1b0(%rsp), %rdi
movq %r12, %rdx
movl $0xfe, %r8d
jmp 0x19c9bd
movq %rax, %rbx
movq 0x31c79a(%rip), %rax    # 0x4b8f80
movq (%rax), %rsi
leaq 0x206a0a(%rip), %rdi    # 0x3a31fa
callq 0x178c0
movq 0x20(%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
movl $0x1, %edi
cmovaeq %rdx, %rdi
movq %rdi, 0x38(%rsp)
cmpq $0x3, %rax
movl $0x2, %edx
cmovaeq %rax, %rdx
cmpq $0x1f480, %rsi          # imm = 0x1F480
cmovaeq %rcx, %rdx
movq %rdx, 0x30(%rsp)
leaq 0x20659e(%rip), %rsi    # 0x3a2de9
movl $0x3e8, %edi            # imm = 0x3E8
movl $0x278, %edx            # imm = 0x278
callq 0x104226
movq %rax, %r14
movq 0x78(%rsp), %rdi
movl 0xc0(%rsp), %esi
xorl %edx, %edx
callq 0xe91b2
movq %rax, 0x10(%rsp)
xorl %eax, %eax
movq %rbx, 0x28(%rsp)
movq %rax, 0x18(%rsp)
callq 0x11fe0c
movl $0x7fffffff, %r12d      # imm = 0x7FFFFFFF
andl %r12d, %eax
xorl %edx, %edx
divq 0x38(%rsp)
movq %rdx, %rbp
leaq 0x1(%rdx), %r15
callq 0x11fe0c
andl %r12d, %eax
movq 0x20(%rsp), %rsi
movq %rsi, %rcx
subq %rbp, %rcx
xorl %edx, %edx
divq %rcx
movq %rdx, %r13
leaq (%rdx,%rbp), %rax
incq %rax
xorl %r12d, %r12d
cmpq %rsi, %rax
sete %r12b
movq %rbx, %rdi
movq %rdx, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x199c9f
movq 0x78(%rsp), %rsi
movl 0xc0(%rsp), %edx
movq 0x10(%rsp), %rdi
movq %r13, 0x8(%rsp)
movq %r13, %rcx
callq 0xe8eed
movl $0x0, %r13d
movl $0x0, %ebx
subq %r12, %r15
je 0x19c95e
xorl %ebx, %ebx
movq 0x1b0(%rsp), %r12
movq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0xe8186
movzbl (%r14,%rbx), %ecx
cmpb %al, %cl
jne 0x19c935
incq %rbx
cmpq %r15, %rbx
jb 0x19c917
xorl %r13d, %r13d
jmp 0x19c959
movzbl %al, %r8d
movq 0x8(%rsp), %rax
leaq (%rbx,%rax), %rdx
movq %r12, %rdi
leaq 0x2067e2(%rip), %rsi    # 0x3a312e
xorl %eax, %eax
callq 0xfcb67
movl $0xfffffff9, %r13d      # imm = 0xFFFFFFF9
cmpq %rbp, %rbx
ja 0x19c97b
leaq -0x1(%rbx), %rax
movzbl 0x1(%r14,%rax), %ecx
cmpl $0xfe, %ecx
jne 0x19c9cf
incq %rbx
incq %rax
cmpq %rbp, %rax
jb 0x19c962
movq 0x18(%rsp), %rax
incq %rax
cmpq 0x30(%rsp), %rax
movq 0x28(%rsp), %rbx
jae 0x19c998
testl %r13d, %r13d
je 0x19c87c
testl %r13d, %r13d
jne 0x19c9fe
callq 0x5fc44
xorl %r13d, %r13d
jmp 0x19c9fe
movzbl %bpl, %r8d
leaq 0x20677c(%rip), %rsi    # 0x3a312e
movq 0x1b0(%rsp), %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0xfcb67
movl $0xfffffffc, %r13d      # imm = 0xFFFFFFFC
jmp 0x19c4e0
addq 0x8(%rsp), %rbx
leaq 0x206753(%rip), %rsi    # 0x3a312e
movq 0x1b0(%rsp), %rdi
movq %rbx, %rdx
movl $0xfe, %r8d
xorl %eax, %eax
callq 0xfcb67
movl $0xfffffff9, %r13d      # imm = 0xFFFFFFF9
movq 0x28(%rsp), %rbx
movq 0x10(%rsp), %rdi
callq 0xe9204
leaq 0x2063da(%rip), %rsi    # 0x3a2de9
movq %r14, %rdi
movl $0x2a6, %edx            # imm = 0x2A6
callq 0x1045eb
movq %rbx, %rdi
callq 0x199c73
jmp 0x19c4e0
callq 0x5fbb8
callq 0x5fc60
callq 0x173b0
callq 0x5fc0d