// File: /workspace/github_c_makefile_star2_O3/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: btreeInitPage
static int btreeInitPage(MemPage *pPage){

  assert( pPage->pBt!=0 );
  assert( pPage->pBt->db!=0 );
  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  assert( pPage->pgno==sqlite3PagerPagenumber(pPage->pDbPage) );
  assert( pPage == sqlite3PagerGetExtra(pPage->pDbPage) );
  assert( pPage->aData == sqlite3PagerGetData(pPage->pDbPage) );

  if( !pPage->isInit ){
    u16 pc;            /* Address of a freeblock within pPage->aData[] */
    u8 hdr;            /* Offset to beginning of page header */
    u8 *data;          /* Equal to pPage->aData */
    BtShared *pBt;        /* The main btree structure */
    int usableSize;    /* Amount of usable space on each page */
    u16 cellOffset;    /* Offset from start of page to first cell pointer */
    int nFree;         /* Number of unused bytes on the page */
    int top;           /* First byte of the cell content area */
    int iCellFirst;    /* First allowable cell or freeblock offset */
    int iCellLast;     /* Last possible cell or freeblock offset */

    pBt = pPage->pBt;

    hdr = pPage->hdrOffset;
    data = pPage->aData;
    /* EVIDENCE-OF: R-28594-02890 The one-byte flag at offset 0 indicating
    ** the b-tree page type. */
    if( decodeFlags(pPage, data[hdr]) ) return SQLITE_CORRUPT_BKPT;
    assert( pBt->pageSize>=512 && pBt->pageSize<=65536 );
    pPage->maskPage = (u16)(pBt->pageSize - 1);
    pPage->nOverflow = 0;
    usableSize = pBt->usableSize;
    pPage->cellOffset = cellOffset = hdr + 8 + pPage->childPtrSize;
    pPage->aDataEnd = &data[usableSize];
    pPage->aCellIdx = &data[cellOffset];
    pPage->aDataOfst = &data[pPage->childPtrSize];
    /* EVIDENCE-OF: R-58015-48175 The two-byte integer at offset 5 designates
    ** the start of the cell content area. A zero value for this integer is
    ** interpreted as 65536. */
    top = get2byteNotZero(&data[hdr+5]);
    /* EVIDENCE-OF: R-37002-32774 The two-byte integer at offset 3 gives the
    ** number of cells on the page. */
    pPage->nCell = get2byte(&data[hdr+3]);
    if( pPage->nCell>MX_CELL(pBt) ){
      /* To many cells for a single page.  The page must be corrupt */
      return SQLITE_CORRUPT_BKPT;
    }
    testcase( pPage->nCell==MX_CELL(pBt) );
    /* EVIDENCE-OF: R-24089-57979 If a page contains no cells (which is only
    ** possible for a root page of a table that contains no rows) then the
    ** offset to the cell content area will equal the page size minus the
    ** bytes of reserved space. */
    assert( pPage->nCell>0 || top==usableSize || CORRUPT_DB );

    /* A malformed database page might cause us to read past the end
    ** of page when parsing a cell.  
    **
    ** The following block of code checks early to see if a cell extends
    ** past the end of a page boundary and causes SQLITE_CORRUPT to be 
    ** returned if it does.
    */
    iCellFirst = cellOffset + 2*pPage->nCell;
    iCellLast = usableSize - 4;
    if( pBt->db->flags & SQLITE_CellSizeCk ){
      int i;            /* Index into the cell pointer array */
      int sz;           /* Size of a cell */

      if( !pPage->leaf ) iCellLast--;
      for(i=0; i<pPage->nCell; i++){
        pc = get2byteAligned(&data[cellOffset+i*2]);
        testcase( pc==iCellFirst );
        testcase( pc==iCellLast );
        if( pc<iCellFirst || pc>iCellLast ){
          return SQLITE_CORRUPT_BKPT;
        }
        sz = pPage->xCellSize(pPage, &data[pc]);
        testcase( pc+sz==usableSize );
        if( pc+sz>usableSize ){
          return SQLITE_CORRUPT_BKPT;
        }
      }
      if( !pPage->leaf ) iCellLast++;
    }  

    /* Compute the total free space on the page
    ** EVIDENCE-OF: R-23588-34450 The two-byte integer at offset 1 gives the
    ** start of the first freeblock on the page, or is zero if there are no
    ** freeblocks. */
    pc = get2byte(&data[hdr+1]);
    nFree = data[hdr+7] + top;  /* Init nFree to non-freeblock free space */
    while( pc>0 ){
      u16 next, size;
      if( pc<iCellFirst || pc>iCellLast ){
        /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
        ** always be at least one cell before the first freeblock.
        **
        ** Or, the freeblock is off the end of the page
        */
        return SQLITE_CORRUPT_BKPT; 
      }
      next = get2byte(&data[pc]);
      size = get2byte(&data[pc+2]);
      if( (next>0 && next<=pc+size+3) || pc+size>usableSize ){
        /* Free blocks must be in ascending order. And the last byte of
        ** the free-block must lie on the database page.  */
        return SQLITE_CORRUPT_BKPT; 
      }
      nFree = nFree + size;
      pc = next;
    }

    /* At this point, nFree contains the sum of the offset to the start
    ** of the cell-content area plus the number of free bytes within
    ** the cell-content area. If this is greater than the usable-size
    ** of the page, then the page must be corrupted. This check also
    ** serves to verify that the offset to the start of the cell-content
    ** area, according to the page header, lies within the page.
    */
    if( nFree>usableSize ){
      return SQLITE_CORRUPT_BKPT; 
    }
    pPage->nFree = (u16)(nFree - iCellFirst);
    pPage->isInit = 1;
  }
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorl %ebx, %ebx
cmpb $0x0, (%rdi)
jne 0x21d8c
movq %rdi, %r14
movq 0x48(%rdi), %r12
movq 0x50(%rdi), %rax
movzbl 0x6(%rdi), %r15d
movq %rax, %r13
movzbl (%rax,%r15), %esi
callq 0x21f92
testl %eax, %eax
je 0x21cf0
leaq 0x59813(%rip), %rsi     # 0x7b4e8
leaq 0x594b1(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xde2f, %edx           # imm = 0xDE2F
jmp 0x21d85
movl 0x30(%r12), %ecx
leal -0x1(%rcx), %eax
movw %ax, 0x14(%r14)
movb $0x0, 0x1(%r14)
movslq 0x34(%r12), %r9
movzbl 0x7(%r14), %edx
leal (%r15,%rdx), %eax
leal 0x8(%r15,%rdx), %esi
movw %si, 0xe(%r14)
leaq (%r13,%r9), %rsi
movq %rsi, 0x58(%r14)
leaq (%rax,%r13), %rsi
addq $0x8, %rsi
movq %rsi, 0x60(%r14)
addq %r13, %rdx
movq %rdx, 0x68(%r14)
movzbl 0x5(%r13,%r15), %r8d
movzwl 0x3(%r13,%r15), %edx
rolw $0x8, %dx
movzbl 0x6(%r13,%r15), %r10d
movzwl %dx, %esi
movw %si, 0x12(%r14)
addl $-0x8, %ecx
movl $0xaaaaaaab, %edi       # imm = 0xAAAAAAAB
imulq %rcx, %rdi
shrq $0x22, %rdi
cmpl %esi, %edi
jae 0x21d9d
leaq 0x59779(%rip), %rsi     # 0x7b4e8
leaq 0x59417(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xde41, %edx           # imm = 0xDE41
xorl %eax, %eax
callq 0xa4c0
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r10, -0x38(%rbp)
movq %r8, -0x40(%rbp)
addq $0x8, %rax
leal (%rax,%rsi,2), %r10d
leal -0x4(%r9), %r11d
movq 0x8(%r12), %rcx
testb $0x10, 0x2f(%rcx)
je 0x21e54
movb 0x5(%r14), %cl
leal -0x5(%r9), %esi
testb %cl, %cl
cmovel %esi, %r11d
testw %dx, %dx
je 0x21e4d
addq %r13, %rax
incq %rax
movq %rax, -0x58(%rbp)
xorl %r12d, %r12d
movq %r9, -0x50(%rbp)
movq %r15, -0x48(%rbp)
movl %r11d, -0x2c(%rbp)
movq -0x58(%rbp), %rax
movzwl -0x1(%rax,%r12,2), %eax
rolw $0x8, %ax
movzwl %ax, %ebx
cmpl %ebx, %r10d
ja 0x21f4e
cmpl %ebx, %r11d
jl 0x21f4e
movl %r10d, %r15d
leaq (%rbx,%r13), %rsi
movq %r14, %rdi
callq *0x78(%r14)
movq -0x50(%rbp), %r9
movzwl %ax, %eax
addl %ebx, %eax
cmpl %r9d, %eax
jg 0x21f70
incq %r12
movzwl 0x12(%r14), %eax
cmpq %rax, %r12
movl %r15d, %r10d
movq -0x48(%rbp), %r15
movl -0x2c(%rbp), %r11d
jb 0x21dec
movb 0x5(%r14), %cl
xorl %ebx, %ebx
cmpb $0x1, %cl
adcl $0x0, %r11d
movq -0x40(%rbp), %rax
shll $0x8, %eax
movq -0x38(%rbp), %rcx
addl %ecx, %eax
decl %eax
movzwl %ax, %edx
movzwl 0x1(%r13,%r15), %ecx
rolw $0x8, %cx
incl %edx
movzbl 0x7(%r13,%r15), %eax
addl %edx, %eax
testw %cx, %cx
je 0x21ed2
movzwl %cx, %edx
cmpl %edx, %r10d
ja 0x21f2c
cmpl %edx, %r11d
jl 0x21f2c
movl %edx, %esi
movzwl (%r13,%rsi), %ecx
rolw $0x8, %cx
movzwl 0x2(%r13,%rsi), %esi
rolw $0x8, %si
testw %cx, %cx
je 0x21ec4
movzwl %cx, %edi
movzwl %si, %esi
leal (%rdx,%rsi), %r8d
addl $0x3, %r8d
cmpl %edi, %r8d
jb 0x21ec7
jmp 0x21ef9
movzwl %si, %esi
addl %esi, %edx
cmpl %r9d, %edx
jg 0x21ef9
addl %esi, %eax
jmp 0x21e7a
cmpl %r9d, %eax
jle 0x21f1b
leaq 0x5960a(%rip), %rsi     # 0x7b4e8
leaq 0x592a8(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xde8b, %edx           # imm = 0xDE8B
jmp 0x21d85
leaq 0x595e8(%rip), %rsi     # 0x7b4e8
leaq 0x59286(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xde7d, %edx           # imm = 0xDE7D
jmp 0x21d85
subl %r10d, %eax
movw %ax, 0x10(%r14)
movb $0x1, (%r14)
jmp 0x21d8c
leaq 0x595b5(%rip), %rsi     # 0x7b4e8
leaq 0x59253(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xde76, %edx           # imm = 0xDE76
jmp 0x21d85
leaq 0x59593(%rip), %rsi     # 0x7b4e8
leaq 0x59231(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xde5d, %edx           # imm = 0xDE5D
jmp 0x21d85
leaq 0x59571(%rip), %rsi     # 0x7b4e8
leaq 0x5920f(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xde62, %edx           # imm = 0xDE62
jmp 0x21d85