// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movq 0x48(%rdi), %r14
movq 0x50(%rdi), %r12
movzbl 0x9(%rdi), %r13d
movzbl (%r12,%r13), %esi
callq 0x41ede6
testl %eax, %eax
je 0x41eb40
leaq 0x131d89(%rip), %rsi    # 0x5508a7
leaq 0x131ea5(%rip), %rdx    # 0x5509ca
leaq 0x131bb2(%rip), %r8     # 0x5506de
movl $0xb, %ebp
movl $0xb, %edi
movl $0xfc03, %ecx           # imm = 0xFC03
jmp 0x41edbd
movl 0x30(%r14), %ecx
leal -0x1(%rcx), %eax
movw %ax, 0x18(%rbx)
movb $0x0, 0xc(%rbx)
movslq 0x34(%r14), %r15
movzbl 0xa(%rbx), %edx
leal (%r13,%rdx), %esi
leal 0x8(%r13,%rdx), %eax
movw %ax, 0x12(%rbx)
leaq (%r12,%r15), %rdi
movq %rdi, 0x58(%rbx)
addq %r12, %rsi
addq $0x8, %rsi
movq %rsi, 0x60(%rbx)
addq %r12, %rdx
movq %rdx, 0x68(%rbx)
movzbl 0x5(%r12,%r13), %r8d
movzwl 0x3(%r12,%r13), %edx
rolw $0x8, %dx
movzbl 0x6(%r12,%r13), %r9d
movzwl %dx, %edx
movw %dx, 0x16(%rbx)
addl $-0x8, %ecx
movl $0xaaaaaaab, %esi       # imm = 0xAAAAAAAB
imulq %rcx, %rsi
shrq $0x22, %rsi
cmpl %edx, %esi
jae 0x41ebd9
leaq 0x131cf0(%rip), %rsi    # 0x5508a7
leaq 0x131e0c(%rip), %rdx    # 0x5509ca
leaq 0x131b19(%rip), %r8     # 0x5506de
movl $0xb, %ebp
movl $0xb, %edi
movl $0xfc16, %ecx           # imm = 0xFC16
jmp 0x41edbd
leal (%rax,%rdx,2), %ecx
movl %ecx, 0x4(%rsp)
leal -0x4(%r15), %edi
movq 0x8(%r14), %rcx
testb $0x20, 0x32(%rcx)
je 0x41ece0
movq %r9, 0x10(%rsp)
movq %r8, 0x18(%rsp)
movq %r15, 0x8(%rsp)
leal -0x5(%r15), %ecx
cmpb $0x0, 0x8(%rbx)
cmovel %ecx, %edi
cmpw $0x0, 0x16(%rbx)
setne %r14b
je 0x41ec6f
movl %eax, %eax
addq %r12, %rax
incq %rax
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
movl %edi, (%rsp)
movq 0x20(%rsp), %rax
movzwl -0x1(%rax,%r15,2), %eax
rolw $0x8, %ax
movzwl %ax, %ebp
cmpl 0x4(%rsp), %ebp
jb 0x41ec78
cmpl %edi, %ebp
jg 0x41ec78
movl %ebp, %esi
addq %r12, %rsi
movq %rbx, %rdi
callq *0x78(%rbx)
movzwl %ax, %eax
addl %ebp, %eax
cmpl 0x8(%rsp), %eax
jg 0x41ec99
incq %r15
movzwl 0x16(%rbx), %eax
cmpq %rax, %r15
setb %r14b
movl (%rsp), %edi
jb 0x41ec2a
cmpb $0x1, 0x8(%rbx)
adcl $0x0, %edi
jmp 0x41ecc2
leaq 0x131c28(%rip), %rsi    # 0x5508a7
leaq 0x131d44(%rip), %rdx    # 0x5509ca
leaq 0x131a51(%rip), %r8     # 0x5506de
movl $0xb, %edi
movl $0xfc32, %ecx           # imm = 0xFC32
jmp 0x41ecb8
leaq 0x131c07(%rip), %rsi    # 0x5508a7
leaq 0x131d23(%rip), %rdx    # 0x5509ca
leaq 0x131a30(%rip), %r8     # 0x5506de
movl $0xb, %edi
movl $0xfc37, %ecx           # imm = 0xFC37
xorl %eax, %eax
callq 0x40743a
movl (%rsp), %edi
movl $0xb, %ebp
testb $0x1, %r14b
movq 0x8(%rsp), %r15
movq 0x18(%rsp), %r8
movq 0x10(%rsp), %r9
jne 0x41edc4
shll $0x8, %r8d
leal (%r8,%r9), %eax
decl %eax
movzwl %ax, %ecx
movzwl 0x1(%r12,%r13), %eax
rolw $0x8, %ax
incl %ecx
movzbl 0x7(%r12,%r13), %r13d
addl %ecx, %r13d
testw %ax, %ax
je 0x41ed94
movzwl %ax, %edx
movl $0xfc49, %ecx           # imm = 0xFC49
cmpl 0x4(%rsp), %edx
jb 0x41ed66
cmpl %edi, %edx
jg 0x41ed61
movl %edx, %eax
movl %edx, %ecx
movzwl (%r12,%rcx), %edx
rolw $0x8, %dx
movzwl 0x2(%r12,%rcx), %ecx
movzwl %dx, %edx
rolw $0x8, %cx
movzwl %cx, %esi
addl %esi, %r13d
leal (%rsi,%rax), %ecx
addl $0x3, %ecx
cmpl %ecx, %edx
ja 0x41ed19
movl $0xfc58, %ecx           # imm = 0xFC58
testl %edx, %edx
jne 0x41ed66
addl %eax, %esi
movb $0x1, %r14b
movl $0xfc5c, %ecx           # imm = 0xFC5C
cmpl %r15d, %esi
ja 0x41ed66
jmp 0x41ed8a
movl $0xfc4e, %ecx           # imm = 0xFC4E
leaq 0x131b3a(%rip), %rsi    # 0x5508a7
leaq 0x131c56(%rip), %rdx    # 0x5509ca
leaq 0x131963(%rip), %r8     # 0x5506de
xorl %r14d, %r14d
movl $0xb, %edi
xorl %eax, %eax
callq 0x40743a
movl $0xb, %ebp
testb %r14b, %r14b
je 0x41edc4
cmpl %r15d, %r13d
jle 0x41edd5
leaq 0x131b07(%rip), %rsi    # 0x5508a7
leaq 0x131c23(%rip), %rdx    # 0x5509ca
leaq 0x131930(%rip), %r8     # 0x5506de
movl $0xb, %ebp
movl $0xb, %edi
movl $0xfc68, %ecx           # imm = 0xFC68
xorl %eax, %eax
callq 0x40743a
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subl 0x4(%rsp), %r13d
movw %r13w, 0x14(%rbx)
movb $0x1, (%rbx)
xorl %ebp, %ebp
jmp 0x41edc4