// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: freeSpace
static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
  u16 iPtr;                             /* Address of ptr to next freeblock */
  u16 iFreeBlk;                         /* Address of the next freeblock */
  u8 hdr;                               /* Page header size.  0 or 100 */
  u8 nFrag = 0;                         /* Reduction in fragmentation */
  u16 iOrigSize = iSize;                /* Original value of iSize */
  u16 x;                                /* Offset to cell content area */
  u32 iEnd = iStart + iSize;            /* First byte past the iStart buffer */
  unsigned char *data = pPage->aData;   /* Page content */

  assert( pPage->pBt!=0 );
  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  assert( CORRUPT_DB || iStart>=pPage->hdrOffset+6+pPage->childPtrSize );
  assert( CORRUPT_DB || iEnd <= pPage->pBt->usableSize );
  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  assert( iSize>=4 );   /* Minimum cell size is 4 */
  assert( iStart<=pPage->pBt->usableSize-4 );

  /* The list of freeblocks must be in ascending order.  Find the
  ** spot on the list where iStart should be inserted.
  */
  hdr = pPage->hdrOffset;
  iPtr = hdr + 1;
  if( data[iPtr+1]==0 && data[iPtr]==0 ){
    iFreeBlk = 0;  /* Shortcut for the case when the freelist is empty */
  }else{
    while( (iFreeBlk = get2byte(&data[iPtr]))<iStart ){
      if( iFreeBlk<iPtr+4 ){
        if( iFreeBlk==0 ) break; /* TH3: corrupt082.100 */
        return SQLITE_CORRUPT_PAGE(pPage);
      }
      iPtr = iFreeBlk;
    }
    if( iFreeBlk>pPage->pBt->usableSize-4 ){ /* TH3: corrupt081.100 */
      return SQLITE_CORRUPT_PAGE(pPage);
    }
    assert( iFreeBlk>iPtr || iFreeBlk==0 );

    /* At this point:
    **    iFreeBlk:   First freeblock after iStart, or zero if none
    **    iPtr:       The address of a pointer to iFreeBlk
    **
    ** Check to see if iFreeBlk should be coalesced onto the end of iStart.
    */
    if( iFreeBlk && iEnd+3>=iFreeBlk ){
      nFrag = iFreeBlk - iEnd;
      if( iEnd>iFreeBlk ) return SQLITE_CORRUPT_PAGE(pPage);
      iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
      if( iEnd > pPage->pBt->usableSize ){
        return SQLITE_CORRUPT_PAGE(pPage);
      }
      iSize = iEnd - iStart;
      iFreeBlk = get2byte(&data[iFreeBlk]);
    }

    /* If iPtr is another freeblock (that is, if iPtr is not the freelist
    ** pointer in the page header) then check to see if iStart should be
    ** coalesced onto the end of iPtr.
    */
    if( iPtr>hdr+1 ){
      int iPtrEnd = iPtr + get2byte(&data[iPtr+2]);
      if( iPtrEnd+3>=iStart ){
        if( iPtrEnd>iStart ) return SQLITE_CORRUPT_PAGE(pPage);
        nFrag += iStart - iPtrEnd;
        iSize = iEnd - iPtr;
        iStart = iPtr;
      }
    }
    if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_PAGE(pPage);
    data[hdr+7] -= nFrag;
  }
  x = get2byte(&data[hdr+5]);
  if( iStart<=x ){
    /* The new freeblock is at the beginning of the cell content area,
    ** so just extend the cell content area rather than create another
    ** freelist entry */
    if( iStart<x ) return SQLITE_CORRUPT_PAGE(pPage);
    if( iPtr!=hdr+1 ) return SQLITE_CORRUPT_PAGE(pPage);
    put2byte(&data[hdr+1], iFreeBlk);
    put2byte(&data[hdr+5], iEnd);
  }else{
    /* Insert the new freeblock into the freelist */
    put2byte(&data[iPtr], iStart);
  }
  if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){
    /* Overwrite deleted information with zeros when the secure_delete
    ** option is enabled */
    memset(&data[iStart], 0, iSize);
  }
  put2byte(&data[iStart], iFreeBlk);
  put2byte(&data[iStart+2], iSize);
  pPage->nFree += iOrigSize;
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r9d
movq %rdi, %r14
movl %esi, %r12d
leal (%r9,%rsi), %edx
movq 0x50(%rdi), %rbx
movzbl 0x9(%rdi), %ebp
leaq 0x1(%rbp), %r10
movl %r10d, %r15d
cmpb $0x0, 0x2(%rbx,%rbp)
jne 0x2ac616
cmpb $0x0, (%rbx,%r10)
je 0x2ac790
movq %rdx, %r8
movl %r15d, %r13d
movzwl %r15w, %eax
movzwl (%rbx,%rax), %r15d
rolw $0x8, %r15w
movzwl %r15w, %ecx
cmpw %r12w, %cx
jae 0x2ac667
leal 0x4(%rax), %edx
cmpl %ecx, %edx
jbe 0x2ac619
testw %r15w, %r15w
je 0x2ac667
leaq 0x132cd7(%rip), %rsi    # 0x3df31f
leaq 0x132de1(%rip), %rdx    # 0x3df430
leaq 0x132b2f(%rip), %r8     # 0x3df185
movl $0xb, %ebp
movl $0xb, %edi
movl $0x102ac, %ecx          # imm = 0x102AC
jmp 0x2ac699
movq 0x48(%r14), %rdx
movl 0x38(%rdx), %edx
leal -0x4(%rdx), %edi
cmpl %ecx, %edi
jae 0x2ac6b1
leaq 0x132ca3(%rip), %rsi    # 0x3df31f
leaq 0x132dad(%rip), %rdx    # 0x3df430
leaq 0x132afb(%rip), %r8     # 0x3df185
movl $0xb, %ebp
movl $0xb, %edi
movl $0x102b1, %ecx          # imm = 0x102B1
xorl %eax, %eax
callq 0x27e637
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testw %r15w, %r15w
sete %dil
movq %r8, %r11
addl $0x3, %r8d
cmpl %ecx, %r8d
setb %r8b
orb %dil, %r8b
je 0x2ac75f
movq %rbp, 0x18(%rsp)
xorl %r8d, %r8d
movl %r9d, %ecx
movl %ecx, 0x4(%rsp)
movq %r11, %rdx
cmpl %eax, %r10d
jae 0x2ac81d
movq %rdx, %rbp
movzwl 0x2(%rbx,%rax), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
leal (%rcx,%rax), %edx
addl $0x3, %edx
movb $0x1, %dil
cmpl %esi, %edx
jb 0x2ac757
addl %eax, %ecx
subl %ecx, %esi
jae 0x2ac7fd
leaq 0x132c07(%rip), %rsi    # 0x3df31f
leaq 0x132d11(%rip), %rdx    # 0x3df430
movl %r8d, 0x14(%rsp)
leaq 0x132a5a(%rip), %r8     # 0x3df185
movl $0xb, %edi
movl $0x102cd, %ecx          # imm = 0x102CD
xorl %eax, %eax
movq %r9, 0x8(%rsp)
movq %r10, 0x20(%rsp)
callq 0x27e637
xorl %edi, %edi
movl 0x14(%rsp), %r8d
movq 0x20(%rsp), %r10
movq 0x8(%rsp), %r9
movq %rbp, %rdx
jmp 0x2ac80f
movl %ecx, %r8d
subl %r11d, %r8d
jae 0x2ac7a4
leaq 0x132bb1(%rip), %rsi    # 0x3df31f
leaq 0x132cbb(%rip), %rdx    # 0x3df430
leaq 0x132a09(%rip), %r8     # 0x3df185
movl $0xb, %ebp
movl $0xb, %edi
movl $0x102bd, %ecx          # imm = 0x102BD
jmp 0x2ac699
movl $0x0, 0x8(%rsp)
movl %r9d, %eax
movl %eax, 0x4(%rsp)
jmp 0x2ac862
movzwl 0x2(%rbx,%rcx), %edi
rolw $0x8, %di
movzwl %di, %edi
addl %ecx, %edi
cmpl %edx, %edi
jbe 0x2ac7df
leaq 0x132b62(%rip), %rsi    # 0x3df31f
leaq 0x132c6c(%rip), %rdx    # 0x3df430
leaq 0x1329ba(%rip), %r8     # 0x3df185
movl $0xb, %ebp
movl $0xb, %edi
movl $0x102c0, %ecx          # imm = 0x102C0
jmp 0x2ac699
movq %rdi, %rdx
movq %rbp, 0x18(%rsp)
subl %r12d, %edi
movl %edi, 0x4(%rsp)
movzwl (%rbx,%rcx), %r15d
rolw $0x8, %r15w
jmp 0x2ac6e2
addb %sil, %r8b
movq %rbp, %rdx
movl %ebp, %eax
subl %r13d, %eax
movl %eax, 0x4(%rsp)
movl %r13d, %r12d
movl $0xb, %ebp
testb %dil, %dil
je 0x2ac6a0
movq 0x18(%rsp), %rbp
movb 0x7(%rbx,%rbp), %al
subb %r8b, %al
jae 0x2ac854
leaq 0x132aed(%rip), %rsi    # 0x3df31f
leaq 0x132bf7(%rip), %rdx    # 0x3df430
leaq 0x132945(%rip), %r8     # 0x3df185
movl $0xb, %ebp
movl $0xb, %edi
movl $0x102d3, %ecx          # imm = 0x102D3
jmp 0x2ac699
movb %al, 0x7(%rbx,%rbp)
movl %r15d, %eax
movl %eax, 0x8(%rsp)
movl %r13d, %r15d
movzwl 0x5(%rbx,%rbp), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
movzwl %r12w, %eax
cmpl %eax, %ecx
jae 0x2ac8cc
movzwl %r15w, %ecx
rolw $0x8, %r12w
movw %r12w, (%rbx,%rcx)
movq 0x48(%r14), %rcx
testb $0xc, 0x28(%rcx)
movl %eax, %ebp
movl 0x4(%rsp), %eax
je 0x2ac8ae
leaq (%rbx,%rbp), %rdi
movzwl 0x4(%rsp), %edx
xorl %esi, %esi
movq %r9, %r15
callq 0x173a0
movl 0x4(%rsp), %eax
movq %r15, %r9
movl 0x8(%rsp), %ecx
movb %ch, (%rbx,%rbp)
movb %cl, 0x1(%rbx,%rbp)
movb %ah, 0x2(%rbx,%rbp)
movb %al, 0x3(%rbx,%rbp)
addl %r9d, 0x14(%r14)
xorl %ebp, %ebp
jmp 0x2ac6a0
jbe 0x2ac8f7
leaq 0x132a4a(%rip), %rsi    # 0x3df31f
leaq 0x132b54(%rip), %rdx    # 0x3df430
leaq 0x1328a2(%rip), %r8     # 0x3df185
movl $0xb, %ebp
movl $0xb, %edi
movl $0x102db, %ecx          # imm = 0x102DB
jmp 0x2ac699
movzwl %r15w, %ecx
cmpl %ecx, %r10d
jne 0x2ac91a
movl 0x8(%rsp), %ecx
rolw $0x8, %cx
movw %cx, (%rbx,%r10)
movb %dh, 0x5(%rbx,%rbp)
movb %dl, 0x6(%rbx,%rbp)
jmp 0x2ac884
leaq 0x1329fe(%rip), %rsi    # 0x3df31f
leaq 0x132b08(%rip), %rdx    # 0x3df430
leaq 0x132856(%rip), %r8     # 0x3df185
movl $0xb, %ebp
movl $0xb, %edi
movl $0x102dc, %ecx          # imm = 0x102DC
jmp 0x2ac699