// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: defragmentPage
static int defragmentPage(MemPage *pPage){
  int i;                     /* Loop counter */
  int pc;                    /* Address of a i-th cell */
  int hdr;                   /* Offset to the page header */
  int size;                  /* Size of a cell */
  int usableSize;            /* Number of usable bytes on a page */
  int cellOffset;            /* Offset to the cell pointer array */
  int cbrk;                  /* Offset to the cell content area */
  int nCell;                 /* Number of cells on the page */
  unsigned char *data;       /* The page data */
  unsigned char *temp;       /* Temp area for cell content */
  int iCellFirst;            /* First allowable cell index */
  int iCellLast;             /* Last possible cell index */


  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  assert( pPage->pBt!=0 );
  assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
  assert( pPage->nOverflow==0 );
  assert( sqlite3_mutex_held(pPage->pBt->mutex) );
  temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
  data = pPage->aData;
  hdr = pPage->hdrOffset;
  cellOffset = pPage->cellOffset;
  nCell = pPage->nCell;
  assert( nCell==get2byte(&data[hdr+3]) );
  usableSize = pPage->pBt->usableSize;
  cbrk = get2byte(&data[hdr+5]);
  memcpy(&temp[cbrk], &data[cbrk], usableSize - cbrk);
  cbrk = usableSize;
  iCellFirst = cellOffset + 2*nCell;
  iCellLast = usableSize - 4;
  for(i=0; i<nCell; i++){
    u8 *pAddr;     /* The i-th cell pointer */
    pAddr = &data[cellOffset + i*2];
    pc = get2byte(pAddr);
    testcase( pc==iCellFirst );
    testcase( pc==iCellLast );
#if !defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
    /* These conditions have already been verified in btreeInitPage()
    ** if SQLITE_ENABLE_OVERSIZE_CELL_CHECK is defined 
    */
    if( pc<iCellFirst || pc>iCellLast ){
      return SQLITE_CORRUPT_BKPT;
    }
#endif
    assert( pc>=iCellFirst && pc<=iCellLast );
    size = cellSizePtr(pPage, &temp[pc]);
    cbrk -= size;
#if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
    if( cbrk<iCellFirst ){
      return SQLITE_CORRUPT_BKPT;
    }
#else
    if( cbrk<iCellFirst || pc+size>usableSize ){
      return SQLITE_CORRUPT_BKPT;
    }
#endif
    assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
    testcase( cbrk+size==usableSize );
    testcase( pc+size==usableSize );
    memcpy(&data[cbrk], &temp[pc], size);
    put2byte(pAddr, cbrk);
  }
  assert( cbrk>=iCellFirst );
  put2byte(&data[hdr+5], cbrk);
  data[hdr+1] = 0;
  data[hdr+2] = 0;
  data[hdr+7] = 0;
  memset(&data[iCellFirst], 0, cbrk-iCellFirst);
  assert( sqlite3PagerIswriteable(pPage->pDbPage) );
  if( cbrk-iCellFirst!=pPage->nFree ){
    return SQLITE_CORRUPT_BKPT;
  }
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rdi
callq 0x43430
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x5(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movzwl 0xc(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x34(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
shll $0x8, %eax
movq -0x38(%rbp), %rcx
movl -0x1c(%rbp), %edx
addl $0x5, %edx
movslq %edx, %rdx
movzbl 0x1(%rcx,%rdx), %ecx
orl %ecx, %eax
movl %eax, -0x2c(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x2c(%rbp), %rax
addq %rax, %rdi
movq -0x38(%rbp), %rsi
movslq -0x2c(%rbp), %rax
addq %rax, %rsi
movl -0x24(%rbp), %eax
subl -0x2c(%rbp), %eax
movslq %eax, %rdx
callq 0x82f0
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movl -0x30(%rbp), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x24(%rbp), %eax
subl $0x4, %eax
movl %eax, -0x48(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x4337b
movq -0x38(%rbp), %rax
movl -0x28(%rbp), %ecx
movl -0x14(%rbp), %edx
shll %edx
addl %edx, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movzbl (%rax), %eax
shll $0x8, %eax
movq -0x50(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x44(%rbp), %eax
jl 0x432d8
movl -0x18(%rbp), %eax
cmpl -0x48(%rbp), %eax
jle 0x432ea
movl $0xc620, %edi           # imm = 0xC620
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x4341f
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movslq -0x18(%rbp), %rax
addq %rax, %rsi
callq 0x41c00
movzwl %ax, %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %ecx
movl -0x2c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x44(%rbp), %eax
jl 0x43322
movl -0x18(%rbp), %eax
addl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x43334
movl $0xc62c, %edi           # imm = 0xC62C
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x4341f
movq -0x38(%rbp), %rdi
movslq -0x2c(%rbp), %rax
addq %rax, %rdi
movq -0x40(%rbp), %rsi
movslq -0x18(%rbp), %rax
addq %rax, %rsi
movslq -0x20(%rbp), %rdx
callq 0x82f0
movl -0x2c(%rbp), %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x50(%rbp), %rax
movb %cl, (%rax)
movl -0x2c(%rbp), %eax
movb %al, %cl
movq -0x50(%rbp), %rax
movb %cl, 0x1(%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x4328d
movl -0x2c(%rbp), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x2c(%rbp), %eax
movb %al, %dl
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl $0x7, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rdi
movslq -0x44(%rbp), %rax
addq %rax, %rdi
movl -0x2c(%rbp), %eax
subl -0x44(%rbp), %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x8200
movl -0x2c(%rbp), %eax
subl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
movzwl 0xe(%rcx), %ecx
cmpl %ecx, %eax
je 0x43418
movl $0xc63d, %edi           # imm = 0xC63D
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x4341f
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)