// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3BtreeIntegrityCheck
SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
  sqlite3 *db,  /* Database connection that is running the check */
  Btree *p,     /* The btree to be checked */
  Pgno *aRoot,  /* An array of root pages numbers for individual trees */
  int nRoot,    /* Number of entries in aRoot[] */
  int mxErr,    /* Stop reporting errors after this many */
  int *pnErr    /* Write number of errors seen to this variable */
){
  Pgno i;
  IntegrityCk sCheck;
  BtShared *pBt = p->pBt;
  u64 savedDbFlags = pBt->db->flags;
  char zErr[100];
  int bPartial = 0;            /* True if not checking all btrees */
  int bCkFreelist = 1;         /* True to scan the freelist */
  VVA_ONLY( int nRef );
  assert( nRoot>0 );

  /* aRoot[0]==0 means this is a partial check */
  if( aRoot[0]==0 ){
    assert( nRoot>1 );
    bPartial = 1;
    if( aRoot[1]!=1 ) bCkFreelist = 0;
  }

  sqlite3BtreeEnter(p);
  assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
  VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) );
  assert( nRef>=0 );
  sCheck.db = db;
  sCheck.pBt = pBt;
  sCheck.pPager = pBt->pPager;
  sCheck.nPage = btreePagecount(sCheck.pBt);
  sCheck.mxErr = mxErr;
  sCheck.nErr = 0;
  sCheck.bOomFault = 0;
  sCheck.zPfx = 0;
  sCheck.v1 = 0;
  sCheck.v2 = 0;
  sCheck.aPgRef = 0;
  sCheck.heap = 0;
  sqlite3StrAccumInit(&sCheck.errMsg, 0, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
  sCheck.errMsg.printfFlags = SQLITE_PRINTF_INTERNAL;
  if( sCheck.nPage==0 ){
    goto integrity_ck_cleanup;
  }

  sCheck.aPgRef = sqlite3MallocZero((sCheck.nPage / 8)+ 1);
  if( !sCheck.aPgRef ){
    sCheck.bOomFault = 1;
    goto integrity_ck_cleanup;
  }
  sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
  if( sCheck.heap==0 ){
    sCheck.bOomFault = 1;
    goto integrity_ck_cleanup;
  }

  i = PENDING_BYTE_PAGE(pBt);
  if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);

  /* Check the integrity of the freelist
  */
  if( bCkFreelist ){
    sCheck.zPfx = "Main freelist: ";
    checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
              get4byte(&pBt->pPage1->aData[36]));
    sCheck.zPfx = 0;
  }

  /* Check all the tables.
  */
#ifndef SQLITE_OMIT_AUTOVACUUM
  if( !bPartial ){
    if( pBt->autoVacuum ){
      Pgno mx = 0;
      Pgno mxInHdr;
      for(i=0; (int)i<nRoot; i++) if( mx<aRoot[i] ) mx = aRoot[i];
      mxInHdr = get4byte(&pBt->pPage1->aData[52]);
      if( mx!=mxInHdr ){
        checkAppendMsg(&sCheck,
          "max rootpage (%d) disagrees with header (%d)",
          mx, mxInHdr
        );
      }
    }else if( get4byte(&pBt->pPage1->aData[64])!=0 ){
      checkAppendMsg(&sCheck,
        "incremental_vacuum enabled with a max rootpage of zero"
      );
    }
  }
#endif
  testcase( pBt->db->flags & SQLITE_CellSizeCk );
  pBt->db->flags &= ~(u64)SQLITE_CellSizeCk;
  for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
    i64 notUsed;
    if( aRoot[i]==0 ) continue;
#ifndef SQLITE_OMIT_AUTOVACUUM
    if( pBt->autoVacuum && aRoot[i]>1 && !bPartial ){
      checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0);
    }
#endif
    checkTreePage(&sCheck, aRoot[i], &notUsed, LARGEST_INT64);
  }
  pBt->db->flags = savedDbFlags;

  /* Make sure every page in the file is referenced
  */
  if( !bPartial ){
    for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){
#ifdef SQLITE_OMIT_AUTOVACUUM
      if( getPageReferenced(&sCheck, i)==0 ){
        checkAppendMsg(&sCheck, "Page %d is never used", i);
      }
#else
      /* If the database supports auto-vacuum, make sure no tables contain
      ** references to pointer-map pages.
      */
      if( getPageReferenced(&sCheck, i)==0 &&
         (PTRMAP_PAGENO(pBt, i)!=i || !pBt->autoVacuum) ){
        checkAppendMsg(&sCheck, "Page %d is never used", i);
      }
      if( getPageReferenced(&sCheck, i)!=0 &&
         (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
        checkAppendMsg(&sCheck, "Pointer map page %d is referenced", i);
      }
#endif
    }
  }

  /* Clean  up and report errors.
  */
integrity_ck_cleanup:
  sqlite3PageFree(sCheck.heap);
  sqlite3_free(sCheck.aPgRef);
  if( sCheck.bOomFault ){
    sqlite3_str_reset(&sCheck.errMsg);
    sCheck.nErr++;
  }
  *pnErr = sCheck.nErr;
  if( sCheck.nErr==0 ) sqlite3_str_reset(&sCheck.errMsg);
  /* Make sure this analysis did not leave any unref() pages. */
  assert( nRef==sqlite3PagerRefcount(pBt->pPager) );
  sqlite3BtreeLeave(p);
  return sqlite3StrAccumFinish(&sCheck.errMsg);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x30(%rax), %rax
movq %rax, -0xa8(%rbp)
movl $0x0, -0x114(%rbp)
movl $0x1, -0x118(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x3fe714
movl $0x1, -0x114(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4(%rax)
je 0x3fe712
movl $0x0, -0x118(%rbp)
jmp 0x3fe714
movq -0x10(%rbp), %rdi
callq 0x3c5aa0
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0xa0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x98(%rbp), %rdi
callq 0x3e7da0
movl %eax, -0x80(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl $0x0, -0x78(%rbp)
movl $0x0, -0x74(%rbp)
movq $0x0, -0x70(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x64(%rbp)
movq $0x0, -0x88(%rbp)
movq $0x0, -0x40(%rbp)
leaq -0x98(%rbp), %rdi
addq $0x38, %rdi
leaq -0x110(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
movl $0x64, %ecx
movl $0x3b9aca00, %r8d       # imm = 0x3B9ACA00
callq 0x3c36a0
movb $0x1, -0x43(%rbp)
cmpl $0x0, -0x80(%rbp)
jne 0x3fe7c5
jmp 0x3feb7a
movl -0x80(%rbp), %eax
shrl $0x3, %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x3c51d0
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
jne 0x3fe7f4
movl $0x1, -0x74(%rbp)
jmp 0x3feb7a
movq -0xa0(%rbp), %rax
movl 0x34(%rax), %edi
callq 0x3e5050
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x3fe81a
movl $0x1, -0x74(%rbp)
jmp 0x3feb7a
movl 0x241490(%rip), %eax    # 0x63fcb0
movq -0xa0(%rbp), %rcx
xorl %edx, %edx
divl 0x34(%rcx)
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x80(%rbp), %eax
ja 0x3fe849
movl -0x2c(%rbp), %esi
leaq -0x98(%rbp), %rdi
callq 0x40cd60
cmpl $0x0, -0x118(%rbp)
je 0x3fe8b4
leaq 0x1ad3e9(%rip), %rax    # 0x5abc42
movq %rax, -0x70(%rbp)
movq -0xa0(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x20, %rdi
callq 0x3db720
movl %eax, -0x12c(%rbp)
movq -0xa0(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x24, %rdi
callq 0x3db720
movl -0x12c(%rbp), %edx
movl %eax, %ecx
leaq -0x98(%rbp), %rdi
movl $0x1, %esi
callq 0x40cda0
movq $0x0, -0x70(%rbp)
cmpl $0x0, -0x114(%rbp)
jne 0x3fe99f
movq -0xa0(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x3fe969
movl $0x0, -0x11c(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3fe91a
movl -0x11c(%rbp), %eax
movq -0x18(%rbp), %rcx
movl -0x2c(%rbp), %edx
cmpl (%rcx,%rdx,4), %eax
jae 0x3fe90d
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x11c(%rbp)
jmp 0x3fe90f
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3fe8e3
movq -0xa0(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x34, %rdi
callq 0x3db720
movl %eax, -0x120(%rbp)
movl -0x11c(%rbp), %eax
cmpl -0x120(%rbp), %eax
je 0x3fe967
movl -0x11c(%rbp), %edx
movl -0x120(%rbp), %ecx
leaq -0x98(%rbp), %rdi
leaq 0x1ad2f2(%rip), %rsi    # 0x5abc52
movb $0x0, %al
callq 0x40cfd0
jmp 0x3fe99d
movq -0xa0(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x40, %rdi
callq 0x3db720
cmpl $0x0, %eax
je 0x3fe99b
leaq -0x98(%rbp), %rdi
leaq 0x1ad2eb(%rip), %rsi    # 0x5abc7f
movb $0x0, %al
callq 0x40cfd0
jmp 0x3fe99d
jmp 0x3fe99f
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x30(%rax), %rcx
andq $-0x200001, %rcx        # imm = 0xFFDFFFFF
movq %rcx, 0x30(%rax)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x1c(%rbp), %ecx
movb %al, -0x12d(%rbp)
jge 0x3fe9dd
cmpl $0x0, -0x7c(%rbp)
setne %al
movb %al, -0x12d(%rbp)
movb -0x12d(%rbp), %al
testb $0x1, %al
jne 0x3fe9ec
jmp 0x3fea73
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
jne 0x3fe9fb
jmp 0x3fea65
movq -0xa0(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x0, %eax
je 0x3fea3e
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
cmpl $0x1, (%rax,%rcx,4)
jbe 0x3fea3e
cmpl $0x0, -0x114(%rbp)
jne 0x3fea3e
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %esi
leaq -0x98(%rbp), %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x40d110
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %esi
leaq -0x98(%rbp), %rdi
leaq -0x128(%rbp), %rdx
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
callq 0x40d1c0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3fe9c0
movq -0xa8(%rbp), %rcx
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rcx, 0x30(%rax)
cmpl $0x0, -0x114(%rbp)
jne 0x3feb78
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x80(%rbp), %ecx
movb %al, -0x12e(%rbp)
ja 0x3feaba
cmpl $0x0, -0x7c(%rbp)
setne %al
movb %al, -0x12e(%rbp)
movb -0x12e(%rbp), %al
testb $0x1, %al
jne 0x3feac9
jmp 0x3feb76
movl -0x2c(%rbp), %esi
leaq -0x98(%rbp), %rdi
callq 0x40da50
cmpl $0x0, %eax
jne 0x3feb16
movq -0xa0(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x3e8c00
cmpl -0x2c(%rbp), %eax
jne 0x3feafe
movq -0xa0(%rbp), %rax
cmpb $0x0, 0x21(%rax)
jne 0x3feb16
movl -0x2c(%rbp), %edx
leaq -0x98(%rbp), %rdi
leaq 0x1ad1a7(%rip), %rsi    # 0x5abcb6
movb $0x0, %al
callq 0x40cfd0
movl -0x2c(%rbp), %esi
leaq -0x98(%rbp), %rdi
callq 0x40da50
cmpl $0x0, %eax
je 0x3feb66
movq -0xa0(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x3e8c00
cmpl -0x2c(%rbp), %eax
jne 0x3feb66
movq -0xa0(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x0, %eax
je 0x3feb66
movl -0x2c(%rbp), %edx
leaq -0x98(%rbp), %rdi
leaq 0x1ad16d(%rip), %rsi    # 0x5abccc
movb $0x0, %al
callq 0x40cfd0
jmp 0x3feb68
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3fea9d
jmp 0x3feb78
jmp 0x3feb7a
movq -0x40(%rbp), %rdi
callq 0x3dbe80
movq -0x88(%rbp), %rdi
callq 0x3c0800
cmpl $0x0, -0x74(%rbp)
je 0x3febae
leaq -0x98(%rbp), %rdi
addq $0x38, %rdi
callq 0x3c35b0
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x78(%rbp)
jne 0x3febcd
leaq -0x98(%rbp), %rdi
addq $0x38, %rdi
callq 0x3c35b0
leaq -0x98(%rbp), %rdi
addq $0x38, %rdi
callq 0x3c3490
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)