// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x38(%rax), %eax
movl %eax, -0x24(%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 -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, -0x2c(%rbp)
movzbl -0x15(%rbp), %eax
addl $0x8, %eax
movq -0x10(%rbp), %rcx
movzbl 0xa(%rcx), %ecx
addl %ecx, %eax
movq -0x10(%rbp), %rcx
movzwl 0x18(%rcx), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
movl -0x24(%rbp), %eax
subl $0x4, %eax
movl %eax, -0x34(%rbp)
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 -0x2c(%rbp), %eax
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x403949
movl -0x14(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x40388a
movl $0x10358, %edi          # imm = 0x10358
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x40397f
jmp 0x40388c
movl -0x14(%rbp), %eax
cmpl -0x34(%rbp), %eax
jle 0x4038a6
movl $0x1035d, %edi          # imm = 0x1035D
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x40397f
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, -0x38(%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, -0x3c(%rbp)
movl -0x28(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x38(%rbp), %eax
movl -0x14(%rbp), %ecx
addl -0x3c(%rbp), %ecx
addl $0x3, %ecx
cmpl %ecx, %eax
ja 0x40390d
jmp 0x403918
movl -0x38(%rbp), %eax
movl %eax, -0x14(%rbp)
jmp 0x40388c
cmpl $0x0, -0x38(%rbp)
jbe 0x40392d
movl $0x10367, %edi          # imm = 0x10367
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x40397f
movl -0x14(%rbp), %eax
addl -0x3c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jbe 0x403947
movl $0x1036b, %edi          # imm = 0x1036B
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x40397f
jmp 0x403949
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jg 0x403959
movl -0x28(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x403968
movl $0x10377, %edi          # imm = 0x10377
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x40397f
movl -0x28(%rbp), %eax
subl -0x30(%rbp), %eax
movzwl %ax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)