// File: /workspace/github_c_makefile_star2_O3/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
movq %rdx, %r12
movq %rdi, 0x8(%rsi)
movq (%rsi), %rax
movq 0x110(%rax), %rdx
movl 0x18(%rdx), %edx
movq %rsi, -0x88(%rbp)
movq %rax, -0x80(%rbp)
movl 0x3c(%rsi), %r14d
movl %r14d, -0x70(%rbp)
movl %r8d, -0x6c(%rbp)
movq $0x0, -0x68(%rbp)
movl $0x0, (%r9)
testq %r14, %r14
je 0x2f5e8
movq %rsi, %r15
movl %ecx, -0x34(%rbp)
movl %edx, -0x38(%rbp)
movq %r9, -0x30(%rbp)
movl %r14d, %ebx
shrl $0x3, %ebx
incq %rbx
movl %ebx, %edi
callq 0xa38c
testq %rax, %rax
je 0x2f5de
movq %rax, %r13
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x8200
movq %r13, -0x78(%rbp)
movl 0x654eb(%rip), %eax     # 0x94840
xorl %edx, %edx
divl 0x30(%r15)
incl %eax
cmpl %r14d, %eax
ja 0x2f376
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), %rbx
movq %rax, 0x30(%rbx)
movq %rax, 0x38(%rbx)
movq $0x0, 0x28(%rbx)
movabsq $0x6400000000, %rax     # imm = 0x6400000000
movq %rax, 0x40(%rbx)
movl $0x3b9aca00, 0x48(%rbx) # imm = 0x3B9ACA00
movw $0x2, 0x4c(%rbx)
movq 0x18(%r15), %rax
movq 0x50(%rax), %rax
movl 0x20(%rax), %edx
movl 0x24(%rax), %ecx
bswapl %edx
bswapl %ecx
leaq 0x4acbf(%rip), %r8      # 0x7a087
movq %rbx, %rdi
movl $0x1, %esi
callq 0x34a7b
movl -0x34(%rbp), %esi
testl %esi, %esi
setg %cl
movl 0x1c(%rbx), %eax
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x2f44a
movl %esi, %ebx
movl $0x1, %r13d
leaq -0x88(%rbp), %r14
movl -0x4(%r12,%r13,4), %esi
testl %esi, %esi
je 0x2f43e
cmpl $0x2, %esi
jl 0x2f427
cmpb $0x0, 0x21(%r15)
je 0x2f427
movq %r14, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x34cca
movl -0x4(%r12,%r13,4), %esi
movq %r14, %rdi
leaq 0x4ac66(%rip), %rdx     # 0x7a097
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x34d73
movl -0x6c(%rbp), %eax
cmpq %rbx, %r13
jae 0x2f44a
incq %r13
testl %eax, %eax
jne 0x2f3fb
cmpl $0x0, -0x70(%rbp)
setne %cl
testl %eax, %eax
setne %al
andb %cl, %al
cmpb $0x1, %al
jne 0x2f588
movl $0x2, %ebx
leal -0x1(%rbx), %r14d
movq -0x78(%rbp), %rax
movl %r14d, %r13d
shrl $0x3, %r13d
movl %r14d, %ecx
andb $0x7, %cl
movl $0x1, %r12d
shll %cl, %r12d
movzbl (%rax,%r13), %eax
movl %r14d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jb 0x2f50e
xorl %eax, %eax
cmpl $0x2, %r14d
jb 0x2f4d6
movl 0x34(%r15), %esi
movl $0xcccccccd, %eax       # imm = 0xCCCCCCCD
imulq %rax, %rsi
shrq $0x22, %rsi
incl %esi
leal -0x3(%rbx), %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %esi
subl %edx, %ecx
movl 0x65381(%rip), %eax     # 0x94840
xorl %edx, %edx
divl 0x30(%r15)
leal 0x1(%rcx), %edx
xorl %esi, %esi
cmpl %eax, %edx
sete %sil
leal (%rcx,%rsi), %eax
addl $0x2, %eax
cmpl %eax, %r14d
jne 0x2f4e6
cmpb $0x0, 0x21(%r15)
jne 0x2f577
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
leaq 0x4abb6(%rip), %rdx     # 0x7a0ac
movl %r14d, %ecx
xorl %eax, %eax
callq 0x3542e
movq -0x78(%rbp), %rax
movzbl (%rax,%r13), %eax
testl %eax, %r12d
je 0x2f577
xorl %eax, %eax
cmpl $0x2, %r14d
jb 0x2f551
movl 0x34(%r15), %esi
movl $0xcccccccd, %eax       # imm = 0xCCCCCCCD
imulq %rax, %rsi
shrq $0x22, %rsi
incl %esi
leal -0x3(%rbx), %ecx
movl %ecx, %eax
xorl %edx, %edx
divl %esi
subl %edx, %ecx
movl 0x65306(%rip), %eax     # 0x94840
xorl %edx, %edx
divl 0x30(%r15)
leal 0x1(%rcx), %edx
xorl %esi, %esi
cmpl %eax, %edx
sete %sil
leal (%rcx,%rsi), %eax
addl $0x2, %eax
cmpl %eax, %r14d
jne 0x2f577
cmpb $0x0, 0x21(%r15)
je 0x2f577
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
leaq 0x4ab55(%rip), %rdx     # 0x7a0c2
movl %r14d, %ecx
xorl %eax, %eax
callq 0x3542e
cmpl -0x70(%rbp), %ebx
ja 0x2f588
incl %ebx
cmpl $0x0, -0x6c(%rbp)
jne 0x2f465
movq (%r15), %rax
movq 0x110(%rax), %rax
movl 0x18(%rax), %r8d
movl -0x38(%rbp), %ecx
cmpl %r8d, %ecx
je 0x2f5b5
leaq 0x4ab3f(%rip), %rdx     # 0x7a0e4
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x3542e
leaq -0x60(%rbp), %r14
movq -0x18(%r14), %rdi
callq 0xa3c7
cmpl $0x0, -0x4(%r14)
je 0x2f5fc
movq %r14, %rdi
callq 0x1749c
movl -0x68(%rbp), %eax
incl %eax
movq -0x30(%rbp), %rcx
movl %eax, (%rcx)
jmp 0x2f5e8
movq -0x30(%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
movq -0x30(%rbp), %rcx
movl %eax, (%rcx)
testl %eax, %eax
jne 0x2f611
movq %r14, %rdi
callq 0x1749c
movq %r14, %rdi
callq 0xb7d6
jmp 0x2f5ea