// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: btreeInitPage
static int btreeInitPage(MemPage *pPage){

  assert( pPage->pBt!=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;
    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 + 12 - 4*pPage->leaf;
    pPage->aDataEnd = &data[usableSize];
    pPage->aCellIdx = &data[cellOffset];
    top = get2byteNotZero(&data[hdr+5]);
    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) );

    /* 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 defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
    {
      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 = get2byte(&data[cellOffset+i*2]);
        testcase( pc==iCellFirst );
        testcase( pc==iCellLast );
        if( pc<iCellFirst || pc>iCellLast ){
          return SQLITE_CORRUPT_BKPT;
        }
        sz = cellSizePtr(pPage, &data[pc]);
        testcase( pc+sz==usableSize );
        if( pc+sz>usableSize ){
          return SQLITE_CORRUPT_BKPT;
        }
      }
      if( !pPage->leaf ) iCellLast++;
    }  
#endif

    /* Compute the total free space on the page */
    pc = get2byte(&data[hdr+1]);
    nFree = data[hdr+7] + top;
    while( pc>0 ){
      u16 next, size;
      if( pc<iCellFirst || pc>iCellLast ){
        /* Start of free block is off 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
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
jne 0x24d44
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movb 0x5(%rax), %al
movb %al, -0x13(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movzbl -0x13(%rbp), %ecx
movzbl (%rax,%rcx), %esi
callq 0x24d80
cmpl $0x0, %eax
je 0x24ac7
movl $0xc74a, %edi           # imm = 0xC74A
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x24d4b
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
subl $0x1, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x12(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x1(%rax)
movq -0x28(%rbp), %rax
movl 0x34(%rax), %eax
movl %eax, -0x2c(%rbp)
movzbl -0x13(%rbp), %eax
addl $0xc, %eax
movq -0x10(%rbp), %rcx
movzbl 0x3(%rcx), %ecx
shll $0x2, %ecx
subl %ecx, %eax
movw %ax, %cx
movw %cx, -0x2e(%rbp)
movq -0x10(%rbp), %rax
movw %cx, 0xc(%rax)
movq -0x20(%rbp), %rcx
movslq -0x2c(%rbp), %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x58(%rax)
movq -0x20(%rbp), %rcx
movzwl -0x2e(%rbp), %eax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x20(%rbp), %rax
movzbl -0x13(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movzbl -0x13(%rbp), %edx
addl $0x5, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
subl $0x1, %eax
andl $0xffff, %eax           # imm = 0xFFFF
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movzbl -0x13(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movzbl -0x13(%rbp), %edx
addl $0x3, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x10(%rax)
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
subl $0x8, %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movl -0x48(%rbp), %eax
cmpl %ecx, %eax
jbe 0x24bdd
movl $0xc756, %edi           # imm = 0xC756
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x24d4b
movzwl -0x2e(%rbp), %eax
movq -0x10(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x2c(%rbp), %eax
subl $0x4, %eax
movl %eax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movzbl -0x13(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movzbl -0x13(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movw %ax, -0x12(%rbp)
movq -0x20(%rbp), %rax
movzbl -0x13(%rbp), %ecx
addl $0x7, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
movzwl -0x12(%rbp), %eax
cmpl $0x0, %eax
jle 0x24d15
movzwl -0x12(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jl 0x24c5e
movzwl -0x12(%rbp), %eax
cmpl -0x40(%rbp), %eax
jle 0x24c70
movl $0xc781, %edi           # imm = 0xC781
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x24d4b
movq -0x20(%rbp), %rax
movzwl -0x12(%rbp), %ecx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movzwl -0x12(%rbp), %edx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movw %ax, -0x42(%rbp)
movq -0x20(%rbp), %rax
movzwl -0x12(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movzwl -0x12(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movw %ax, -0x44(%rbp)
movzwl -0x42(%rbp), %eax
cmpl $0x0, %eax
jle 0x24cde
movzwl -0x42(%rbp), %eax
movzwl -0x12(%rbp), %ecx
movzwl -0x44(%rbp), %edx
addl %edx, %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
jle 0x24ced
movzwl -0x12(%rbp), %eax
movzwl -0x44(%rbp), %ecx
addl %ecx, %eax
cmpl -0x2c(%rbp), %eax
jle 0x24cfc
movl $0xc788, %edi           # imm = 0xC788
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x24d4b
movl -0x34(%rbp), %eax
movzwl -0x44(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x34(%rbp)
movw -0x42(%rbp), %ax
movw %ax, -0x12(%rbp)
jmp 0x24c3f
movl -0x34(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jle 0x24d2c
movl $0xc796, %edi           # imm = 0xC796
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x24d4b
movl -0x34(%rbp), %eax
subl -0x3c(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0xe(%rax)
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)