// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: freeSpace
static int freeSpace(MemPage *pPage, int start, int size){
  int addr, pbegin, hdr;
  int iLast;                        /* Largest possible freeblock offset */
  unsigned char *data = pPage->aData;

  assert( pPage->pBt!=0 );
  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  assert( start>=pPage->hdrOffset+6+pPage->childPtrSize );
  assert( (start + size) <= (int)pPage->pBt->usableSize );
  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  assert( size>=0 );   /* Minimum cell size is 4 */

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

  /* Add the space back into the linked list of freeblocks.  Note that
  ** even though the freeblock list was checked by btreeInitPage(),
  ** btreeInitPage() did not detect overlapping cells or
  ** freeblocks that overlapped cells.   Nor does it detect when the
  ** cell content area exceeds the value in the page header.  If these
  ** situations arise, then subsequent insert operations might corrupt
  ** the freelist.  So we do need to check for corruption while scanning
  ** the freelist.
  */
  hdr = pPage->hdrOffset;
  addr = hdr + 1;
  iLast = pPage->pBt->usableSize - 4;
  assert( start<=iLast );
  while( (pbegin = get2byte(&data[addr]))<start && pbegin>0 ){
    if( pbegin<addr+4 ){
      return SQLITE_CORRUPT_BKPT;
    }
    addr = pbegin;
  }
  if( pbegin>iLast ){
    return SQLITE_CORRUPT_BKPT;
  }
  assert( pbegin>addr || pbegin==0 );
  put2byte(&data[addr], start);
  put2byte(&data[start], pbegin);
  put2byte(&data[start+2], size);
  pPage->nFree = pPage->nFree + (u16)size;

  /* Coalesce adjacent free blocks */
  addr = hdr + 1;
  while( (pbegin = get2byte(&data[addr]))>0 ){
    int pnext, psize, x;
    assert( pbegin>addr );
    assert( pbegin <= (int)pPage->pBt->usableSize-4 );
    pnext = get2byte(&data[pbegin]);
    psize = get2byte(&data[pbegin+2]);
    if( pbegin + psize + 3 >= pnext && pnext>0 ){
      int frag = pnext - (pbegin+psize);
      if( (frag<0) || (frag>(int)data[hdr+7]) ){
        return SQLITE_CORRUPT_BKPT;
      }
      data[hdr+7] -= (u8)frag;
      x = get2byte(&data[pnext]);
      put2byte(&data[pbegin], x);
      x = pnext + get2byte(&data[pnext+2]) - pbegin;
      put2byte(&data[pbegin+2], x);
    }else{
      addr = pbegin;
    }
  }

  /* If the cell content area begins with a freeblock, remove it. */
  if( data[hdr+1]==data[hdr+5] && data[hdr+2]==data[hdr+6] ){
    int top;
    pbegin = get2byte(&data[hdr+1]);
    memcpy(&data[hdr+1], &data[pbegin], 2);
    top = get2byte(&data[hdr+5]) + get2byte(&data[pbegin+2]);
    put2byte(&data[hdr+5], top);
  }
  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%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 0x42a88
movq -0x30(%rbp), %rdi
movslq -0x14(%rbp), %rax
addq %rax, %rdi
movslq -0x18(%rbp), %rdx
xorl %esi, %esi
callq 0x8200
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x34(%rax), %eax
subl $0x4, %eax
movl %eax, -0x28(%rbp)
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzbl (%rax,%rcx), %ecx
shll $0x8, %ecx
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rdx
movzbl 0x1(%rax,%rdx), %eax
orl %eax, %ecx
movl %ecx, -0x20(%rbp)
xorl %eax, %eax
cmpl -0x14(%rbp), %ecx
movb %al, -0x45(%rbp)
jge 0x42ae2
cmpl $0x0, -0x20(%rbp)
setg %al
movb %al, -0x45(%rbp)
movb -0x45(%rbp), %al
testb $0x1, %al
jne 0x42aeb
jmp 0x42b12
movl -0x20(%rbp), %eax
movl -0x1c(%rbp), %ecx
addl $0x4, %ecx
cmpl %ecx, %eax
jge 0x42b0a
movl $0xc6d3, %edi           # imm = 0xC6D3
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x42e8b
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x42aad
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jle 0x42b2c
movl $0xc6d8, %edi           # imm = 0xC6D8
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x42e8b
movl -0x14(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x14(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx)
movl -0x20(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x20(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movslq -0x14(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx)
movl -0x18(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x18(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x14(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
movq -0x10(%rbp), %rax
movzwl 0xe(%rax), %eax
movl -0x18(%rbp), %ecx
movzwl %cx, %ecx
addl %ecx, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0xe(%rax)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, %eax
jle 0x42d65
movq -0x30(%rbp), %rax
movslq -0x20(%rbp), %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movslq -0x20(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movl -0x20(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x20(%rbp), %eax
addl -0x38(%rbp), %eax
addl $0x3, %eax
cmpl -0x34(%rbp), %eax
jl 0x42d5a
cmpl $0x0, -0x34(%rbp)
jle 0x42d5a
movl -0x34(%rbp), %eax
movl -0x20(%rbp), %ecx
addl -0x38(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jl 0x42c84
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
movl -0x24(%rbp), %edx
addl $0x7, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jle 0x42c96
movl $0xc6eb, %edi           # imm = 0xC6EB
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x42e8b
movl -0x40(%rbp), %eax
movzbl %al, %esi
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x7, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %edx
subl %esi, %edx
movb %dl, (%rax,%rcx)
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movslq -0x20(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movslq -0x20(%rbp), %rcx
movb %dl, 0x1(%rax,%rcx)
movl -0x34(%rbp), %eax
movq -0x30(%rbp), %rcx
movl -0x34(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
shll $0x8, %ecx
movq -0x30(%rbp), %rdx
movl -0x34(%rbp), %esi
addl $0x2, %esi
movslq %esi, %rsi
movzbl 0x1(%rdx,%rsi), %edx
orl %edx, %ecx
addl %ecx, %eax
subl -0x20(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x3c(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x20(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
jmp 0x42d60
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x42bc6
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movq -0x30(%rbp), %rcx
movl -0x24(%rbp), %edx
addl $0x5, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x42e84
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movq -0x30(%rbp), %rcx
movl -0x24(%rbp), %edx
addl $0x6, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
jne 0x42e84
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movl -0x24(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x20(%rbp)
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq -0x30(%rbp), %rdx
movslq -0x20(%rbp), %rsi
movw (%rdx,%rsi), %dx
movw %dx, (%rax,%rcx)
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x30(%rbp), %rcx
movl -0x24(%rbp), %edx
addl $0x5, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movq -0x30(%rbp), %rcx
movl -0x20(%rbp), %edx
addl $0x2, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
shll $0x8, %ecx
movq -0x30(%rbp), %rdx
movl -0x20(%rbp), %esi
addl $0x2, %esi
movslq %esi, %rsi
movzbl 0x1(%rdx,%rsi), %edx
orl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x44(%rbp), %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)