// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: btreeComputeFreeSpace
static int btreeComputeFreeSpace(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 */
  int usableSize;    /* Amount of usable space on each page */
  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==1 );
  assert( pPage->nFree<0 );

  usableSize = pPage->pBt->usableSize;
  hdr = pPage->hdrOffset;
  data = pPage->aData;
  /* 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]);
  iCellFirst = hdr + 8 + pPage->childPtrSize + 2*pPage->nCell;
  iCellLast = usableSize - 4;

  /* 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<top ){
      /* 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 || nFree<iCellFirst ){
    return SQLITE_CORRUPT_PAGE(pPage);
  }
  pPage->nFree = (u16)(nFree - iCellFirst);
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x48(%rdi), %rcx
movq 0x50(%rdi), %rax
movl 0x38(%rcx), %r13d
movzbl 0x9(%rdi), %r14d
movzbl 0x5(%rax,%r14), %ecx
shll $0x8, %ecx
movzbl 0x6(%rax,%r14), %edx
addl %edx, %ecx
decl %ecx
movzwl %cx, %edx
movzbl 0xa(%rdi), %r9d
movzwl 0x1(%rax,%r14), %ecx
rolw $0x8, %cx
movzwl 0x18(%rdi), %r15d
movzbl 0x7(%rax,%r14), %esi
leal (%rdx,%rsi), %r12d
incl %r12d
testw %cx, %cx
je 0x2aa437
movzwl %cx, %esi
movl $0x10358, %ecx          # imm = 0x10358
cmpl %edx, %esi
jbe 0x2aa405
leal -0x4(%r13), %ecx
cmpl %ecx, %esi
jg 0x2aa400
movl %esi, %edx
movl %esi, %esi
movzwl (%rax,%rsi), %edi
rolw $0x8, %di
movzwl 0x2(%rax,%rsi), %r8d
movzwl %di, %esi
rolw $0x8, %r8w
movzwl %r8w, %edi
addl %edi, %r12d
leal (%rdi,%rdx), %r8d
addl $0x3, %r8d
cmpl %r8d, %esi
ja 0x2aa3b5
movl $0x10367, %ecx          # imm = 0x10367
testl %esi, %esi
jne 0x2aa405
addl %edx, %edi
movb $0x1, %al
movl $0x1036b, %ecx          # imm = 0x1036B
cmpl %r13d, %edi
ja 0x2aa405
jmp 0x2aa42e
movl $0x1035d, %ecx          # imm = 0x1035D
leaq 0x134f13(%rip), %rsi    # 0x3df31f
leaq 0x13501d(%rip), %rdx    # 0x3df430
leaq 0x134d6b(%rip), %r8     # 0x3df185
movl $0xb, %edi
xorl %eax, %eax
movl %r9d, %ebp
callq 0x27e637
xorl %eax, %eax
movl %ebp, %r9d
movl $0xb, %ebp
testb %al, %al
je 0x2aa481
cmpl %r13d, %r12d
jg 0x2aa456
addl %r9d, %r14d
leal (%r14,%r15,2), %eax
addl $0x8, %eax
subl %eax, %r12d
jl 0x2aa456
movzwl %r12w, %eax
movl %eax, 0x14(%rbx)
xorl %ebp, %ebp
jmp 0x2aa481
leaq 0x134ec2(%rip), %rsi    # 0x3df31f
leaq 0x134fcc(%rip), %rdx    # 0x3df430
leaq 0x134d1a(%rip), %r8     # 0x3df185
movl $0xb, %ebp
movl $0xb, %edi
movl $0x10377, %ecx          # imm = 0x10377
xorl %eax, %eax
callq 0x27e637
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq