// File: /workspace/github_c_makefile_star2_O3/shifengbin[P]bishe/Output/../Persistence/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 */
  u32 iLast = pPage->pBt->usableSize-4; /* Largest possible freeblock offset */
  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<=iLast );

  /* Overwrite deleted information with zeros when the secure_delete
  ** option is enabled */
  if( pPage->pBt->btsFlags & BTS_SECURE_DELETE ){
    memset(&data[iStart], 0, iSize);
  }

  /* 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]))>0 && iFreeBlk<iStart ){
      if( iFreeBlk<iPtr+4 ) return SQLITE_CORRUPT_BKPT;
      iPtr = iFreeBlk;
    }
    if( iFreeBlk>iLast ) return SQLITE_CORRUPT_BKPT;
    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_BKPT;
      iEnd = iFreeBlk + get2byte(&data[iFreeBlk+2]);
      if( iEnd > pPage->pBt->usableSize ) return SQLITE_CORRUPT_BKPT;
      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_BKPT;
        nFrag += iStart - iPtrEnd;
        iSize = iEnd - iPtr;
        iStart = iPtr;
      }
    }
    if( nFrag>data[hdr+7] ) return SQLITE_CORRUPT_BKPT;
    data[hdr+7] -= nFrag;
  }
  if( iStart==get2byte(&data[hdr+5]) ){
    /* 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( iPtr!=hdr+1 ) return SQLITE_CORRUPT_BKPT;
    put2byte(&data[hdr+1], iFreeBlk);
    put2byte(&data[hdr+5], iEnd);
  }else{
    /* Insert the new freeblock into the freelist */
    put2byte(&data[iPtr], iStart);
    put2byte(&data[iStart], iFreeBlk);
    put2byte(&data[iStart+2], iSize);
  }
  pPage->nFree += iOrigSize;
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %r15d
movq %rdi, %r14
movl %edx, %r10d
movq 0x48(%rdi), %rax
movq 0x50(%rdi), %rbx
movl 0x34(%rax), %r13d
testb $0x4, 0x26(%rax)
je 0x398cd
movzwl %r15w, %edi
addq %rbx, %rdi
movq %rdx, -0x30(%rbp)
movzwl %r10w, %edx
xorl %esi, %esi
movq %r14, %r12
movl %r10d, %r14d
callq 0xa220
movl %r14d, %r10d
movq %r12, %r14
movq -0x30(%rbp), %rdx
addl %r15d, %edx
movq %rdx, %r11
movzbl 0x6(%r14), %eax
leaq 0x1(%rax), %rcx
cmpb $0x0, 0x2(%rbx,%rax)
jne 0x398ed
cmpb $0x0, (%rbx,%rcx)
je 0x399da
addl $-0x4, %r13d
movl %ecx, %esi
movzwl %si, %edi
movzwl (%rbx,%rdi), %edx
rolw $0x8, %dx
movzwl %dx, %r9d
testw %r9w, %r9w
je 0x3993a
cmpw %r15w, %dx
jae 0x3993a
addl $0x4, %edi
movl %edx, %esi
cmpl %r9d, %edi
jbe 0x398f3
leaq 0x41bc9(%rip), %rsi     # 0x7b4e8
leaq 0x41867(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xdd95, %edx           # imm = 0xDD95
jmp 0x39b30
cmpl %r9d, %r13d
jae 0x39961
leaq 0x41ba2(%rip), %rsi     # 0x7b4e8
leaq 0x41840(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xdd98, %edx           # imm = 0xDD98
jmp 0x39b30
movl %r10d, %r12d
testw %dx, %dx
sete %r8b
leal 0x3(%r11), %r10d
cmpl %r9d, %r10d
setb %r10b
orb %r8b, %r10b
je 0x399e9
xorl %r8d, %r8d
movl %r12d, %r10d
movl %r12d, %r13d
cmpl %edi, %ecx
jae 0x39a82
movzwl 0x2(%rbx,%rdi), %r9d
rolw $0x8, %r9w
movzwl %r9w, %r9d
leal (%r9,%rdi), %r10d
addl $0x3, %r10d
cmpl %r15d, %r10d
jb 0x39a7f
addl %edi, %r9d
subl %r9d, %r15d
jae 0x39a70
leaq 0x41b29(%rip), %rsi     # 0x7b4e8
leaq 0x417c7(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xddb1, %edx           # imm = 0xDDB1
jmp 0x39b30
xorl %edx, %edx
movl %r15d, %edi
movl %ecx, %esi
movl %r10d, %r13d
jmp 0x39ab7
movq %r11, %r13
movl %r9d, %r8d
subl %r13d, %r8d
jae 0x39a16
leaq 0x41aed(%rip), %rsi     # 0x7b4e8
leaq 0x4178b(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xdda3, %edx           # imm = 0xDDA3
jmp 0x39b30
movzwl 0x2(%rbx,%r9), %edx
rolw $0x8, %dx
movzwl %dx, %r10d
addl %r9d, %r10d
movq 0x48(%r14), %rdx
cmpl 0x34(%rdx), %r10d
jbe 0x39a53
leaq 0x41ab0(%rip), %rsi     # 0x7b4e8
leaq 0x4174e(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xdda5, %edx           # imm = 0xDDA5
jmp 0x39b30
movq %r10, %rdx
movq %r10, %r11
movl %edx, %r13d
subl %r15d, %r13d
movzwl (%rbx,%r9), %edx
rolw $0x8, %dx
movl %r12d, %r10d
jmp 0x39984
addb %r15b, %r8b
movq %r11, %rdi
movl %edi, %r13d
subl %esi, %r13d
movl %esi, %r15d
movl %r12d, %r10d
movb 0x7(%rbx,%rax), %dil
subb %r8b, %dil
jae 0x39aae
leaq 0x41a55(%rip), %rsi     # 0x7b4e8
leaq 0x416f3(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xddb7, %edx           # imm = 0xDDB7
jmp 0x39b30
movb %dil, 0x7(%rbx,%rax)
movzwl %r15w, %edi
movzwl 0x5(%rbx,%rax), %r8d
rolw $0x8, %r8w
movzwl %r8w, %r8d
cmpl %edi, %r8d
jne 0x39ae7
movzwl %si, %esi
cmpl %esi, %ecx
jne 0x39b13
rolw $0x8, %dx
movw %dx, (%rbx,%rcx)
movq %r11, %rcx
movb %ch, 0x5(%rbx,%rax)
movb %cl, 0x6(%rbx,%rax)
jmp 0x39b0a
movzwl %si, %ecx
movzwl %r15w, %eax
rolw $0x8, %r15w
movw %r15w, (%rbx,%rcx)
movb %dh, (%rbx,%rax)
movb %dl, 0x1(%rbx,%rax)
movl %r13d, %ecx
movb %ch, 0x2(%rbx,%rax)
movb %cl, 0x3(%rbx,%rax)
addw %r10w, 0x10(%r14)
xorl %ebx, %ebx
jmp 0x39b37
leaq 0x419ce(%rip), %rsi     # 0x7b4e8
leaq 0x4166c(%rip), %rcx     # 0x7b18d
movl $0xb, %ebx
movl $0xb, %edi
movl $0xddbe, %edx           # imm = 0xDDBE
xorl %eax, %eax
callq 0xa4c0
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq