// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3BtreeIntegrityCheck
SQLITE_PRIVATE char *sqlite3BtreeIntegrityCheck(
  Btree *p,     /* The btree to be checked */
  int *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;
  int nRef;
  IntegrityCk sCheck;
  BtShared *pBt = p->pBt;
  char zErr[100];

  sqlite3BtreeEnter(p);
  assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
  nRef = sqlite3PagerRefcount(pBt->pPager);
  sCheck.pBt = pBt;
  sCheck.pPager = pBt->pPager;
  sCheck.nPage = btreePagecount(sCheck.pBt);
  sCheck.mxErr = mxErr;
  sCheck.nErr = 0;
  sCheck.mallocFailed = 0;
  *pnErr = 0;
  if( sCheck.nPage==0 ){
    sqlite3BtreeLeave(p);
    return 0;
  }

  sCheck.aPgRef = sqlite3MallocZero((sCheck.nPage / 8)+ 1);
  if( !sCheck.aPgRef ){
    *pnErr = 1;
    sqlite3BtreeLeave(p);
    return 0;
  }
  i = PENDING_BYTE_PAGE(pBt);
  if( i<=sCheck.nPage ) setPageReferenced(&sCheck, i);
  sqlite3StrAccumInit(&sCheck.errMsg, zErr, sizeof(zErr), SQLITE_MAX_LENGTH);
  sCheck.errMsg.useMalloc = 2;

  /* Check the integrity of the freelist
  */
  checkList(&sCheck, 1, get4byte(&pBt->pPage1->aData[32]),
            get4byte(&pBt->pPage1->aData[36]), "Main freelist: ");

  /* Check all the tables.
  */
  for(i=0; (int)i<nRoot && sCheck.mxErr; i++){
    if( aRoot[i]==0 ) continue;
#ifndef SQLITE_OMIT_AUTOVACUUM
    if( pBt->autoVacuum && aRoot[i]>1 ){
      checkPtrmap(&sCheck, aRoot[i], PTRMAP_ROOTPAGE, 0, 0);
    }
#endif
    checkTreePage(&sCheck, aRoot[i], "List of tree roots: ", NULL, NULL);
  }

  /* Make sure every page in the file is referenced
  */
  for(i=1; i<=sCheck.nPage && sCheck.mxErr; i++){
#ifdef SQLITE_OMIT_AUTOVACUUM
    if( getPageReferenced(&sCheck, i)==0 ){
      checkAppendMsg(&sCheck, 0, "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, 0, "Page %d is never used", i);
    }
    if( getPageReferenced(&sCheck, i)!=0 && 
       (PTRMAP_PAGENO(pBt, i)==i && pBt->autoVacuum) ){
      checkAppendMsg(&sCheck, 0, "Pointer map page %d is referenced", i);
    }
#endif
  }

  /* Make sure this analysis did not leave any unref() pages.
  ** This is an internal consistency check; an integrity check
  ** of the integrity check.
  */
  if( NEVER(nRef != sqlite3PagerRefcount(pBt->pPager)) ){
    checkAppendMsg(&sCheck, 0, 
      "Outstanding page count goes from %d to %d during this analysis",
      nRef, sqlite3PagerRefcount(pBt->pPager)
    );
  }

  /* Clean  up and report errors.
  */
  sqlite3BtreeLeave(p);
  sqlite3_free(sCheck.aPgRef);
  if( sCheck.mallocFailed ){
    sqlite3StrAccumReset(&sCheck.errMsg);
    *pnErr = sCheck.nErr+1;
    return 0;
  }
  *pnErr = sCheck.nErr;
  if( sCheck.nErr==0 ) sqlite3StrAccumReset(&sCheck.errMsg);
  return sqlite3StrAccumFinish(&sCheck.errMsg);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %edx, %r12d
movq 0x8(%rdi), %rbx
movq (%rdi), %rax
movq %rax, 0x8(%rbx)
movq (%rbx), %rax
movq 0x110(%rax), %rdx
movl 0x18(%rdx), %edx
movq %rbx, -0x88(%rbp)
movq %rax, -0x80(%rbp)
movl 0x3c(%rbx), %r14d
movl %r14d, -0x70(%rbp)
movl %ecx, -0x6c(%rbp)
movq $0x0, -0x68(%rbp)
movl $0x0, (%r8)
testq %r14, %r14
je 0x2ed4c
movq %rsi, %r15
movl %edx, -0x2c(%rbp)
movq %r8, -0x38(%rbp)
shrl $0x3, %r14d
incq %r14
movl %r14d, %edi
callq 0xa2a2
movq %rax, %r13
testq %rax, %rax
je 0x2eabe
movq %r13, %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x8200
movq %r13, -0x78(%rbp)
testq %r13, %r13
je 0x2ed42
movl 0x65d6f(%rip), %eax     # 0x94840
xorl %edx, %edx
divl 0x30(%rbx)
incl %eax
cmpl -0x70(%rbp), %eax
ja 0x2eaf1
movl %eax, %ecx
andb $0x7, %cl
movl $0x1, %edx
shll %cl, %edx
shrl $0x3, %eax
orb %dl, (%r13,%rax)
leaq -0xf0(%rbp), %rax
leaq -0x88(%rbp), %rdi
movq %rax, 0x30(%rdi)
movq %rax, 0x38(%rdi)
movq $0x0, 0x28(%rdi)
movabsq $0x6400000000, %rax     # imm = 0x6400000000
movq %rax, 0x40(%rdi)
movl $0x3b9aca00, 0x48(%rdi) # imm = 0x3B9ACA00
movw $0x2, 0x4c(%rdi)
movq 0x18(%rbx), %rax
movq 0x50(%rax), %rax
movl 0x20(%rax), %edx
movl 0x24(%rax), %ecx
bswapl %edx
bswapl %ecx
leaq 0x4b544(%rip), %r8      # 0x7a087
movl $0x1, %esi
callq 0x34335
testl %r12d, %r12d
jle 0x2ebb5
cmpl $0x0, -0x6c(%rbp)
je 0x2ebb5
movl %r12d, %r14d
movl $0x1, %r13d
leaq -0x88(%rbp), %r12
movl -0x4(%r15,%r13,4), %esi
testl %esi, %esi
je 0x2eba7
cmpl $0x2, %esi
jl 0x2eb8e
cmpb $0x0, 0x21(%rbx)
je 0x2eb8e
movq %r12, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x34578
movl -0x4(%r15,%r13,4), %esi
movq %r12, %rdi
leaq 0x4b4fa(%rip), %rdx     # 0x7a097
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x34621
cmpq %r14, %r13
jae 0x2ebb5
incq %r13
cmpl $0x0, -0x6c(%rbp)
jne 0x2eb68
cmpl $0x0, -0x70(%rbp)
je 0x2ecec
cmpl $0x0, -0x6c(%rbp)
je 0x2ecec
movl $0x2, %r14d
leal -0x1(%r14), %r13d
movq -0x78(%rbp), %rax
movl %r13d, %r12d
shrl $0x3, %r12d
movl %r13d, %ecx
andb $0x7, %cl
movl $0x1, %r15d
shll %cl, %r15d
movzbl (%rax,%r12), %eax
movl %r13d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jb 0x2ec64
xorl %eax, %eax
cmpl $0x2, %r13d
jb 0x2ec3f
movl 0x34(%rbx), %esi
movl $0xcccccccd, %eax       # imm = 0xCCCCCCCD
imulq %rax, %rsi
shrq $0x22, %rsi
incl %esi
leal -0x3(%r14), %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %esi
subl %edx, %ecx
movl 0x65c17(%rip), %eax     # 0x94840
xorl %edx, %edx
divl 0x30(%rbx)
leal 0x1(%rcx), %edx
xorl %esi, %esi
cmpl %eax, %edx
sete %sil
leal (%rcx,%rsi), %eax
addl $0x2, %eax
cmpl %eax, %r13d
jne 0x2ec4a
cmpb $0x0, 0x21(%rbx)
jne 0x2ec64
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
leaq 0x4b452(%rip), %rdx     # 0x7a0ac
movl %r13d, %ecx
xorl %eax, %eax
callq 0x34ce9
movq -0x78(%rbp), %rax
movzbl (%rax,%r12), %eax
testl %eax, %r15d
je 0x2ecd9
xorl %eax, %eax
cmpl $0x2, %r13d
jb 0x2ecb4
movl 0x34(%rbx), %esi
movl $0xcccccccd, %eax       # imm = 0xCCCCCCCD
imulq %rax, %rsi
shrq $0x22, %rsi
incl %esi
leal -0x3(%r14), %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %esi
subl %edx, %ecx
movl 0x65ba2(%rip), %eax     # 0x94840
xorl %edx, %edx
divl 0x30(%rbx)
leal 0x1(%rcx), %edx
xorl %esi, %esi
cmpl %eax, %edx
sete %sil
leal (%rcx,%rsi), %eax
addl $0x2, %eax
cmpl %eax, %r13d
jne 0x2ecd9
cmpb $0x0, 0x21(%rbx)
je 0x2ecd9
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
leaq 0x4b3f3(%rip), %rdx     # 0x7a0c2
movl %r13d, %ecx
xorl %eax, %eax
callq 0x34ce9
cmpl -0x70(%rbp), %r14d
ja 0x2ecec
incl %r14d
cmpl $0x0, -0x6c(%rbp)
jne 0x2ebcf
movq (%rbx), %rax
movq 0x110(%rax), %rax
movl 0x18(%rax), %r8d
movl -0x2c(%rbp), %ecx
cmpl %r8d, %ecx
movq -0x38(%rbp), %rbx
je 0x2ed1d
leaq 0x4b3d7(%rip), %rdx     # 0x7a0e4
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x34ce9
leaq -0x60(%rbp), %r14
movq -0x18(%r14), %rdi
callq 0xa2e8
cmpl $0x0, -0x4(%r14)
je 0x2ed60
movq %r14, %rdi
callq 0x1749a
movl -0x68(%rbp), %eax
incl %eax
movl %eax, (%rbx)
jmp 0x2ed4c
movq -0x38(%rbp), %rax
movl $0x1, (%rax)
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x68(%rbp), %eax
movl %eax, (%rbx)
testl %eax, %eax
jne 0x2ed71
movq %r14, %rdi
callq 0x1749a
movq %r14, %rdi
callq 0xb6e7
jmp 0x2ed4e