// File: /workspace/github_c_makefile_star2_O3/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, -0x60(%rbp)
movq %rcx, %r13
movq %rdx, %r15
movl %esi, %ebx
movq %rdi, %r14
xorl %eax, %eax
movq %rax, -0x78(%rbp)
movq $0x0, -0x68(%rbp)
movq %rax, -0x50(%rbp)
leaq 0x4546d(%rip), %rdx     # 0x7a21c
leaq -0x120(%rbp), %rsi
movl $0x64, %edi
movl %ebx, %ecx
xorl %eax, %eax
callq 0xb954
testl %ebx, %ebx
je 0x35418
movq %r13, -0x80(%rbp)
movq (%r14), %r13
movl 0x34(%r13), %r12d
movq %r14, %rdi
movl %ebx, %esi
movq %r15, %rdx
callq 0x35526
testl %eax, %eax
jne 0x35418
movq %r14, -0x38(%rbp)
movq %r12, -0x58(%rbp)
leaq -0x90(%rbp), %rdx
movq %r13, %rdi
movl %ebx, %esi
xorl %ecx, %ecx
callq 0x20068
testl %eax, %eax
je 0x34e33
movq $0x0, -0x68(%rbp)
leaq 0x4540c(%rip), %rdx     # 0x7a226
leaq -0x120(%rbp), %rsi
movq -0x38(%rbp), %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x3542e
jmp 0x35418
movl %ebx, -0x2c(%rbp)
movq %r13, -0x40(%rbp)
movq -0x90(%rbp), %r15
movb $0x0, (%r15)
movq %r15, %rdi
callq 0x1c99b
testl %eax, %eax
je 0x34e7d
leaq 0x453f4(%rip), %rdx     # 0x7a24c
movq $0x0, -0x68(%rbp)
leaq -0x120(%rbp), %rsi
movq -0x38(%rbp), %rdi
movl %eax, %ecx
xorl %eax, %eax
callq 0x3542e
movq 0x68(%r15), %rdi
jmp 0x35413
cmpw $0x0, 0x10(%r15)
movq -0x38(%rbp), %rbx
movq %r15, -0x48(%rbp)
movq -0x58(%rbp), %rax
je 0x350a8
leal -0x5(%rax), %ecx
movl %ecx, -0x68(%rbp)
addl $-0x4, %eax
movl %eax, -0x70(%rbp)
xorl %r13d, %r13d
xorl %r14d, %r14d
cmpl $0x0, 0x1c(%rbx)
je 0x350b0
movl $0x64, %edi
leaq -0x120(%rbp), %rsi
leaq 0x453ae(%rip), %rdx     # 0x7a272
movl -0x2c(%rbp), %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0xb954
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 0x2121e
movq %r15, %rax
movl -0xa0(%rbp), %r15d
cmpb $0x0, 0x2(%rax)
je 0x34f4b
movq -0xb0(%rbp), %rbx
testq %r13, %r13
je 0x34f54
movq -0x50(%rbp), %r8
cmpq %r8, %rbx
jg 0x34f45
movq -0x38(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq 0x45351(%rip), %rdx     # 0x7a28c
movq %rbx, %rcx
xorl %eax, %eax
callq 0x3542e
movq %rbx, -0x50(%rbp)
jmp 0x34f5c
addl -0xb0(%rbp), %r15d
jmp 0x34f60
movq %rbx, -0x50(%rbp)
movq %rbx, -0x78(%rbp)
movq -0x38(%rbp), %rbx
movzwl -0x96(%rbp), %eax
cmpl %eax, %r15d
jbe 0x34ff7
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 0x34ff7
addl -0x68(%rbp), %r15d
subl %eax, %r15d
movl %r15d, %eax
xorl %edx, %edx
divl -0x70(%rbp)
movl %eax, %r8d
movq %rbx, %r15
movl (%rcx), %ebx
bswapl %ebx
movq -0x40(%rbp), %rax
cmpb $0x0, 0x21(%rax)
leaq -0x120(%rbp), %rax
je 0x34fe2
movq %r15, %rdi
movl %ebx, %esi
movl $0x3, %edx
movl -0x2c(%rbp), %ecx
movl %r8d, -0x84(%rbp)
movq %rax, %r8
callq 0x34cca
leaq -0x120(%rbp), %rax
movl -0x84(%rbp), %r8d
movq %r15, %rdi
xorl %esi, %esi
movl %ebx, %edx
movl %r8d, %ecx
movq %rax, %r8
callq 0x34a7b
movq %r15, %rbx
movq -0x48(%rbp), %r15
cmpb $0x0, 0x3(%r15)
je 0x3500a
movl %r14d, %r12d
jmp 0x35092
movq %rbx, %r15
movl (%r12), %ebx
bswapl %ebx
movq -0x40(%rbp), %rax
cmpb $0x0, 0x21(%rax)
leaq -0x120(%rbp), %r12
je 0x35039
movq %r15, %rdi
movl %ebx, %esi
movl $0x5, %edx
movl -0x2c(%rbp), %ecx
movq %r12, %r8
callq 0x34cca
testq %r13, %r13
leaq -0x50(%rbp), %r8
cmoveq %r13, %r8
movq %r15, %rdi
movl %ebx, %esi
movq %r12, %rdx
leaq -0x78(%rbp), %rcx
callq 0x34d73
movl %eax, %r12d
testq %r13, %r13
je 0x3508a
cmpl %r14d, %r12d
movq -0x48(%rbp), %r15
je 0x35084
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq -0x120(%rbp), %rsi
leaq 0x4523d(%rip), %rdx     # 0x7a2b8
xorl %eax, %eax
callq 0x3542e
jmp 0x35092
movq -0x38(%rbp), %rbx
jmp 0x35092
movq -0x38(%rbp), %rbx
movq -0x48(%rbp), %r15
incq %r13
movzwl 0x10(%r15), %eax
movl %r12d, %r14d
cmpq %rax, %r13
jb 0x34ea7
jmp 0x350b3
movl $0x1, %r12d
jmp 0x350b6
movl %r14d, %r12d
incl %r12d
cmpb $0x0, 0x3(%r15)
movq -0x80(%rbp), %r13
jne 0x35150
movq 0x50(%r15), %rax
movzbl 0x5(%r15), %ecx
movl 0x8(%rax,%rcx), %r15d
bswapl %r15d
leaq 0x451f4(%rip), %rdx     # 0x7a2d1
leaq -0x120(%rbp), %rsi
movl $0x64, %edi
movl -0x2c(%rbp), %r14d
movl %r14d, %ecx
xorl %eax, %eax
callq 0xb954
movq -0x40(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x3511b
leaq -0x120(%rbp), %r8
movq %rbx, %rdi
movl %r15d, %esi
movl $0x5, %edx
movl %r14d, %ecx
callq 0x34cca
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 0x34d73
cmpb $0x0, 0x3(%r15)
je 0x351ff
cmpb $0x0, 0x2(%r15)
je 0x351ff
testq %r13, %r13
je 0x351be
movq (%r13), %r8
cmpq $0x0, -0x60(%rbp)
je 0x351de
movq -0x78(%rbp), %rcx
cmpq %r8, %rcx
jg 0x3518c
leaq 0x451af(%rip), %rdx     # 0x7a32a
leaq -0x120(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3542e
movq -0x50(%rbp), %rcx
movq -0x60(%rbp), %rax
movq (%rax), %r8
cmpq %r8, %rcx
jle 0x351b8
leaq 0x451c2(%rip), %rdx     # 0x7a365
leaq -0x120(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3542e
movq -0x50(%rbp), %rcx
movq %rcx, (%r13)
jmp 0x351ff
cmpq $0x0, -0x60(%rbp)
je 0x351ff
movq -0x78(%rbp), %rcx
movq -0x60(%rbp), %rax
movq (%rax), %r8
cmpq %r8, %rcx
jg 0x351ff
leaq 0x451c6(%rip), %rdx     # 0x7a3a2
jmp 0x351ee
movq -0x50(%rbp), %rcx
cmpq %r8, %rcx
jle 0x351ff
leaq 0x450ff(%rip), %rdx     # 0x7a2ed
leaq -0x120(%rbp), %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3542e
movq %r15, %rax
movq 0x50(%r15), %r15
movzbl 0x5(%rax), %r13d
movq -0x40(%rbp), %rax
movl 0x30(%rax), %edi
callq 0x1cc98
testq %rax, %rax
movq %r12, -0x68(%rbp)
je 0x353b0
movzbl 0x5(%r15,%r13), %edx
shll $0x8, %edx
movzbl 0x6(%r15,%r13), %ecx
addl %edx, %ecx
decl %ecx
movzwl %cx, %ecx
leaq (%rax,%rcx), %rdi
incq %rdi
leaq 0x1(%rcx), %rbx
notl %ecx
addl -0x58(%rbp), %ecx
movslq %ecx, %rdx
xorl %esi, %esi
movq %rax, %r14
callq 0x8200
movq %r14, -0x40(%rbp)
movq %r14, %rdi
movl $0x1, %esi
movq %rbx, %rdx
callq 0x8200
movq %r13, -0x70(%rbp)
movzwl 0x3(%r15,%r13), %eax
rolw $0x8, %ax
testw %ax, %ax
je 0x3532b
movzwl %ax, %eax
movq -0x48(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
shll $0x2, %ecx
movq -0x70(%rbp), %rdx
subq %rcx, %rdx
movq -0x58(%rbp), %rcx
addl $-0x4, %ecx
movl %ecx, -0x60(%rbp)
movl %eax, %eax
movq %rax, -0x80(%rbp)
leaq (%rdx,%r15), %rbx
addq $0xc, %rbx
xorl %r13d, %r13d
movzwl (%rbx,%r13,2), %eax
rolw $0x8, %ax
movzwl %ax, %r14d
cmpl -0x60(%rbp), %r14d
jle 0x352d3
leal 0x10000(%r14), %ecx
cmpl -0x58(%rbp), %ecx
jg 0x352ed
jmp 0x3530f
movl %r14d, %esi
addq %r15, %rsi
movq -0x48(%rbp), %rdi
callq 0x30fe4
movzwl %ax, %ecx
addl %r14d, %ecx
cmpl -0x58(%rbp), %ecx
jle 0x3530a
movq -0x38(%rbp), %rdi
xorl %esi, %esi
leaq 0x450e3(%rip), %rdx     # 0x7a3dd
movl %r13d, %ecx
movl -0x2c(%rbp), %r8d
xorl %eax, %eax
callq 0x3542e
jmp 0x35322
testw %ax, %ax
je 0x35322
leal -0x1(%rcx), %eax
addq -0x40(%rbp), %rax
incb (%rax)
decl %ecx
decq %rax
cmpl %r14d, %ecx
jg 0x35316
incq %r13
cmpq -0x80(%rbp), %r13
jne 0x352b2
movq -0x70(%rbp), %rax
movzwl 0x1(%r15,%rax), %eax
rolw $0x8, %ax
testw %ax, %ax
movq -0x38(%rbp), %r14
movq -0x58(%rbp), %r8
movq -0x40(%rbp), %rdi
je 0x3538b
movzwl %ax, %eax
movl %eax, %eax
movzbl 0x2(%r15,%rax), %edx
shll $0x8, %edx
movzbl 0x3(%r15,%rax), %esi
movl %edx, %ecx
orl %esi, %ecx
je 0x3537a
addl %eax, %ecx
addl %eax, %edx
addl %esi, %edx
decl %edx
addq %rdi, %rdx
incb (%rdx)
decl %ecx
decq %rdx
cmpl %eax, %ecx
jg 0x3536f
movzwl (%r15,%rax), %eax
rolw $0x8, %ax
movzwl %ax, %eax
testw %ax, %ax
jne 0x3534d
testl %r8d, %r8d
jle 0x353b9
xorl %ecx, %ecx
xorl %r13d, %r13d
movb (%rdi,%rcx), %al
testb %al, %al
je 0x353a2
cmpb $0x2, %al
jl 0x353a5
jmp 0x353be
incl %r13d
incq %rcx
cmpq %rcx, -0x58(%rbp)
jne 0x35395
jmp 0x353d9
movl $0x1, 0x24(%rbx)
jmp 0x3540b
xorl %r13d, %r13d
jmp 0x353d9
leaq 0x45042(%rip), %rdx     # 0x7a407
movq %r14, %rdi
xorl %esi, %esi
movl -0x2c(%rbp), %r8d
xorl %eax, %eax
callq 0x3542e
movq -0x40(%rbp), %rdi
movq -0x70(%rbp), %rax
movzbl 0x7(%r15,%rax), %r8d
cmpl %r8d, %r13d
je 0x35406
leaq 0x4503d(%rip), %rdx     # 0x7a42c
movq %r14, %rdi
xorl %esi, %esi
movl %r13d, %ecx
movl -0x2c(%rbp), %r9d
xorl %eax, %eax
callq 0x3542e
movq -0x40(%rbp), %rdi
callq 0x1cdc9
movq -0x48(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0xddd3
movq -0x68(%rbp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq