// File: /workspace/github_c_makefile_star2_O0/ukontainer[P]sqlite-bench/sqlite3.c
// Function: btreeInitPage
static int btreeInitPage(MemPage *pPage){
  int 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 */

  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) );
  assert( pPage->isInit==0 );

  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_PAGE(pPage);
  }
  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_PAGE(pPage);
  }
  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_PAGE(pPage);
      }
      sz = pPage->xCellSize(pPage, &data[pc]);
      testcase( pc+sz==usableSize );
      if( pc+sz>usableSize ){
        return SQLITE_CORRUPT_PAGE(pPage);
      }
    }
    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 */
  if( pc>0 ){
    u32 next, size;
    if( pc<iCellFirst ){
      /* EVIDENCE-OF: R-55530-52930 In a well-formed b-tree page, there will
      ** always be at least one cell before the first freeblock.
      */
      return SQLITE_CORRUPT_PAGE(pPage); 
    }
    while( 1 ){
      if( pc>iCellLast ){
        /* Freeblock off the end of the page */
        return SQLITE_CORRUPT_PAGE(pPage);
      }
      next = get2byte(&data[pc]);
      size = get2byte(&data[pc+2]);
      nFree = nFree + size;
      if( next<=pc+size+3 ) break;
      pc = next;
    }
    if( next>0 ){
      /* Freeblock not in ascending order */
      return SQLITE_CORRUPT_PAGE(pPage);
    }
    if( pc+size>(unsigned int)usableSize ){
      /* Last freeblock extends past page end */
      return SQLITE_CORRUPT_PAGE(pPage);
    }
  }

  /* 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_PAGE(pPage);
  }
  pPage->nFree = (u16)(nFree - iCellFirst);
  pPage->isInit = 1;
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movb 0x9(%rax), %al
movb %al, -0x15(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movzbl -0x15(%rbp), %ecx
movzbl (%rax,%rcx), %esi
callq 0x429520
cmpl $0x0, %eax
je 0x42916a
movl $0xfc03, %edi           # imm = 0xFC03
callq 0x424f40
movl %eax, -0x4(%rbp)
jmp 0x42950c
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
subl $0x1, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x18(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0xc(%rax)
movq -0x28(%rbp), %rax
movl 0x34(%rax), %eax
movl %eax, -0x2c(%rbp)
movzbl -0x15(%rbp), %eax
addl $0x8, %eax
movq -0x10(%rbp), %rcx
movzbl 0xa(%rcx), %ecx
addl %ecx, %eax
movw %ax, %cx
movw %cx, -0x2e(%rbp)
movq -0x10(%rbp), %rax
movw %cx, 0x12(%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), %rcx
movq -0x10(%rbp), %rax
movzbl 0xa(%rax), %eax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x20(%rbp), %rax
movzbl -0x15(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movzbl -0x15(%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 -0x15(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movzbl -0x15(%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, 0x16(%rax)
movq -0x10(%rbp), %rax
movzwl 0x16(%rax), %eax
movl %eax, -0x54(%rbp)
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
subl $0x8, %eax
movl $0x6, %ecx
xorl %edx, %edx
divl %ecx
movl %eax, %ecx
movl -0x54(%rbp), %eax
cmpl %ecx, %eax
jbe 0x429294
movl $0xfc16, %edi           # imm = 0xFC16
callq 0x424f40
movl %eax, -0x4(%rbp)
jmp 0x42950c
movzwl -0x2e(%rbp), %eax
movq -0x10(%rbp), %rcx
movzwl 0x16(%rcx), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x2c(%rbp), %eax
subl $0x4, %eax
movl %eax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %eax
andl $0x200000, %eax         # imm = 0x200000
cmpl $0x0, %eax
je 0x4293ae
movq -0x10(%rbp), %rax
cmpb $0x0, 0x8(%rax)
jne 0x4292dc
movl -0x40(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
movzwl 0x16(%rcx), %ecx
cmpl %ecx, %eax
jge 0x429399
movq -0x20(%rbp), %rax
movzwl -0x2e(%rbp), %ecx
movl -0x44(%rbp), %edx
shll %edx
addl %edx, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movzwl -0x2e(%rbp), %edx
movl -0x44(%rbp), %esi
shll %esi
addl %esi, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jl 0x42933b
movl -0x14(%rbp), %eax
cmpl -0x40(%rbp), %eax
jle 0x42934d
movl $0xfc32, %edi           # imm = 0xFC32
callq 0x424f40
movl %eax, -0x4(%rbp)
jmp 0x42950c
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movslq -0x14(%rbp), %rcx
addq %rcx, %rsi
callq *%rax
movzwl %ax, %eax
movl %eax, -0x48(%rbp)
movl -0x14(%rbp), %eax
addl -0x48(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jle 0x429389
movl $0xfc37, %edi           # imm = 0xFC37
callq 0x424f40
movl %eax, -0x4(%rbp)
jmp 0x42950c
jmp 0x42938b
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x4292e3
movq -0x10(%rbp), %rax
cmpb $0x0, 0x8(%rax)
jne 0x4293ac
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4293ae
movq -0x20(%rbp), %rax
movzbl -0x15(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movzbl -0x15(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x14(%rbp)
movq -0x20(%rbp), %rax
movzbl -0x15(%rbp), %ecx
addl $0x7, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x4294d6
movl -0x14(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jge 0x429417
movl $0xfc49, %edi           # imm = 0xFC49
callq 0x424f40
movl %eax, -0x4(%rbp)
jmp 0x42950c
jmp 0x429419
movl -0x14(%rbp), %eax
cmpl -0x40(%rbp), %eax
jle 0x429433
movl $0xfc4e, %edi           # imm = 0xFC4E
callq 0x424f40
movl %eax, -0x4(%rbp)
jmp 0x42950c
movq -0x20(%rbp), %rax
movslq -0x14(%rbp), %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movslq -0x14(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x20(%rbp), %rcx
movl -0x14(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x50(%rbp)
movl -0x34(%rbp), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x4c(%rbp), %eax
movl -0x14(%rbp), %ecx
addl -0x50(%rbp), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
ja 0x42949a
jmp 0x4294a5
movl -0x4c(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x429419
cmpl $0x0, -0x4c(%rbp)
jbe 0x4294ba
movl $0xfc58, %edi           # imm = 0xFC58
callq 0x424f40
movl %eax, -0x4(%rbp)
jmp 0x42950c
movl -0x14(%rbp), %eax
addl -0x50(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jbe 0x4294d4
movl $0xfc5c, %edi           # imm = 0xFC5C
callq 0x424f40
movl %eax, -0x4(%rbp)
jmp 0x42950c
jmp 0x4294d6
movl -0x34(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jle 0x4294ed
movl $0xfc68, %edi           # imm = 0xFC68
callq 0x424f40
movl %eax, -0x4(%rbp)
jmp 0x42950c
movl -0x34(%rbp), %eax
subl -0x3c(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x14(%rax)
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)