// File: /workspace/github_c_makefile_star2_O3/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
pushq %rax
movl %edx, %r12d
movq %rdi, %r14
leal (%r12,%rsi), %edx
movq 0x50(%rdi), %rbp
movzbl 0x9(%rdi), %eax
leaq 0x1(%rax), %rcx
movl %ecx, %edi
cmpb $0x0, 0x2(%rbp,%rax)
jne 0x2a2afa
cmpb $0x0, (%rbp,%rcx)
je 0x2a2c04
movl %edi, %r8d
movzwl %di, %r9d
movzwl (%rbp,%r9), %edi
rolw $0x8, %di
movzwl %di, %r11d
cmpw %si, %r11w
jae 0x2a2b4c
leal 0x4(%r9), %r10d
cmpl %r11d, %r10d
jbe 0x2a2afa
testw %di, %di
je 0x2a2b4c
leaq 0x1330a1(%rip), %rsi    # 0x3d5bcb
leaq 0x1331ab(%rip), %rdx    # 0x3d5cdc
leaq 0x132ef9(%rip), %r8     # 0x3d5a31
movl $0xb, %ebx
movl $0xb, %edi
movl $0x102ac, %ecx          # imm = 0x102AC
jmp 0x2a2db4
movq 0x48(%r14), %r10
movl 0x38(%r10), %r15d
leal -0x4(%r15), %r10d
cmpl %r11d, %r10d
jae 0x2a2b86
leaq 0x133067(%rip), %rsi    # 0x3d5bcb
leaq 0x133171(%rip), %rdx    # 0x3d5cdc
leaq 0x132ebf(%rip), %r8     # 0x3d5a31
movl $0xb, %ebx
movl $0xb, %edi
movl $0x102b1, %ecx          # imm = 0x102B1
jmp 0x2a2db4
testw %di, %di
sete %r10b
leal 0x3(%rdx), %ebx
cmpl %r11d, %ebx
setb %bl
orb %r10b, %bl
je 0x2a2bd3
xorl %r10d, %r10d
movl %r12d, %ebx
cmpl %r9d, %ecx
jae 0x2a2c9f
movl %ebx, %r15d
movzwl 0x2(%rbp,%r9), %r11d
rolw $0x8, %r11w
movzwl %r11w, %r11d
leal (%r11,%r9), %ebx
addl $0x3, %ebx
cmpl %esi, %ebx
jae 0x2a2c50
movl %r15d, %ebx
jmp 0x2a2c9f
movl %r11d, %r10d
subl %edx, %r10d
jae 0x2a2c12
leaq 0x132fe9(%rip), %rsi    # 0x3d5bcb
leaq 0x1330f3(%rip), %rdx    # 0x3d5cdc
leaq 0x132e41(%rip), %r8     # 0x3d5a31
movl $0xb, %ebx
movl $0xb, %edi
movl $0x102bd, %ecx          # imm = 0x102BD
jmp 0x2a2db4
xorl %r15d, %r15d
movl %esi, %r9d
movl %r12d, %ebx
jmp 0x2a2ce1
movzwl 0x2(%rbp,%r11), %edx
rolw $0x8, %dx
movzwl %dx, %edx
addl %r11d, %edx
cmpl %r15d, %edx
jbe 0x2a2c81
leaq 0x132f9d(%rip), %rsi    # 0x3d5bcb
leaq 0x1330a7(%rip), %rdx    # 0x3d5cdc
leaq 0x132df5(%rip), %r8     # 0x3d5a31
movl $0xb, %ebx
movl $0xb, %edi
movl $0x102c0, %ecx          # imm = 0x102C0
jmp 0x2a2db4
addl %r9d, %r11d
subl %r11d, %esi
jae 0x2a2c94
leaq 0x132f6c(%rip), %rsi    # 0x3d5bcb
leaq 0x133076(%rip), %rdx    # 0x3d5cdc
leaq 0x132dc4(%rip), %r8     # 0x3d5a31
movl $0xb, %ebx
movl $0xb, %edi
movl $0x102cd, %ecx          # imm = 0x102CD
jmp 0x2a2db4
movl %edx, %ebx
subl %esi, %ebx
movzwl (%rbp,%r11), %edi
rolw $0x8, %di
jmp 0x2a2ba1
addb %sil, %r10b
movl %edx, %ebx
subl %r8d, %ebx
movl %r8d, %esi
movb 0x7(%rbp,%rax), %r9b
subb %r10b, %r9b
jae 0x2a2cd2
leaq 0x132f1b(%rip), %rsi    # 0x3d5bcb
leaq 0x133025(%rip), %rdx    # 0x3d5cdc
leaq 0x132d73(%rip), %r8     # 0x3d5a31
movl $0xb, %ebx
movl $0xb, %edi
movl $0x102d3, %ecx          # imm = 0x102D3
jmp 0x2a2db4
movb %r9b, 0x7(%rbp,%rax)
movzwl %si, %r9d
movl %edi, %r15d
movl %r8d, %edi
movzwl 0x5(%rbp,%rax), %r8d
rolw $0x8, %r8w
movzwl %r8w, %r8d
cmpl %r9d, %r8d
jae 0x2a2d45
movl %ebx, %r8d
movzwl %di, %eax
movl %esi, %ecx
rolw $0x8, %cx
movw %cx, (%rbp,%rax)
movq 0x48(%r14), %rax
testb $0xc, 0x28(%rax)
movzwl %si, %ebx
movl %r8d, %ecx
je 0x2a2d2a
leaq (%rbx,%rbp), %rdi
movzwl %cx, %edx
xorl %esi, %esi
movl %ecx, %r13d
callq 0x173a0
movl %r13d, %ecx
movl %r15d, %eax
movb %ah, (%rbp,%rbx)
movb %al, 0x1(%rbp,%rbx)
movb %ch, 0x2(%rbp,%rbx)
movb %cl, 0x3(%rbp,%rbx)
addl %r12d, 0x14(%r14)
xorl %ebx, %ebx
jmp 0x2a2dbb
jbe 0x2a2d6d
leaq 0x132e7d(%rip), %rsi    # 0x3d5bcb
leaq 0x132f87(%rip), %rdx    # 0x3d5cdc
leaq 0x132cd5(%rip), %r8     # 0x3d5a31
movl $0xb, %ebx
movl $0xb, %edi
movl $0x102db, %ecx          # imm = 0x102DB
jmp 0x2a2db4
movzwl %di, %edi
cmpl %edi, %ecx
jne 0x2a2d90
movl %ebx, %r8d
movl %r15d, %edi
rolw $0x8, %di
movw %di, (%rbp,%rcx)
movb %dh, 0x5(%rbp,%rax)
movb %dl, 0x6(%rbp,%rax)
jmp 0x2a2d06
leaq 0x132e34(%rip), %rsi    # 0x3d5bcb
leaq 0x132f3e(%rip), %rdx    # 0x3d5cdc
leaq 0x132c8c(%rip), %r8     # 0x3d5a31
movl $0xb, %ebx
movl $0xb, %edi
movl $0x102dc, %ecx          # imm = 0x102DC
xorl %eax, %eax
callq 0x274d08
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq