// File: /workspace/github_c_makefile_star2_O0/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: defragmentPage
static int defragmentPage(MemPage *pPage){
  int i;                     /* Loop counter */
  int pc;                    /* Address of the 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 */
  unsigned char *src;        /* Source of 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 = 0;
  src = data = pPage->aData;
  hdr = pPage->hdrOffset;
  cellOffset = pPage->cellOffset;
  nCell = pPage->nCell;
  assert( nCell==get2byte(&data[hdr+3]) );
  usableSize = pPage->pBt->usableSize;
  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 );
    /* These conditions have already been verified in btreeInitPage()
    ** if PRAGMA cell_size_check=ON.
    */
    if( pc<iCellFirst || pc>iCellLast ){
      return SQLITE_CORRUPT_BKPT;
    }
    assert( pc>=iCellFirst && pc<=iCellLast );
    size = pPage->xCellSize(pPage, &src[pc]);
    cbrk -= size;
    if( cbrk<iCellFirst || pc+size>usableSize ){
      return SQLITE_CORRUPT_BKPT;
    }
    assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
    testcase( cbrk+size==usableSize );
    testcase( pc+size==usableSize );
    put2byte(pAddr, cbrk);
    if( temp==0 ){
      int x;
      if( cbrk==pc ) continue;
      temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
      x = get2byte(&data[hdr+5]);
      memcpy(&temp[x], &data[x], (cbrk+size) - x);
      src = temp;
    }
    memcpy(&data[cbrk], &src[pc], size);
  }
  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 $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x38(%rbp)
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x6(%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movzwl 0xe(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x12(%rax), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x34(%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x28(%rbp), %eax
movl -0x30(%rbp), %ecx
shll %ecx
addl %ecx, %eax
movl %eax, -0x4c(%rbp)
movl -0x24(%rbp), %eax
subl $0x4, %eax
movl %eax, -0x50(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x4c94b
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, -0x58(%rbp)
movq -0x58(%rbp), %rax
movzbl (%rax), %eax
shll $0x8, %eax
movq -0x58(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
orl %ecx, %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jl 0x4c821
movl -0x18(%rbp), %eax
cmpl -0x50(%rbp), %eax
jle 0x4c833
movl $0xdcaa, %edi           # imm = 0xDCAA
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x4c9ef
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
movslq -0x18(%rbp), %rcx
addq %rcx, %rsi
callq *%rax
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 -0x4c(%rbp), %eax
jl 0x4c870
movl -0x18(%rbp), %eax
addl -0x20(%rbp), %eax
cmpl -0x24(%rbp), %eax
jle 0x4c882
movl $0xdcb0, %edi           # imm = 0xDCB0
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x4c9ef
movl -0x2c(%rbp), %eax
sarl $0x8, %eax
movb %al, %cl
movq -0x58(%rbp), %rax
movb %cl, (%rax)
movl -0x2c(%rbp), %eax
movb %al, %cl
movq -0x58(%rbp), %rax
movb %cl, 0x1(%rax)
cmpq $0x0, -0x40(%rbp)
jne 0x4c91e
movl -0x2c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x4c8b0
jmp 0x4c93d
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rdi
callq 0x4ca00
movq %rax, -0x40(%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, -0x5c(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x5c(%rbp), %rax
addq %rax, %rdi
movq -0x38(%rbp), %rsi
movslq -0x5c(%rbp), %rax
addq %rax, %rsi
movl -0x2c(%rbp), %eax
addl -0x20(%rbp), %eax
subl -0x5c(%rbp), %eax
movslq %eax, %rdx
callq 0xb420
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x38(%rbp), %rdi
movslq -0x2c(%rbp), %rax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
movslq -0x18(%rbp), %rax
addq %rax, %rsi
movslq -0x20(%rbp), %rdx
callq 0xb420
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x4c7d6
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 -0x4c(%rbp), %rax
addq %rax, %rdi
movl -0x2c(%rbp), %eax
subl -0x4c(%rbp), %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0xb2b0
movl -0x2c(%rbp), %eax
subl -0x4c(%rbp), %eax
movq -0x10(%rbp), %rcx
movzwl 0x10(%rcx), %ecx
cmpl %ecx, %eax
je 0x4c9e8
movl $0xdcc8, %edi           # imm = 0xDCC8
callq 0x2a650
movl %eax, -0x4(%rbp)
jmp 0x4c9ef
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)