// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq 0x48(%rdi), %rcx
movq 0x50(%rdi), %rdx
movzbl 0x6(%rdi), %eax
movq %rax, -0x68(%rbp)
movzwl 0xe(%rdi), %eax
movq %rdi, -0x58(%rbp)
movzwl 0x12(%rdi), %r14d
movl 0x34(%rcx), %esi
leal (%rax,%r14,2), %ecx
movl %ecx, -0x30(%rbp)
testl %r14d, %r14d
movq %rdx, -0x40(%rbp)
je 0x3ad63
leal -0x4(%rsi), %ecx
movl %ecx, -0x5c(%rbp)
addq %rdx, %rax
incq %rax
movq %rax, -0x70(%rbp)
xorl %ebx, %ebx
movq %rsi, %rax
movq %rsi, -0x78(%rbp)
movl %eax, -0x2c(%rbp)
movq $0x0, -0x48(%rbp)
movq %rdx, -0x38(%rbp)
movq %r14, -0x50(%rbp)
movq -0x70(%rbp), %rax
movzwl -0x1(%rax,%rbx,2), %eax
rolw $0x8, %ax
movzwl %ax, %r15d
cmpl -0x30(%rbp), %r15d
jb 0x3ac90
cmpl -0x5c(%rbp), %r15d
jg 0x3ac90
movl %r15d, %r12d
movq -0x38(%rbp), %rax
leaq (%rax,%r12), %rsi
movq -0x58(%rbp), %rdi
callq *0x78(%rdi)
movzwl %ax, %r13d
movl -0x2c(%rbp), %r14d
subl %r13d, %r14d
cmpl -0x30(%rbp), %r14d
jl 0x3acb9
leal (%r15,%r13), %eax
cmpl -0x78(%rbp), %eax
jg 0x3acb9
movl %r14d, %eax
rolw $0x8, %ax
movq -0x70(%rbp), %rcx
movw %ax, -0x1(%rcx,%rbx,2)
cmpq $0x0, -0x48(%rbp)
jne 0x3ad2d
cmpl %r15d, %r14d
jne 0x3acdf
movl $0x4, %eax
movq $0x0, -0x48(%rbp)
jmp 0x3ad28
movl $0xb, %edi
leaq 0x4283c(%rip), %rsi     # 0x7d4d8
movl $0xdcaa, %edx           # imm = 0xDCAA
leaq 0x424d5(%rip), %rcx     # 0x7d17d
xorl %eax, %eax
callq 0xa4b0
movl $0x1, %eax
jmp 0x3ad4d
movl $0xb, %edi
leaq 0x42813(%rip), %rsi     # 0x7d4d8
movl $0xdcb0, %edx           # imm = 0xDCB0
leaq 0x424ac(%rip), %rcx     # 0x7d17d
xorl %eax, %eax
callq 0xa4b0
movl $0x1, %eax
jmp 0x3ad45
movq -0x58(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rax
movq 0x108(%rax), %rdx
movq %rdx, -0x38(%rbp)
movq -0x40(%rbp), %rcx
movq -0x68(%rbp), %rax
movzwl 0x5(%rcx,%rax), %eax
rolw $0x8, %ax
movzwl %ax, %eax
leaq (%rdx,%rax), %rdi
leaq (%rcx,%rax), %rsi
movl -0x2c(%rbp), %ecx
subl %eax, %ecx
movslq %ecx, %rdx
callq 0xa310
xorl %eax, %eax
movq -0x38(%rbp), %rcx
movq %rcx, -0x48(%rbp)
cmpl %r15d, %r14d
je 0x3ad45
movl %r14d, %edi
addq -0x40(%rbp), %rdi
addq -0x38(%rbp), %r12
movq %r12, %rsi
movq %r13, %rdx
callq 0xa310
xorl %eax, %eax
movl %r14d, -0x2c(%rbp)
movq -0x50(%rbp), %r14
testb $0x3, %al
jne 0x3add6
incq %rbx
cmpq %rbx, %r14
jne 0x3ac15
jmp 0x3ad66
movl %esi, -0x2c(%rbp)
movl -0x2c(%rbp), %esi
movl %esi, %eax
rolw $0x8, %ax
movq -0x40(%rbp), %rcx
movq -0x68(%rbp), %rdx
movw %ax, 0x5(%rcx,%rdx)
movw $0x0, 0x1(%rcx,%rdx)
movb $0x0, 0x7(%rcx,%rdx)
movl -0x30(%rbp), %eax
movl %eax, %edi
addq %rcx, %rdi
subl %eax, %esi
movslq %esi, %r15
xorl %r14d, %r14d
xorl %esi, %esi
movq %r15, %rdx
callq 0xa210
movq -0x58(%rbp), %rax
movzwl 0x10(%rax), %eax
cmpl %eax, %r15d
je 0x3addc
leaq 0x42722(%rip), %rsi     # 0x7d4d8
leaq 0x423c0(%rip), %rcx     # 0x7d17d
movl $0xb, %r14d
movl $0xb, %edi
movl $0xdcc8, %edx           # imm = 0xDCC8
xorl %eax, %eax
callq 0xa4b0
jmp 0x3addc
movl $0xb, %r14d
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq