// File: /workspace/github_c_makefile_star2_O1/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 $0x188, %rsp            # imm = 0x188
movq %r8, (%rsp)
movl %edx, 0x10(%rsp)
testq %rdi, %rdi
je 0x1a504b
movq %rsi, %r13
testq %rsi, %rsi
je 0x1a504b
movq 0x1c0(%rsp), %r12
testq %r12, %r12
je 0x1a504b
movq %r9, %rbx
movq %rcx, %r14
movq %rdi, %rbp
movq %r12, %rdi
callq 0x101a9a
testb %al, %al
jne 0x1a5050
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x80(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x3, %esi
movq %r13, %rdx
movq %rbx, %rcx
movq %r12, %r8
callq 0x1aab20
movl %eax, %r15d
testl %eax, %eax
je 0x1a4a16
leaq 0x207af2(%rip), %rsi    # 0x3ac4f0
movq %r12, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x1019cf
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
jmp 0x1a4ae5
movq %r13, 0x20(%rsp)
movq 0x88(%rsp), %rdi
callq 0xec1d8
movq %rax, 0x18(%rsp)
leaq 0x1(%rax), %r13
movq (%rbp), %rax
cmpq %r13, 0x10(%rax)
jne 0x1a4ac9
movl 0x20(%rbp), %eax
testb $0x1, 0x10(%rsp)
movl %r15d, 0xc(%rsp)
movq %r13, 0x30(%rsp)
jne 0x1a4b56
xorl %r12d, %r12d
testl %eax, %eax
jne 0x1a4df9
cmpl $0x0, 0x20(%rbp)
je 0x1a4db0
movq 0x30(%rbp), %rcx
cmpb $0x1, 0xc0(%rsp)
jne 0x1a4a8b
movq 0xc8(%rsp), %rdx
cmpq %rcx, %rdx
jne 0x1a4c52
movq %rcx, (%rsp)
movb $0x1, %bl
testb $0x2, 0x10(%rsp)
je 0x1a4da8
testb $0x4, 0x40(%rbp)
jne 0x1a4c75
leaq 0x207c1d(%rip), %rsi    # 0x3ac6ca
xorl %ebx, %ebx
movq 0x1c0(%rsp), %rdi
xorl %eax, %eax
callq 0x1019cf
movl $0xfffffffb, %r12d      # imm = 0xFFFFFFFB
jmp 0x1a4da8
leaq 0x207a92(%rip), %rsi    # 0x3ac562
movq %r12, %rdi
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x1019cf
movl $0xfffffffe, %r12d      # imm = 0xFFFFFFFE
testl %r15d, %r15d
jne 0x1a4af7
leaq 0x88(%rsp), %rdi
callq 0x1a9e1c
testb $0x1, 0x80(%rsp)
je 0x1a4b1c
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x1a4b1c
leaq 0x206e62(%rip), %rsi    # 0x3ab974
movl $0x87, %edx
callq 0x109670
testb $0x4, 0x80(%rsp)
je 0x1a4b41
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x1a4b41
leaq 0x206e3d(%rip), %rsi    # 0x3ab974
movl $0x89, %edx
callq 0x109670
movl %r12d, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testl %eax, %eax
je 0x1a4c12
testq %r13, %r13
je 0x1a4c2e
xorl %ebx, %ebx
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0x50(%rsp), %rdx
callq 0x1a327c
movl $0x0, %r12d
testl %eax, %eax
je 0x1a4bde
movq %rbp, %rdi
movq %rbx, %rsi
leaq 0x50(%rsp), %rdx
callq 0x1a3411
movq %rax, %r15
movq 0xe0(%rsp), %rax
movq (%rax,%rbx,8), %r13
xorl %r12d, %r12d
cmpq %r13, %r15
je 0x1a4bcf
movq 0x1c0(%rsp), %rdi
leaq 0x2079ec(%rip), %rsi    # 0x3ac5a5
movq %rbx, %rdx
movq %r15, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x1019cf
movl $0xfffffffd, %r12d      # imm = 0xFFFFFFFD
cmpq %r13, %r15
movl 0xc(%rsp), %r15d
movq 0x30(%rsp), %r13
jne 0x1a4c31
testq %r14, %r14
je 0x1a4bff
leaq 0x1(%rbx), %rax
xorl %edx, %edx
divq %r14
testq %rdx, %rdx
jne 0x1a4bff
movl $0x2e, %edi
movq (%rsp), %rsi
callq 0x17f80
incq %rbx
cmpq %r13, %rbx
jae 0x1a4c31
testl %r12d, %r12d
je 0x1a4b69
jmp 0x1a4c31
leaq 0x2079cd(%rip), %rsi    # 0x3ac5e6
movq %r12, %rdi
xorl %eax, %eax
callq 0x1019cf
movl $0xfffffffd, %r12d      # imm = 0xFFFFFFFD
jmp 0x1a4ae5
xorl %r12d, %r12d
testq %r14, %r14
je 0x1a4c44
movl $0xa, %edi
movq (%rsp), %rsi
callq 0x17f80
testl %r12d, %r12d
jne 0x1a4ae5
jmp 0x1a4a62
leaq 0x207a01(%rip), %rsi    # 0x3ac65a
xorl %ebx, %ebx
movq 0x1c0(%rsp), %rdi
xorl %eax, %eax
callq 0x1019cf
movl $0xfffffffa, %r12d      # imm = 0xFFFFFFFA
jmp 0x1a4da8
movq %rbp, %rdi
movq (%rsp), %r14
movq %r14, %rsi
callq 0x1a505f
movl %eax, %ebx
cmpb $-0x2, %al
jne 0x1a4ca7
leaq 0x50(%rsp), %rdx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1a5099
movq %rax, (%rsp)
xorl %eax, %eax
movq 0x18(%rsp), %r15
jmp 0x1a4cd9
movzbl %bl, %ecx
leaq 0x2079dd(%rip), %rsi    # 0x3ac68e
movq 0x1c0(%rsp), %rdi
movq 0x18(%rsp), %rdx
movl $0xfe, %r8d
xorl %eax, %eax
callq 0x1019cf
movl $0xfffffffc, %r12d      # imm = 0xFFFFFFFC
movl $0x2, %eax
movq %r13, %r15
cmpb $-0x2, %bl
jne 0x1a4d9e
decq %r15
cmpq $-0x1, %r15
je 0x1a4d94
movq 0x88(%rsp), %rdi
movl 0xd0(%rsp), %edx
movq %r15, %rsi
callq 0xec1f8
movq (%rbp), %rdi
testq %rdi, %rdi
je 0x1a5055
movq 0x18(%rbp), %rdx
testq %rdx, %rdx
je 0x1a5055
movl %eax, %ebx
movq (%rdi), %rax
movq 0x8(%rdi), %r14
movq (%rsp), %rsi
callq *0x30(%rax)
cmpl $0x1, (%r14)
jne 0x1a505a
movzbl %al, %eax
movzbl 0x118(%r14,%rax), %r14d
cmpb %bl, %r14b
jne 0x1a4d62
movq %rbp, %rdi
movq (%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x1a5099
movq %rax, (%rsp)
jmp 0x1a4d88
movzbl %bl, %r8d
movq 0x1c0(%rsp), %rdi
leaq 0x207919(%rip), %rsi    # 0x3ac68e
movq %r15, %rdx
movl %r14d, %ecx
xorl %eax, %eax
callq 0x1019cf
movl $0xfffffffc, %r12d      # imm = 0xFFFFFFFC
decq %r15
cmpb %bl, %r14b
je 0x1a4ce5
xorl %eax, %eax
testl %r12d, %r12d
setne %al
addl %eax, %eax
testl %eax, %eax
sete %bl
movl 0xc(%rsp), %r15d
testb %bl, %bl
je 0x1a4ae5
testb $0x4, 0x10(%rsp)
je 0x1a4ae5
movq %rbp, %rdi
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x1a20a6
testq %rax, %rax
jne 0x1a4e03
leaq 0x207941(%rip), %rsi    # 0x3ac71d
movq 0x1c0(%rsp), %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x1019cf
movl $0xfffffff8, %r12d      # imm = 0xFFFFFFF8
jmp 0x1a4ae5
callq 0x6109c
jmp 0x1a4a62
movq %rax, 0x28(%rsp)
movq 0x31f171(%rip), %rax    # 0x4c3f80
movq (%rax), %rsi
leaq 0x207941(%rip), %rdi    # 0x3ac75a
callq 0x178c0
movq %r13, %rax
shrq $0x7, %rax
movl $0x3e8, %ecx            # imm = 0x3E8
cmpq %rcx, %rax
movl $0x3e8, %edx            # imm = 0x3E8
cmovbq %rax, %rdx
cmpq $0x80, %r13
movl $0x1, %esi
cmovaeq %rdx, %rsi
movq %rsi, 0x40(%rsp)
cmpq $0x3, %rax
movl $0x2, %edx
cmovaeq %rax, %rdx
cmpq $0x1f480, %r13          # imm = 0x1F480
cmovaeq %rcx, %rdx
movq %rdx, 0x38(%rsp)
leaq 0x2074da(%rip), %rsi    # 0x3ac349
movl $0x3e8, %edi            # imm = 0x3E8
movl $0x278, %edx            # imm = 0x278
callq 0x1092b2
movq %rax, %rbp
movq 0x88(%rsp), %rdi
movl 0xd0(%rsp), %esi
xorl %edx, %edx
callq 0xed76d
movq %rax, (%rsp)
testl %r12d, %r12d
sete %al
jne 0x1a500f
incq 0x18(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x20(%rsp)
callq 0x125bcc
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
andl %ebx, %eax
xorl %edx, %edx
divq 0x40(%rsp)
movq %rdx, %r14
movq %rbp, %r15
leaq 0x1(%rdx), %rbp
callq 0x125bcc
andl %ebx, %eax
movq 0x18(%rsp), %rcx
subq %r14, %rcx
xorl %edx, %edx
divq %rcx
movq %rdx, %r12
movq %r14, 0x48(%rsp)
leaq (%rdx,%r14), %rax
incq %rax
xorl %ebx, %ebx
cmpq %r13, %rax
sete %bl
movq 0x28(%rsp), %rdi
movq %rdx, %rsi
movq %rbp, %r14
movq %rbp, %rdx
movq %r15, %rbp
movq %r15, %rcx
callq 0x1a21e2
movq 0x88(%rsp), %rsi
movl 0xd0(%rsp), %edx
movq (%rsp), %rdi
movq %r12, 0x10(%rsp)
movq %r12, %rcx
callq 0xed48e
movl $0x0, %r15d
movl $0x0, %r12d
subq %rbx, %r14
je 0x1a4f9a
xorl %r12d, %r12d
xorl %r15d, %r15d
movq (%rsp), %rdi
callq 0xec7be
movl %eax, %ebx
movzbl (%rbp,%r15), %r13d
cmpb %al, %r13b
je 0x1a4f8d
movzbl %bl, %r8d
movq 0x10(%rsp), %rax
leaq (%r15,%rax), %rdx
movq 0x1c0(%rsp), %rdi
leaq 0x207711(%rip), %rsi    # 0x3ac68e
movl %r13d, %ecx
xorl %eax, %eax
callq 0x1019cf
movl $0xfffffff9, %r12d      # imm = 0xFFFFFFF9
cmpb %bl, %r13b
jne 0x1a4f9a
incq %r15
cmpq %r14, %r15
jb 0x1a4f4b
movq 0x30(%rsp), %r13
movq 0x48(%rsp), %r14
cmpq %r14, %r15
ja 0x1a4ff1
movzbl (%rbp,%r15), %ebx
cmpl $0xfe, %ebx
jne 0x1a4fbc
incq %r15
jmp 0x1a4fe9
movq 0x10(%rsp), %rax
leaq (%r15,%rax), %rdx
movq 0x1c0(%rsp), %rdi
leaq 0x2076ba(%rip), %rsi    # 0x3ac68e
movl %ebx, %ecx
movl $0xfe, %r8d
xorl %eax, %eax
callq 0x1019cf
movl $0xfffffff9, %r12d      # imm = 0xFFFFFFF9
cmpl $0xfe, %ebx
je 0x1a4fa4
movq 0x20(%rsp), %rcx
incq %rcx
testl %r12d, %r12d
sete %al
cmpq 0x38(%rsp), %rcx
jae 0x1a500f
testl %r12d, %r12d
je 0x1a4eae
testb %al, %al
jne 0x1a5044
movq (%rsp), %rdi
callq 0xed7bf
leaq 0x207326(%rip), %rsi    # 0x3ac349
movq %rbp, %rdi
movl $0x2a6, %edx            # imm = 0x2A6
callq 0x109670
movq 0x28(%rsp), %rdi
callq 0x1a21b6
movl 0xc(%rsp), %r15d
jmp 0x1a4ae5
callq 0x610ef
jmp 0x1a5013
callq 0x61063
callq 0x6110b
callq 0x610b8
callq 0x173b0