// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: editPage
static int editPage(
  MemPage *pPg,                   /* Edit this page */
  int iOld,                       /* Index of first cell currently on page */
  int iNew,                       /* Index of new first cell on page */
  int nNew,                       /* Final number of cells on page */
  CellArray *pCArray              /* Array of cells and sizes */
){
  u8 * const aData = pPg->aData;
  const int hdr = pPg->hdrOffset;
  u8 *pBegin = &pPg->aCellIdx[nNew * 2];
  int nCell = pPg->nCell;       /* Cells stored on pPg */
  u8 *pData;
  u8 *pCellptr;
  int i;
  int iOldEnd = iOld + pPg->nCell + pPg->nOverflow;
  int iNewEnd = iNew + nNew;

#ifdef SQLITE_DEBUG
  u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
  memcpy(pTmp, aData, pPg->pBt->usableSize);
#endif

  /* Remove cells from the start and end of the page */
  assert( nCell>=0 );
  if( iOld<iNew ){
    int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray);
    if( NEVER(nShift>nCell) ) return SQLITE_CORRUPT_BKPT;
    memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
    nCell -= nShift;
  }
  if( iNewEnd < iOldEnd ){
    int nTail = pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
    assert( nCell>=nTail );
    nCell -= nTail;
  }

  pData = &aData[get2byteNotZero(&aData[hdr+5])];
  if( pData<pBegin ) goto editpage_fail;

  /* Add cells to the start of the page */
  if( iNew<iOld ){
    int nAdd = MIN(nNew,iOld-iNew);
    assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
    assert( nAdd>=0 );
    pCellptr = pPg->aCellIdx;
    memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
    if( pageInsertArray(
          pPg, pBegin, &pData, pCellptr,
          iNew, nAdd, pCArray
    ) ) goto editpage_fail;
    nCell += nAdd;
  }

  /* Add any overflow cells */
  for(i=0; i<pPg->nOverflow; i++){
    int iCell = (iOld + pPg->aiOvfl[i]) - iNew;
    if( iCell>=0 && iCell<nNew ){
      pCellptr = &pPg->aCellIdx[iCell * 2];
      if( nCell>iCell ){
        memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
      }
      nCell++;
      cachedCellSize(pCArray, iCell+iNew);
      if( pageInsertArray(
            pPg, pBegin, &pData, pCellptr,
            iCell+iNew, 1, pCArray
      ) ) goto editpage_fail;
    }
  }

  /* Append cells to the end of the page */
  assert( nCell>=0 );
  pCellptr = &pPg->aCellIdx[nCell*2];
  if( pageInsertArray(
        pPg, pBegin, &pData, pCellptr,
        iNew+nCell, nNew-nCell, pCArray
  ) ) goto editpage_fail;

  pPg->nCell = nNew;
  pPg->nOverflow = 0;

  put2byte(&aData[hdr+3], pPg->nCell);
  put2byte(&aData[hdr+5], pData - aData);

#ifdef SQLITE_DEBUG
  for(i=0; i<nNew && !CORRUPT_DB; i++){
    u8 *pCell = pCArray->apCell[i+iNew];
    int iOff = get2byteAligned(&pPg->aCellIdx[i*2]);
    if( SQLITE_WITHIN(pCell, aData, &aData[pPg->pBt->usableSize]) ){
      pCell = &pTmp[pCell - aData];
    }
    assert( 0==memcmp(pCell, &aData[iOff],
            pCArray->pRef->xCellSize(pCArray->pRef, pCArray->apCell[i+iNew])) );
  }
#endif

  return SQLITE_OK;
 editpage_fail:
  /* Unable to edit this page. Rebuild it from scratch instead. */
  populateCellCache(pCArray, iNew, nNew);
  return rebuildPage(pCArray, iNew, nNew, pPg);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x1c(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x18(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movzwl 0x18(%rcx), %ecx
addl %ecx, %eax
movq -0x10(%rbp), %rcx
movzbl 0xc(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x18(%rbp), %eax
addl -0x1c(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x407b95
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
subl -0x14(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x407f00
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
cmpl -0x44(%rbp), %eax
jle 0x407b63
movl $0x117ed, %edi          # imm = 0x117ED
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x407e90
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rsi
movl -0x68(%rbp), %eax
shll %eax
cltq
addq %rax, %rsi
movl -0x44(%rbp), %eax
shll %eax
movslq %eax, %rdx
callq 0x19bf0
movl -0x68(%rbp), %ecx
movl -0x44(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x60(%rbp), %eax
jge 0x407bc1
movq -0x10(%rbp), %rdi
movl -0x64(%rbp), %esi
movl -0x60(%rbp), %edx
subl -0x64(%rbp), %edx
movq -0x28(%rbp), %rcx
callq 0x407f00
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %ecx
movl -0x44(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x34(%rbp), %edx
addl $0x5, %edx
movslq %edx, %rdx
movzbl (%rcx,%rdx), %ecx
shll $0x8, %ecx
movq -0x30(%rbp), %rdx
movl -0x34(%rbp), %esi
addl $0x5, %esi
movslq %esi, %rsi
movzbl 0x1(%rdx,%rsi), %edx
orl %edx, %ecx
subl $0x1, %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
addl $0x1, %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x407c12
jmp 0x407e6b
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x407ca5
movl -0x1c(%rbp), %eax
movl -0x14(%rbp), %ecx
subl -0x18(%rbp), %ecx
cmpl %ecx, %eax
jge 0x407c33
movl -0x1c(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x407c3c
movl -0x14(%rbp), %eax
subl -0x18(%rbp), %eax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl %eax, -0x70(%rbp)
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
movl -0x70(%rbp), %eax
shll %eax
cltq
addq %rax, %rdi
movq -0x58(%rbp), %rsi
movl -0x44(%rbp), %eax
shll %eax
movslq %eax, %rdx
callq 0x19bf0
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x58(%rbp), %rcx
movl -0x18(%rbp), %r8d
movl -0x70(%rbp), %r9d
movq -0x28(%rbp), %rax
leaq -0x50(%rbp), %rdx
movq %rax, (%rsp)
callq 0x4080a0
cmpl $0x0, %eax
je 0x407c9c
jmp 0x407e6b
movl -0x70(%rbp), %eax
addl -0x44(%rbp), %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movq -0x10(%rbp), %rcx
movzbl 0xc(%rcx), %ecx
cmpl %ecx, %eax
jge 0x407d87
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
movslq -0x5c(%rbp), %rdx
movzwl 0x1c(%rcx,%rdx,2), %ecx
addl %ecx, %eax
subl -0x18(%rbp), %eax
movl %eax, -0x74(%rbp)
cmpl $0x0, -0x74(%rbp)
jl 0x407d77
movl -0x74(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x407d77
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x74(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x74(%rbp), %eax
jle 0x407d28
movq -0x58(%rbp), %rdi
addq $0x2, %rdi
movq -0x58(%rbp), %rsi
movl -0x44(%rbp), %eax
subl -0x74(%rbp), %eax
shll %eax
movslq %eax, %rdx
callq 0x19bf0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rdi
movl -0x74(%rbp), %esi
addl -0x18(%rbp), %esi
callq 0x407a10
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x58(%rbp), %rcx
movl -0x74(%rbp), %r8d
addl -0x18(%rbp), %r8d
movq -0x28(%rbp), %rax
leaq -0x50(%rbp), %rdx
movl $0x1, %r9d
movq %rax, (%rsp)
callq 0x4080a0
cmpl $0x0, %eax
je 0x407d75
jmp 0x407e6b
jmp 0x407d77
jmp 0x407d79
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x407cac
movq -0x10(%rbp), %rax
movq 0x60(%rax), %rax
movl -0x44(%rbp), %ecx
shll %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x58(%rbp), %rcx
movl -0x18(%rbp), %r8d
addl -0x44(%rbp), %r8d
movl -0x1c(%rbp), %r9d
subl -0x44(%rbp), %r9d
movq -0x28(%rbp), %rax
leaq -0x50(%rbp), %rdx
movq %rax, (%rsp)
callq 0x4080a0
cmpl $0x0, %eax
je 0x407dd5
jmp 0x407e6b
movl -0x1c(%rbp), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x18(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0xc(%rax)
movq -0x10(%rbp), %rax
movzwl 0x18(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x10(%rbp), %rax
movw 0x18(%rax), %ax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
movq -0x50(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
sarq $0x8, %rax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x50(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
movl $0x0, -0x4(%rbp)
jmp 0x407e90
movq -0x28(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x1c(%rbp), %edx
callq 0x4082e0
movq -0x28(%rbp), %rdi
movl -0x18(%rbp), %esi
movl -0x1c(%rbp), %edx
movq -0x10(%rbp), %rcx
callq 0x407670
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)