// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movw %dx, %ax
movw %si, %cx
movq %rdi, -0x10(%rbp)
movw %cx, -0x12(%rbp)
movw %ax, -0x14(%rbp)
movb $0x0, -0x1a(%rbp)
movw -0x14(%rbp), %ax
movw %ax, -0x1c(%rbp)
movzwl -0x12(%rbp), %eax
movzwl -0x14(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movb 0x9(%rax), %al
movb %al, -0x19(%rbp)
movzbl -0x19(%rbp), %eax
addl $0x1, %eax
movw %ax, -0x16(%rbp)
movq -0x30(%rbp), %rax
movzwl -0x16(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x4046d7
movq -0x30(%rbp), %rax
movzwl -0x16(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x4046d7
movw $0x0, -0x18(%rbp)
jmp 0x40490d
jmp 0x4046d9
movq -0x30(%rbp), %rax
movzwl -0x16(%rbp), %ecx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movzwl -0x16(%rbp), %edx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movw %ax, -0x18(%rbp)
movzwl %ax, %eax
movzwl -0x12(%rbp), %ecx
cmpl %ecx, %eax
jge 0x40473c
movzwl -0x18(%rbp), %eax
movzwl -0x16(%rbp), %ecx
addl $0x4, %ecx
cmpl %ecx, %eax
jge 0x404732
movzwl -0x18(%rbp), %eax
cmpl $0x0, %eax
jne 0x404720
jmp 0x40473c
movl $0x102ac, %edi          # imm = 0x102AC
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x404aad
movw -0x18(%rbp), %ax
movw %ax, -0x16(%rbp)
jmp 0x4046d9
movzwl -0x18(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl 0x38(%rcx), %ecx
subl $0x4, %ecx
cmpl %ecx, %eax
jbe 0x404764
movl $0x102b1, %edi          # imm = 0x102B1
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x404aad
movzwl -0x18(%rbp), %eax
cmpl $0x0, %eax
je 0x40482e
movl -0x24(%rbp), %eax
addl $0x3, %eax
movzwl -0x18(%rbp), %ecx
cmpl %ecx, %eax
jb 0x40482e
movzwl -0x18(%rbp), %eax
subl -0x24(%rbp), %eax
movb %al, -0x1a(%rbp)
movl -0x24(%rbp), %eax
movzwl -0x18(%rbp), %ecx
cmpl %ecx, %eax
jbe 0x4047aa
movl $0x102bd, %edi          # imm = 0x102BD
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x404aad
movzwl -0x18(%rbp), %eax
movq -0x30(%rbp), %rcx
movzwl -0x18(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
shll $0x8, %ecx
movq -0x30(%rbp), %rdx
movzwl -0x18(%rbp), %esi
addl $0x2, %esi
movslq %esi, %rsi
movzbl 0x1(%rdx,%rsi), %edx
orl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpl 0x38(%rcx), %eax
jbe 0x4047ff
movl $0x102c0, %edi          # imm = 0x102C0
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x404aad
movl -0x24(%rbp), %eax
movzwl -0x12(%rbp), %ecx
subl %ecx, %eax
movw %ax, -0x14(%rbp)
movq -0x30(%rbp), %rax
movzwl -0x18(%rbp), %ecx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movzwl -0x18(%rbp), %edx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movw %ax, -0x18(%rbp)
movzwl -0x16(%rbp), %eax
movzbl -0x19(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x4048c6
movzwl -0x16(%rbp), %eax
movq -0x30(%rbp), %rcx
movzwl -0x16(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
shll $0x8, %ecx
movq -0x30(%rbp), %rdx
movzwl -0x16(%rbp), %esi
addl $0x2, %esi
movslq %esi, %rsi
movzbl 0x1(%rdx,%rsi), %edx
orl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
addl $0x3, %eax
movzwl -0x12(%rbp), %ecx
cmpl %ecx, %eax
jl 0x4048c4
movl -0x34(%rbp), %eax
movzwl -0x12(%rbp), %ecx
cmpl %ecx, %eax
jle 0x40489f
movl $0x102cd, %edi          # imm = 0x102CD
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x404aad
movzwl -0x12(%rbp), %ecx
subl -0x34(%rbp), %ecx
movzbl -0x1a(%rbp), %eax
addl %ecx, %eax
movb %al, -0x1a(%rbp)
movl -0x24(%rbp), %eax
movzwl -0x16(%rbp), %ecx
subl %ecx, %eax
movw %ax, -0x14(%rbp)
movw -0x16(%rbp), %ax
movw %ax, -0x12(%rbp)
jmp 0x4048c6
movzbl -0x1a(%rbp), %eax
movq -0x30(%rbp), %rcx
movzbl -0x19(%rbp), %edx
addl $0x7, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jle 0x4048f2
movl $0x102d3, %edi          # imm = 0x102D3
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x404aad
movzbl -0x1a(%rbp), %esi
movq -0x30(%rbp), %rax
movzbl -0x19(%rbp), %ecx
addl $0x7, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
subl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
movzbl -0x19(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movzbl -0x19(%rbp), %edx
addl $0x5, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movw %ax, -0x1e(%rbp)
movzwl -0x12(%rbp), %eax
movzwl -0x1e(%rbp), %ecx
cmpl %ecx, %eax
jg 0x4049ee
movzwl -0x12(%rbp), %eax
movzwl -0x1e(%rbp), %ecx
cmpl %ecx, %eax
jge 0x404969
movl $0x102db, %edi          # imm = 0x102DB
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x404aad
movzwl -0x16(%rbp), %eax
movzbl -0x19(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x40498a
movl $0x102dc, %edi          # imm = 0x102DC
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x404aad
movzwl -0x18(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movzbl -0x19(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movw -0x18(%rbp), %ax
movb %al, %dl
movq -0x30(%rbp), %rax
movzbl -0x19(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
movl -0x24(%rbp), %eax
shrl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movzbl -0x19(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x24(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movzbl -0x19(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
jmp 0x404a14
movzwl -0x12(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movzwl -0x16(%rbp), %ecx
movb %dl, (%rax,%rcx)
movw -0x12(%rbp), %ax
movb %al, %dl
movq -0x30(%rbp), %rax
movzwl -0x16(%rbp), %ecx
movb %dl, 0x1(%rax,%rcx)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movzwl 0x28(%rax), %eax
andl $0xc, %eax
cmpl $0x0, %eax
je 0x404a40
movq -0x30(%rbp), %rdi
movzwl -0x12(%rbp), %eax
addq %rax, %rdi
movzwl -0x14(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x19360
movzwl -0x18(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movzwl -0x12(%rbp), %ecx
movb %dl, (%rax,%rcx)
movw -0x18(%rbp), %ax
movb %al, %dl
movq -0x30(%rbp), %rax
movzwl -0x12(%rbp), %ecx
movb %dl, 0x1(%rax,%rcx)
movzwl -0x14(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movzwl -0x12(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movw -0x14(%rbp), %ax
movb %al, %dl
movq -0x30(%rbp), %rax
movzwl -0x12(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
movzwl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
addl 0x14(%rax), %ecx
movl %ecx, 0x14(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)