// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: checkTreePage
static int checkTreePage(
  IntegrityCk *pCheck,  /* Context for the sanity check */
  int iPage,            /* Page number of the page to check */
  char *zParentContext, /* Parent context */
  i64 *pnParentMinKey, 
  i64 *pnParentMaxKey
){
  MemPage *pPage;
  int i, rc, depth, d2, pgno, cnt;
  int hdr, cellStart;
  int nCell;
  u8 *data;
  BtShared *pBt;
  int usableSize;
  char zContext[100];
  char *hit = 0;
  i64 nMinKey = 0;
  i64 nMaxKey = 0;

  sqlite3_snprintf(sizeof(zContext), zContext, "Page %d: ", iPage);

  /* Check that the page exists
  */
  pBt = pCheck->pBt;
  usableSize = pBt->usableSize;
  if( iPage==0 ) return 0;
  if( checkRef(pCheck, iPage, zParentContext) ) return 0;
  if( (rc = btreeGetPage(pBt, (Pgno)iPage, &pPage, 0))!=0 ){
    checkAppendMsg(pCheck, zContext,
       "unable to get the page. error code=%d", rc);
    return 0;
  }

  /* Clear MemPage.isInit to make sure the corruption detection code in
  ** btreeInitPage() is executed.  */
  pPage->isInit = 0;
  if( (rc = btreeInitPage(pPage))!=0 ){
    assert( rc==SQLITE_CORRUPT );  /* The only possible error from InitPage */
    checkAppendMsg(pCheck, zContext, 
                   "btreeInitPage() returns error code %d", rc);
    releasePage(pPage);
    return 0;
  }

  /* Check out all the cells.
  */
  depth = 0;
  for(i=0; i<pPage->nCell && pCheck->mxErr; i++){
    u8 *pCell;
    u32 sz;
    CellInfo info;

    /* Check payload overflow pages
    */
    sqlite3_snprintf(sizeof(zContext), zContext,
             "On tree page %d cell %d: ", iPage, i);
    pCell = findCell(pPage,i);
    btreeParseCellPtr(pPage, pCell, &info);
    sz = info.nData;
    if( !pPage->intKey ) sz += (int)info.nKey;
    /* For intKey pages, check that the keys are in order.
    */
    else if( i==0 ) nMinKey = nMaxKey = info.nKey;
    else{
      if( info.nKey <= nMaxKey ){
        checkAppendMsg(pCheck, zContext, 
            "Rowid %lld out of order (previous was %lld)", info.nKey, nMaxKey);
      }
      nMaxKey = info.nKey;
    }
    assert( sz==info.nPayload );
    if( (sz>info.nLocal) 
     && (&pCell[info.iOverflow]<=&pPage->aData[pBt->usableSize])
    ){
      int nPage = (sz - info.nLocal + usableSize - 5)/(usableSize - 4);
      Pgno pgnoOvfl = get4byte(&pCell[info.iOverflow]);
#ifndef SQLITE_OMIT_AUTOVACUUM
      if( pBt->autoVacuum ){
        checkPtrmap(pCheck, pgnoOvfl, PTRMAP_OVERFLOW1, iPage, zContext);
      }
#endif
      checkList(pCheck, 0, pgnoOvfl, nPage, zContext);
    }

    /* Check sanity of left child page.
    */
    if( !pPage->leaf ){
      pgno = get4byte(pCell);
#ifndef SQLITE_OMIT_AUTOVACUUM
      if( pBt->autoVacuum ){
        checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage, zContext);
      }
#endif
      d2 = checkTreePage(pCheck, pgno, zContext, &nMinKey, i==0 ? NULL : &nMaxKey);
      if( i>0 && d2!=depth ){
        checkAppendMsg(pCheck, zContext, "Child page depth differs");
      }
      depth = d2;
    }
  }

  if( !pPage->leaf ){
    pgno = get4byte(&pPage->aData[pPage->hdrOffset+8]);
    sqlite3_snprintf(sizeof(zContext), zContext, 
                     "On page %d at right child: ", iPage);
#ifndef SQLITE_OMIT_AUTOVACUUM
    if( pBt->autoVacuum ){
      checkPtrmap(pCheck, pgno, PTRMAP_BTREE, iPage, zContext);
    }
#endif
    checkTreePage(pCheck, pgno, zContext, NULL, !pPage->nCell ? NULL : &nMaxKey);
  }
 
  /* For intKey leaf pages, check that the min/max keys are in order
  ** with any left/parent/right pages.
  */
  if( pPage->leaf && pPage->intKey ){
    /* if we are a left child page */
    if( pnParentMinKey ){
      /* if we are the left most child page */
      if( !pnParentMaxKey ){
        if( nMaxKey > *pnParentMinKey ){
          checkAppendMsg(pCheck, zContext, 
              "Rowid %lld out of order (max larger than parent min of %lld)",
              nMaxKey, *pnParentMinKey);
        }
      }else{
        if( nMinKey <= *pnParentMinKey ){
          checkAppendMsg(pCheck, zContext, 
              "Rowid %lld out of order (min less than parent min of %lld)",
              nMinKey, *pnParentMinKey);
        }
        if( nMaxKey > *pnParentMaxKey ){
          checkAppendMsg(pCheck, zContext, 
              "Rowid %lld out of order (max larger than parent max of %lld)",
              nMaxKey, *pnParentMaxKey);
        }
        *pnParentMinKey = nMaxKey;
      }
    /* else if we're a right child page */
    } else if( pnParentMaxKey ){
      if( nMinKey <= *pnParentMaxKey ){
        checkAppendMsg(pCheck, zContext, 
            "Rowid %lld out of order (min less than parent max of %lld)",
            nMinKey, *pnParentMaxKey);
      }
    }
  }

  /* Check for complete coverage of the page
  */
  data = pPage->aData;
  hdr = pPage->hdrOffset;
  hit = sqlite3PageMalloc( pBt->pageSize );
  if( hit==0 ){
    pCheck->mallocFailed = 1;
  }else{
    int contentOffset = get2byteNotZero(&data[hdr+5]);
    assert( contentOffset<=usableSize );  /* Enforced by btreeInitPage() */
    memset(hit+contentOffset, 0, usableSize-contentOffset);
    memset(hit, 1, contentOffset);
    nCell = get2byte(&data[hdr+3]);
    cellStart = hdr + 12 - 4*pPage->leaf;
    for(i=0; i<nCell; i++){
      int pc = get2byte(&data[cellStart+i*2]);
      u32 size = 65536;
      int j;
      if( pc<=usableSize-4 ){
        size = cellSizePtr(pPage, &data[pc]);
      }
      if( (int)(pc+size-1)>=usableSize ){
        checkAppendMsg(pCheck, 0, 
            "Corruption detected in cell %d on page %d",i,iPage);
      }else{
        for(j=pc+size-1; j>=pc; j--) hit[j]++;
      }
    }
    i = get2byte(&data[hdr+1]);
    while( i>0 ){
      int size, j;
      assert( i<=usableSize-4 );     /* Enforced by btreeInitPage() */
      size = get2byte(&data[i+2]);
      assert( i+size<=usableSize );  /* Enforced by btreeInitPage() */
      for(j=i+size-1; j>=i; j--) hit[j]++;
      j = get2byte(&data[i]);
      assert( j==0 || j>i+size );  /* Enforced by btreeInitPage() */
      assert( j<=usableSize-4 );   /* Enforced by btreeInitPage() */
      i = j;
    }
    for(i=cnt=0; i<usableSize; i++){
      if( hit[i]==0 ){
        cnt++;
      }else if( hit[i]>1 ){
        checkAppendMsg(pCheck, 0,
          "Multiple uses for byte %d of page %d", i, iPage);
        break;
      }
    }
    if( cnt!=data[hdr+7] ){
      checkAppendMsg(pCheck, 0, 
          "Fragmentation of %d bytes reported as %d on page %d",
          cnt, data[hdr+7], iPage);
    }
  }
  sqlite3PageFree(hit);
  releasePage(pPage);
  return depth+1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %r8, %r13
movq %rcx, %r12
movq %rdx, %r15
movl %esi, %r14d
movq %rdi, %rbx
xorl %eax, %eax
movq %rax, -0x88(%rbp)
movq $0x0, -0x68(%rbp)
movq %rax, -0x50(%rbp)
leaq 0x45bbc(%rip), %rdx     # 0x7a21c
leaq -0x120(%rbp), %rsi
movl $0x64, %edi
movl %r14d, %ecx
xorl %eax, %eax
callq 0xb859
testl %r14d, %r14d
je 0x34cd3
movq %r13, -0x60(%rbp)
movq %r12, -0x80(%rbp)
movq (%rbx), %r12
movl 0x34(%r12), %r13d
movq %rbx, %rdi
movl %r14d, %esi
movq %r15, %rdx
callq 0x34de1
testl %eax, %eax
jne 0x34cd3
movq %rbx, -0x38(%rbp)
leaq -0x90(%rbp), %rdx
movq $0x0, -0x68(%rbp)
movq %r12, %rdi
movl %r14d, %esi
xorl %ecx, %ecx
callq 0x2035c
testl %eax, %eax
je 0x346e9
leaq 0x45b56(%rip), %rdx     # 0x7a226
leaq -0x120(%rbp), %rsi
movq -0x38(%rbp), %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x34ce9
jmp 0x34cd3
movq %r12, -0x40(%rbp)
movq -0x90(%rbp), %r15
movb $0x0, (%r15)
movq %r15, %rdi
callq 0x1cb41
testl %eax, %eax
je 0x3472c
leaq 0x45b41(%rip), %rdx     # 0x7a24c
movq $0x0, -0x68(%rbp)
leaq -0x120(%rbp), %rsi
movq -0x38(%rbp), %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x34ce9
jmp 0x34cca
cmpw $0x0, 0x10(%r15)
movq -0x38(%rbp), %rbx
movq %r15, -0x48(%rbp)
movq %r13, -0x70(%rbp)
movl %r14d, -0x2c(%rbp)
je 0x34952
leal -0x5(%r13), %eax
movl %eax, -0x68(%rbp)
leal -0x4(%r13), %eax
movl %eax, -0x58(%rbp)
xorl %r13d, %r13d
xorl %r14d, %r14d
cmpl $0x0, 0x1c(%rbx)
je 0x3495a
movl $0x64, %edi
leaq -0x120(%rbp), %rsi
leaq 0x45af9(%rip), %rdx     # 0x7a272
movl -0x2c(%rbp), %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0xb859
movzwl 0x12(%r15), %eax
movq 0x60(%r15), %rcx
movzbl (%rcx,%r13,2), %edx
shll $0x8, %edx
movzbl 0x1(%rcx,%r13,2), %r12d
orl %edx, %r12d
andl %eax, %r12d
addq 0x50(%r15), %r12
movq %r15, %rdi
movq %r12, %rsi
leaq -0xb0(%rbp), %rdx
callq 0x21585
movq %r15, %rax
movl -0xa0(%rbp), %r15d
cmpb $0x0, 0x2(%rax)
je 0x34800
movq -0xb0(%rbp), %rbx
testq %r13, %r13
je 0x34809
movq -0x50(%rbp), %r8
cmpq %r8, %rbx
jg 0x347fa
movq -0x38(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq 0x45a9c(%rip), %rdx     # 0x7a28c
movq %rbx, %rcx
xorl %eax, %eax
callq 0x34ce9
movq %rbx, -0x50(%rbp)
jmp 0x34814
addl -0xb0(%rbp), %r15d
jmp 0x34814
movq %rbx, -0x50(%rbp)
movq %rbx, -0x88(%rbp)
movzwl -0x96(%rbp), %eax
cmpl %eax, %r15d
jbe 0x3489f
movzwl -0x94(%rbp), %ecx
addq %r12, %rcx
movq -0x40(%rbp), %rdx
movl 0x34(%rdx), %edx
movq -0x48(%rbp), %rsi
addq 0x50(%rsi), %rdx
cmpq %rdx, %rcx
ja 0x3489f
addl -0x68(%rbp), %r15d
subl %eax, %r15d
movl %r15d, %eax
xorl %edx, %edx
divl -0x58(%rbp)
movl %eax, %r8d
movl (%rcx), %ebx
bswapl %ebx
movq -0x40(%rbp), %rax
cmpb $0x0, 0x21(%rax)
movq -0x38(%rbp), %r15
leaq -0x120(%rbp), %rax
je 0x3488d
movq %r15, %rdi
movl %ebx, %esi
movl $0x3, %edx
movl -0x2c(%rbp), %ecx
movl %r8d, -0x78(%rbp)
movq %rax, %r8
callq 0x34578
leaq -0x120(%rbp), %rax
movl -0x78(%rbp), %r8d
movq %r15, %rdi
xorl %esi, %esi
movl %ebx, %edx
movl %r8d, %ecx
movq %rax, %r8
callq 0x34335
movq -0x48(%rbp), %r15
cmpb $0x0, 0x3(%r15)
je 0x348b6
movl %r14d, %r12d
movq -0x38(%rbp), %rbx
jmp 0x3493c
movl (%r12), %ebx
bswapl %ebx
movq -0x40(%rbp), %rax
cmpb $0x0, 0x21(%rax)
movq -0x38(%rbp), %r15
leaq -0x120(%rbp), %r12
je 0x348e6
movq %r15, %rdi
movl %ebx, %esi
movl $0x5, %edx
movl -0x2c(%rbp), %ecx
movq %r12, %r8
callq 0x34578
testq %r13, %r13
leaq -0x50(%rbp), %r8
cmoveq %r13, %r8
movq %r15, %rdi
movl %ebx, %esi
movq %r12, %rdx
leaq -0x88(%rbp), %rcx
callq 0x34621
movl %eax, %r12d
testq %r13, %r13
je 0x34934
cmpl %r14d, %r12d
movq -0x48(%rbp), %r15
je 0x348ad
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq -0x120(%rbp), %rsi
leaq 0x4598d(%rip), %rdx     # 0x7a2b8
xorl %eax, %eax
callq 0x34ce9
jmp 0x3493c
movq -0x38(%rbp), %rbx
movq -0x48(%rbp), %r15
incq %r13
movzwl 0x10(%r15), %eax
movl %r12d, %r14d
cmpq %rax, %r13
jb 0x3475c
jmp 0x3495d
movl $0x1, %r12d
jmp 0x34964
movl %r14d, %r12d
incl %r12d
movl -0x2c(%rbp), %r14d
cmpb $0x0, 0x3(%r15)
jne 0x349e7
movq 0x50(%r15), %rax
movzbl 0x5(%r15), %ecx
movl 0x8(%rax,%rcx), %r15d
bswapl %r15d
leaq 0x4594e(%rip), %rdx     # 0x7a2d1
leaq -0x120(%rbp), %rsi
movl $0x64, %edi
movl %r14d, %ecx
xorl %eax, %eax
callq 0xb859
movq -0x40(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x349bd
leaq -0x120(%rbp), %r8
movq %rbx, %rdi
movl %r15d, %esi
movl $0x5, %edx
movl %r14d, %ecx
callq 0x34578
xorl %eax, %eax
movq -0x48(%rbp), %rcx
cmpw $0x0, 0x10(%rcx)
leaq -0x50(%rbp), %r8
cmoveq %rax, %r8
leaq -0x120(%rbp), %rdx
movq %rbx, %rdi
movl %r15d, %esi
movq %rcx, %r15
xorl %ecx, %ecx
callq 0x34621
movq %r12, -0x68(%rbp)
cmpb $0x0, 0x3(%r15)
je 0x34ab1
cmpb $0x0, 0x2(%r15)
je 0x34ab1
movq -0x80(%rbp), %rax
testq %rax, %rax
je 0x34a6d
movq (%rax), %r8
cmpq $0x0, -0x60(%rbp)
je 0x34a90
movq -0x88(%rbp), %rcx
cmpq %r8, %rcx
jg 0x34a38
leaq 0x45903(%rip), %rdx     # 0x7a32a
leaq -0x120(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x34ce9
movq -0x50(%rbp), %rcx
movq -0x60(%rbp), %rax
movq (%rax), %r8
cmpq %r8, %rcx
jle 0x34a60
leaq 0x45916(%rip), %rdx     # 0x7a365
leaq -0x120(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x34ce9
movq -0x50(%rbp), %rax
movq -0x80(%rbp), %rcx
movq %rax, (%rcx)
jmp 0x34ab1
cmpq $0x0, -0x60(%rbp)
je 0x34ab1
movq -0x88(%rbp), %rcx
movq -0x60(%rbp), %rax
movq (%rax), %r8
cmpq %r8, %rcx
jg 0x34ab1
leaq 0x45914(%rip), %rdx     # 0x7a3a2
jmp 0x34aa0
movq -0x50(%rbp), %rcx
cmpq %r8, %rcx
jle 0x34ab1
leaq 0x4584d(%rip), %rdx     # 0x7a2ed
leaq -0x120(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x34ce9
movq 0x50(%r15), %r12
movzbl 0x5(%r15), %r13d
movq -0x40(%rbp), %rax
movl 0x30(%rax), %edi
callq 0x1ce52
testq %rax, %rax
je 0x34c70
movzbl 0x5(%r12,%r13), %edx
shll $0x8, %edx
movzbl 0x6(%r12,%r13), %ecx
addl %edx, %ecx
decl %ecx
movzwl %cx, %ecx
leaq (%rax,%rcx), %rdi
incq %rdi
leaq 0x1(%rcx), %rbx
notl %ecx
addl -0x70(%rbp), %ecx
movslq %ecx, %rdx
xorl %esi, %esi
movq %rax, %r14
callq 0x8200
movq %r14, -0x58(%rbp)
movq %r14, %rdi
movl $0x1, %esi
movq %rbx, %rdx
callq 0x8200
movq %r12, -0x40(%rbp)
movq %r13, -0x78(%rbp)
movzwl 0x3(%r12,%r13), %eax
rolw $0x8, %ax
testw %ax, %ax
je 0x34bdf
movzwl %ax, %eax
movq -0x48(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
shll $0x2, %ecx
movq -0x78(%rbp), %rdx
subq %rcx, %rdx
movq -0x70(%rbp), %rcx
addl $-0x4, %ecx
movl %ecx, -0x60(%rbp)
movl %eax, %eax
movq %rax, -0x80(%rbp)
movq -0x40(%rbp), %rax
leaq (%rdx,%rax), %r12
addq $0xc, %r12
xorl %r13d, %r13d
movzbl (%r12,%r13,2), %ebx
shll $0x8, %ebx
movzbl 0x1(%r12,%r13,2), %r15d
leal (%rbx,%r15), %r14d
movl $0x10000, %ecx          # imm = 0x10000
cmpl -0x60(%rbp), %r14d
jg 0x34b95
movl %r14d, %esi
addq -0x40(%rbp), %rsi
movq -0x48(%rbp), %rdi
callq 0x3072b
movzwl %ax, %ecx
leal (%rcx,%r14), %eax
cmpl -0x70(%rbp), %eax
jle 0x34bbb
movq -0x38(%rbp), %rdi
xorl %esi, %esi
leaq 0x45832(%rip), %rdx     # 0x7a3dd
movl %r13d, %ecx
movl -0x2c(%rbp), %r8d
xorl %eax, %eax
callq 0x34ce9
jmp 0x34bd6
testl %ecx, %ecx
je 0x34bd6
addl %ebx, %ecx
addl %r15d, %ecx
decl %ecx
addq -0x58(%rbp), %rcx
incb (%rcx)
decl %eax
decq %rcx
cmpl %r14d, %eax
jg 0x34bca
incq %r13
cmpq -0x80(%rbp), %r13
jne 0x34b65
movq -0x40(%rbp), %rbx
movq -0x78(%rbp), %r12
movzwl 0x1(%rbx,%r12), %ecx
rolw $0x8, %cx
testw %cx, %cx
movq -0x48(%rbp), %r15
movq -0x70(%rbp), %rdi
movq -0x58(%rbp), %rax
je 0x34c47
movzwl %cx, %ecx
movl %ecx, %r8d
movzbl 0x2(%rbx,%r8), %edx
shll $0x8, %edx
movzbl 0x3(%rbx,%r8), %esi
movl %edx, %ecx
orl %esi, %ecx
je 0x34c36
addl %r8d, %ecx
addl %r8d, %edx
addl %esi, %edx
decl %edx
addq %rax, %rdx
incb (%rdx)
decl %ecx
decq %rdx
cmpl %r8d, %ecx
jg 0x34c2a
movzwl (%rbx,%r8), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
testw %cx, %cx
jne 0x34c05
testl %edi, %edi
movq -0x38(%rbp), %r14
jle 0x34c79
xorl %ecx, %ecx
xorl %r13d, %r13d
movb (%rax,%rcx), %dl
testb %dl, %dl
je 0x34c62
cmpb $0x2, %dl
jl 0x34c65
jmp 0x34c7e
incl %r13d
incq %rcx
cmpq %rcx, -0x70(%rbp)
jne 0x34c54
jmp 0x34c99
movl $0x1, 0x24(%rbx)
jmp 0x34cc2
xorl %r13d, %r13d
jmp 0x34c99
leaq 0x45782(%rip), %rdx     # 0x7a407
movq %r14, %rdi
xorl %esi, %esi
movl -0x2c(%rbp), %r8d
xorl %eax, %eax
callq 0x34ce9
movq -0x58(%rbp), %rax
movzbl 0x7(%rbx,%r12), %r8d
cmpl %r8d, %r13d
je 0x34cc2
leaq 0x45781(%rip), %rdx     # 0x7a42c
movq %r14, %rdi
xorl %esi, %esi
movl %r13d, %ecx
movl -0x2c(%rbp), %r9d
xorl %eax, %eax
callq 0x34ce9
movq -0x58(%rbp), %rax
movq %rax, %rdi
callq 0x1cf8c
movq 0x68(%r15), %rdi
callq 0xdcd4
movq -0x68(%rbp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq