// File: /workspace/github_c_makefile_star2_O1/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
subq $0x28, %rsp
movl %esi, %r11d
movl %edx, %r8d
movl %r11d, %r12d
movq 0x48(%rdi), %rax
movq 0x50(%rdi), %rsi
movl 0x34(%rax), %r14d
testb $0x4, 0x26(%rax)
je 0x3a782
movq %rdi, -0x48(%rbp)
movzwl %r12w, %edi
addq %rsi, %rdi
movq %rdx, -0x40(%rbp)
movzwl %r8w, %edx
movq %rsi, %r13
xorl %esi, %esi
movl %r8d, %r15d
movl %r11d, %ebx
callq 0xa210
movl %ebx, %r11d
movq -0x40(%rbp), %rdx
movq %r13, %rsi
movl %r15d, %r8d
movq -0x48(%rbp), %rdi
addl %r11d, %edx
movzbl 0x6(%rdi), %ecx
leaq 0x1(%rcx), %r10
cmpb $0x0, 0x2(%rsi,%rcx)
jne 0x3a79f
cmpb $0x0, (%rsi,%r10)
je 0x3a8d5
movq %rcx, %r13
addl $-0x4, %r14d
movl %r10d, %r15d
movzwl %r15w, %eax
movzwl (%rsi,%rax), %ebx
rolw $0x8, %bx
movzwl %bx, %ecx
testw %cx, %cx
je 0x3a7ed
cmpw %r12w, %bx
jae 0x3a7ed
addl $0x4, %eax
movl %ebx, %r15d
cmpl %ecx, %eax
jbe 0x3a7a9
leaq 0x42d04(%rip), %rsi     # 0x7d4d8
leaq 0x429a2(%rip), %rcx     # 0x7d17d
movl $0xb, %r13d
movl $0xb, %edi
movl $0xdd95, %edx           # imm = 0xDD95
jmp 0x3a810
cmpl %ecx, %r14d
jae 0x3a829
leaq 0x42cdf(%rip), %rsi     # 0x7d4d8
leaq 0x4297d(%rip), %rcx     # 0x7d17d
movl $0xb, %r13d
movl $0xb, %edi
movl $0xdd98, %edx           # imm = 0xDD98
xorl %eax, %eax
callq 0xa4b0
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r14
testw %bx, %bx
movq %rdx, %r9
sete %dl
leal 0x3(%r9), %esi
cmpl %ecx, %esi
setb %sil
orb %dl, %sil
je 0x3a8e5
movl $0x0, -0x2c(%rbp)
movl %r8d, %ecx
movl %ecx, -0x30(%rbp)
movq %r14, %rsi
movq %r9, %rdx
cmpl %eax, %r10d
jae 0x3a90f
movq %rdx, -0x40(%rbp)
movzwl 0x2(%rsi,%rax), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
leal (%rcx,%rax), %edx
addl $0x3, %edx
movb $0x1, %r9b
cmpl %r11d, %edx
jb 0x3a8cc
addl %eax, %ecx
subl %ecx, %r11d
jae 0x3a972
leaq 0x42c44(%rip), %rsi     # 0x7d4d8
leaq 0x428e2(%rip), %rcx     # 0x7d17d
movq %rdi, -0x48(%rbp)
movl $0xb, %edi
movl $0xddb1, %edx           # imm = 0xDDB1
xorl %eax, %eax
movw %r8w, -0x32(%rbp)
movq %r10, -0x50(%rbp)
callq 0xa4b0
xorl %r9d, %r9d
movq -0x50(%rbp), %r10
movq %r14, %rsi
movzwl -0x32(%rbp), %r8d
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rdx
jmp 0x3a98a
xorl %ebx, %ebx
movl %r10d, %r15d
movl %r8d, %eax
movl %eax, -0x30(%rbp)
jmp 0x3a9cc
movl %ecx, %ebx
subl %r9d, %ebx
jae 0x3a917
leaq 0x42be5(%rip), %rsi     # 0x7d4d8
leaq 0x42883(%rip), %rcx     # 0x7d17d
movl $0xb, %r13d
movl $0xb, %edi
movl $0xdda3, %edx           # imm = 0xDDA3
jmp 0x3a810
movq %r13, %rcx
jmp 0x3a99c
movq %r14, %rsi
movzwl 0x2(%r14,%rcx), %edx
rolw $0x8, %dx
movzwl %dx, %r9d
addl %ecx, %r9d
movq 0x48(%rdi), %rdx
cmpl 0x34(%rdx), %r9d
jbe 0x3a958
leaq 0x42b9c(%rip), %rsi     # 0x7d4d8
leaq 0x4283a(%rip), %rcx     # 0x7d17d
movl $0xb, %r13d
movl $0xb, %edi
movl $0xdda5, %edx           # imm = 0xDDA5
jmp 0x3a810
movq %r9, %rdx
movl %ebx, -0x2c(%rbp)
subl %r12d, %r9d
movl %r9d, -0x30(%rbp)
movzwl (%rsi,%rcx), %ebx
rolw $0x8, %bx
jmp 0x3a85b
movl -0x2c(%rbp), %eax
addb %r11b, %al
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %rdx
movl %edx, %eax
subl %r15d, %eax
movl %eax, -0x30(%rbp)
movl %r15d, %r12d
movq %r13, %rcx
movl $0xb, %r13d
testb %r9b, %r9b
je 0x3a817
movb 0x7(%rsi,%rcx), %al
subb -0x2c(%rbp), %al
jae 0x3a9c8
leaq 0x42b2c(%rip), %rsi     # 0x7d4d8
leaq 0x427ca(%rip), %rcx     # 0x7d17d
movl $0xb, %r13d
movl $0xb, %edi
movl $0xddb7, %edx           # imm = 0xDDB7
jmp 0x3a810
movb %al, 0x7(%rsi,%rcx)
movzwl %r12w, %eax
movq %rcx, %r9
movzwl 0x5(%rsi,%rcx), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
cmpl %eax, %ecx
jne 0x3aa03
movzwl %r15w, %eax
cmpl %eax, %r10d
jne 0x3aa30
rolw $0x8, %bx
movw %bx, (%rsi,%r10)
movq %r9, %rax
movb %dh, 0x5(%rsi,%rax)
movb %dl, 0x6(%rsi,%r9)
jmp 0x3aa23
movzwl %r15w, %ecx
movl %eax, %edx
rolw $0x8, %dx
movw %dx, (%rsi,%rcx)
movb %bh, (%rsi,%rax)
movb %bl, 0x1(%rsi,%rax)
movl -0x30(%rbp), %ecx
movb %ch, 0x2(%rsi,%rax)
movb %cl, 0x3(%rsi,%rax)
addw %r8w, 0x10(%rdi)
xorl %r13d, %r13d
jmp 0x3a817
leaq 0x42aa1(%rip), %rsi     # 0x7d4d8
leaq 0x4273f(%rip), %rcx     # 0x7d17d
movl $0xb, %r13d
movl $0xb, %edi
movl $0xddbe, %edx           # imm = 0xDDBE
jmp 0x3a810