// File: /workspace/github_c_makefile_star2_O0/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
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)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x34(%rax), %eax
subl $0x4, %eax
movl %eax, -0x20(%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
movq 0x48(%rax), %rax
movzwl 0x26(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x4bf7c
movq -0x30(%rbp), %rdi
movzwl -0x12(%rbp), %eax
addq %rax, %rdi
movzwl -0x14(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0xb2b0
movq -0x10(%rbp), %rax
movb 0x6(%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 0x4bfc4
movq -0x30(%rbp), %rax
movzwl -0x16(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x4bfc4
movw $0x0, -0x18(%rbp)
jmp 0x4c1fd
jmp 0x4bfc6
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, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x35(%rbp)
jle 0x4c005
movzwl -0x18(%rbp), %eax
movzwl -0x12(%rbp), %ecx
cmpl %ecx, %eax
setl %al
movb %al, -0x35(%rbp)
movb -0x35(%rbp), %al
testb $0x1, %al
jne 0x4c00e
jmp 0x4c039
movzwl -0x18(%rbp), %eax
movzwl -0x16(%rbp), %ecx
addl $0x4, %ecx
cmpl %ecx, %eax
jge 0x4c02f
movl $0xdd95, %edi           # imm = 0xDD95
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x4c34f
movw -0x18(%rbp), %ax
movw %ax, -0x16(%rbp)
jmp 0x4bfc6
movzwl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
jbe 0x4c054
movl $0xdd98, %edi           # imm = 0xDD98
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x4c34f
movzwl -0x18(%rbp), %eax
cmpl $0x0, %eax
je 0x4c11e
movl -0x24(%rbp), %eax
addl $0x3, %eax
movzwl -0x18(%rbp), %ecx
cmpl %ecx, %eax
jb 0x4c11e
movzwl -0x18(%rbp), %eax
subl -0x24(%rbp), %eax
movb %al, -0x1a(%rbp)
movl -0x24(%rbp), %eax
movzwl -0x18(%rbp), %ecx
cmpl %ecx, %eax
jbe 0x4c09a
movl $0xdda3, %edi           # imm = 0xDDA3
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x4c34f
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 0x34(%rcx), %eax
jbe 0x4c0ef
movl $0xdda5, %edi           # imm = 0xDDA5
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x4c34f
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 0x4c1b6
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 0x4c1b4
movl -0x34(%rbp), %eax
movzwl -0x12(%rbp), %ecx
cmpl %ecx, %eax
jle 0x4c18f
movl $0xddb1, %edi           # imm = 0xDDB1
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x4c34f
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 0x4c1b6
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 0x4c1e2
movl $0xddb7, %edi           # imm = 0xDDB7
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x4c34f
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)
movzwl -0x12(%rbp), %eax
movq -0x30(%rbp), %rcx
movzbl -0x19(%rbp), %edx
addl $0x5, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
shll $0x8, %ecx
movq -0x30(%rbp), %rdx
movzbl -0x19(%rbp), %esi
addl $0x5, %esi
movslq %esi, %rsi
movzbl 0x1(%rdx,%rsi), %edx
orl %edx, %ecx
cmpl %ecx, %eax
jne 0x4c2b8
movzwl -0x16(%rbp), %eax
movzbl -0x19(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x4c254
movl $0xddbe, %edi           # imm = 0xDDBE
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x4c34f
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 0x4c336
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)
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), %edx
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %ecx
addl %edx, %ecx
movw %cx, 0x10(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)