// File: /workspace/github_c_makefile_star2_O0/ukontainer[P]sqlite-bench/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;
  IntegrityCk sCheck;
  BtShared *pBt = p->pBt;
  int savedDbFlags = pBt->db->flags;
  char zErr[100];
  VVA_ONLY( int nRef );

  sqlite3BtreeEnter(p);
  assert( p->inTrans>TRANS_NONE && pBt->inTransaction>TRANS_NONE );
  VVA_ONLY( nRef = sqlite3PagerRefcount(pBt->pPager) );
  assert( nRef>=0 );
  sCheck.pBt = pBt;
  sCheck.pPager = pBt->pPager;
  sCheck.nPage = btreePagecount(sCheck.pBt);
  sCheck.mxErr = mxErr;
  sCheck.nErr = 0;
  sCheck.mallocFailed = 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.mallocFailed = 1;
    goto integrity_ck_cleanup;
  }
  sCheck.heap = (u32*)sqlite3PageMalloc( pBt->pageSize );
  if( sCheck.heap==0 ){
    sCheck.mallocFailed = 1;
    goto integrity_ck_cleanup;
  }

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

  /* Check the integrity of the freelist
  */
  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( pBt->autoVacuum ){
    int mx = 0;
    int 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 &= ~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 ){
      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
  */
  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.mallocFailed ){
    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 $0x120, %rsp            # imm = 0x120
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %eax
movl %eax, -0x94(%rbp)
movq -0x8(%rbp), %rdi
callq 0x40b350
movq -0x90(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x90(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x80(%rbp)
movq -0x88(%rbp), %rdi
callq 0x42cef0
movl %eax, -0x70(%rbp)
movl -0x18(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x64(%rbp)
movq $0x0, -0x60(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x30(%rbp)
leaq -0x88(%rbp), %rdi
addq $0x38, %rdi
leaq -0x100(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
movl $0x64, %ecx
movl $0x3b9aca00, %r8d       # imm = 0x3B9ACA00
callq 0x408fb0
movb $0x1, -0x33(%rbp)
cmpl $0x0, -0x70(%rbp)
jne 0x442c13
jmp 0x442f8a
movl -0x70(%rbp), %eax
shrl $0x3, %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x40aa30
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x442c3c
movl $0x1, -0x64(%rbp)
jmp 0x442f8a
movq -0x90(%rbp), %rax
movl 0x30(%rax), %edi
callq 0x42a1c0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x442c62
movl $0x1, -0x64(%rbp)
jmp 0x442f8a
movl 0x18b938(%rip), %eax    # 0x5ce5a0
movq -0x90(%rbp), %rcx
xorl %edx, %edx
divl 0x30(%rcx)
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x70(%rbp), %eax
ja 0x442c91
movl -0x24(%rbp), %esi
leaq -0x88(%rbp), %rdi
callq 0x450430
leaq 0x13c4e2(%rip), %rax    # 0x57f17a
movq %rax, -0x60(%rbp)
movq -0x90(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x20, %rdi
callq 0x420960
movl %eax, -0x114(%rbp)
movq -0x90(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x24, %rdi
callq 0x420960
movl -0x114(%rbp), %edx
movl %eax, %ecx
leaq -0x88(%rbp), %rdi
movl $0x1, %esi
callq 0x450470
movq $0x0, -0x60(%rbp)
movq -0x90(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x442d9b
movl $0x0, -0x104(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x442d4c
movl -0x104(%rbp), %eax
movq -0x10(%rbp), %rcx
movl -0x24(%rbp), %edx
cmpl (%rcx,%rdx,4), %eax
jge 0x442d3f
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x104(%rbp)
jmp 0x442d41
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x442d15
movq -0x90(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x34, %rdi
callq 0x420960
movl %eax, -0x108(%rbp)
movl -0x104(%rbp), %eax
cmpl -0x108(%rbp), %eax
je 0x442d99
movl -0x104(%rbp), %edx
movl -0x108(%rbp), %ecx
leaq -0x88(%rbp), %rdi
leaq 0x13c3f8(%rip), %rsi    # 0x57f18a
movb $0x0, %al
callq 0x4506b0
jmp 0x442dcf
movq -0x90(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x50(%rax), %rdi
addq $0x40, %rdi
callq 0x420960
cmpl $0x0, %eax
je 0x442dcd
leaq -0x88(%rbp), %rdi
leaq 0x13c3f1(%rip), %rsi    # 0x57f1b7
movb $0x0, %al
callq 0x4506b0
jmp 0x442dcf
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %ecx
andl $0xffdfffff, %ecx       # imm = 0xFFDFFFFF
movl %ecx, 0x30(%rax)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %ecx
xorl %eax, %eax
cmpl -0x14(%rbp), %ecx
movb %al, -0x115(%rbp)
jge 0x442e0a
cmpl $0x0, -0x6c(%rbp)
setne %al
movb %al, -0x115(%rbp)
movb -0x115(%rbp), %al
testb $0x1, %al
jne 0x442e16
jmp 0x442e94
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
jne 0x442e25
jmp 0x442e86
movq -0x90(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x0, %eax
je 0x442e5f
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
cmpl $0x1, (%rax,%rcx,4)
jle 0x442e5f
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %esi
leaq -0x88(%rbp), %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x4507f0
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %esi
leaq -0x88(%rbp), %rdi
leaq -0x110(%rbp), %rdx
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
callq 0x4508a0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x442ded
movl -0x94(%rbp), %ecx
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
movl %ecx, 0x30(%rax)
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %ecx
xorl %eax, %eax
cmpl -0x70(%rbp), %ecx
movb %al, -0x116(%rbp)
ja 0x442ecc
cmpl $0x0, -0x6c(%rbp)
setne %al
movb %al, -0x116(%rbp)
movb -0x116(%rbp), %al
testb $0x1, %al
jne 0x442edb
jmp 0x442f88
movl -0x24(%rbp), %esi
leaq -0x88(%rbp), %rdi
callq 0x451100
cmpl $0x0, %eax
jne 0x442f28
movq -0x90(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x42dd40
cmpl -0x24(%rbp), %eax
jne 0x442f10
movq -0x90(%rbp), %rax
cmpb $0x0, 0x21(%rax)
jne 0x442f28
movl -0x24(%rbp), %edx
leaq -0x88(%rbp), %rdi
leaq 0x13c2cd(%rip), %rsi    # 0x57f1ee
movb $0x0, %al
callq 0x4506b0
movl -0x24(%rbp), %esi
leaq -0x88(%rbp), %rdi
callq 0x451100
cmpl $0x0, %eax
je 0x442f78
movq -0x90(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x42dd40
cmpl -0x24(%rbp), %eax
jne 0x442f78
movq -0x90(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x0, %eax
je 0x442f78
movl -0x24(%rbp), %edx
leaq -0x88(%rbp), %rdi
leaq 0x13c293(%rip), %rsi    # 0x57f204
movb $0x0, %al
callq 0x4506b0
jmp 0x442f7a
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x442eaf
jmp 0x442f8a
movq -0x30(%rbp), %rdi
callq 0x4210c0
movq -0x78(%rbp), %rdi
callq 0x406240
cmpl $0x0, -0x64(%rbp)
je 0x442fbb
leaq -0x88(%rbp), %rdi
addq $0x38, %rdi
callq 0x408ec0
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x68(%rbp)
jne 0x442fda
leaq -0x88(%rbp), %rdi
addq $0x38, %rdi
callq 0x408ec0
movq -0x8(%rbp), %rdi
callq 0x40c4a0
leaq -0x88(%rbp), %rdi
addq $0x38, %rdi
callq 0x408da0
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nopl (%rax)