// File: /workspace/github_c_makefile_star2_O0/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
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
callq 0xe0f0
movq -0x88(%rbp), %rax
movq (%rax), %rdi
callq 0x47780
movl %eax, -0x30(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movq -0x80(%rbp), %rdi
callq 0x2ab10
movl %eax, -0x68(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x64(%rbp)
movl $0x0, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
cmpl $0x0, -0x68(%rbp)
jne 0x3ec2d
movq $0x0, -0x8(%rbp)
jmp 0x3ef3f
movl -0x68(%rbp), %edi
shrl $0x3, %edi
addl $0x1, %edi
callq 0xd860
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x3ec5d
movq -0x28(%rbp), %rax
movl $0x1, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x3ef3f
movl 0x91c6d(%rip), %eax     # 0xd08d0
movq -0x88(%rbp), %rcx
xorl %edx, %edx
divl 0x30(%rcx)
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x68(%rbp), %eax
ja 0x3ec89
movl -0x2c(%rbp), %esi
leaq -0x80(%rbp), %rdi
callq 0x477b0
leaq -0x80(%rbp), %rdi
addq $0x28, %rdi
leaq -0xf0(%rbp), %rsi
movl $0x64, %edx
movl $0x3b9aca00, %ecx       # imm = 0x3B9ACA00
callq 0xa720
movb $0x2, -0x34(%rbp)
movq -0x88(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x20, %rdi
callq 0x20a50
movl %eax, -0xf4(%rbp)
movq -0x88(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x24, %rdi
callq 0x20a50
movl -0xf4(%rbp), %edx
movl %eax, %ecx
leaq -0x80(%rbp), %rdi
movl $0x1, %esi
leaq 0x6fe8a(%rip), %r8      # 0xaeb83
callq 0x477f0
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x1c(%rbp), %ecx
movb %al, -0xf5(%rbp)
jge 0x3ed22
cmpl $0x0, -0x64(%rbp)
setne %al
movb %al, -0xf5(%rbp)
movb -0xf5(%rbp), %al
testb $0x1, %al
jne 0x3ed2e
jmp 0x3eda9
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
jne 0x3ed3d
jmp 0x3ed9b
movq -0x88(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x0, %eax
je 0x3ed79
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
cmpl $0x1, (%rax,%rcx,4)
jle 0x3ed79
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %esi
leaq -0x80(%rbp), %rdi
movl $0x1, %edx
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r8d
callq 0x47a30
movq -0x18(%rbp), %rax
movl -0x2c(%rbp), %ecx
movl (%rax,%rcx,4), %esi
leaq -0x80(%rbp), %rdi
leaq 0x6fe05(%rip), %rdx     # 0xaeb93
xorl %eax, %eax
movl %eax, %r8d
movq %r8, %rcx
callq 0x47af0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3ed05
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %ecx
xorl %eax, %eax
cmpl -0x68(%rbp), %ecx
movb %al, -0xf6(%rbp)
ja 0x3edcd
cmpl $0x0, -0x64(%rbp)
setne %al
movb %al, -0xf6(%rbp)
movb -0xf6(%rbp), %al
testb $0x1, %al
jne 0x3eddc
jmp 0x3ee85
movl -0x2c(%rbp), %esi
leaq -0x80(%rbp), %rdi
callq 0x48510
cmpl $0x0, %eax
jne 0x3ee27
movq -0x88(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x2b950
cmpl -0x2c(%rbp), %eax
jne 0x3ee0e
movq -0x88(%rbp), %rax
cmpb $0x0, 0x21(%rax)
jne 0x3ee27
movl -0x2c(%rbp), %ecx
leaq -0x80(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0x6fd88(%rip), %rdx     # 0xaeba8
movb $0x0, %al
callq 0x48550
movl -0x2c(%rbp), %esi
leaq -0x80(%rbp), %rdi
callq 0x48510
cmpl $0x0, %eax
je 0x3ee75
movq -0x88(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x2b950
cmpl -0x2c(%rbp), %eax
jne 0x3ee75
movq -0x88(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x0, %eax
je 0x3ee75
movl -0x2c(%rbp), %ecx
leaq -0x80(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0x6fd50(%rip), %rdx     # 0xaebbe
movb $0x0, %al
callq 0x48550
jmp 0x3ee77
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3edb0
movl -0x30(%rbp), %eax
movl %eax, -0xfc(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rdi
callq 0x47780
movl %eax, %ecx
movl -0xfc(%rbp), %eax
cmpl %ecx, %eax
je 0x3eee0
movl -0x30(%rbp), %eax
movl %eax, -0x100(%rbp)
movq -0x88(%rbp), %rax
movq (%rax), %rdi
callq 0x47780
movl -0x100(%rbp), %ecx
movl %eax, %r8d
leaq -0x80(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0x6fd07(%rip), %rdx     # 0xaebe0
movb $0x0, %al
callq 0x48550
movq -0x70(%rbp), %rdi
callq 0xa420
cmpl $0x0, -0x5c(%rbp)
je 0x3ef12
leaq -0x80(%rbp), %rdi
addq $0x28, %rdi
callq 0x1be70
movl -0x60(%rbp), %ecx
addl $0x1, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x3ef3f
movl -0x60(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x60(%rbp)
jne 0x3ef2e
leaq -0x80(%rbp), %rdi
addq $0x28, %rdi
callq 0x1be70
leaq -0x80(%rbp), %rdi
addq $0x28, %rdi
callq 0xc310
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax)