// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: rebuildPage
static int rebuildPage(
  CellArray *pCArray,             /* Content to be added to page pPg */
  int iFirst,                     /* First cell in pCArray to use */
  int nCell,                      /* Final number of cells on page */
  MemPage *pPg                    /* The page to be reconstructed */
){
  const int hdr = pPg->hdrOffset;          /* Offset of header on pPg */
  u8 * const aData = pPg->aData;           /* Pointer to data for pPg */
  const int usableSize = pPg->pBt->usableSize;
  u8 * const pEnd = &aData[usableSize];
  int i = iFirst;                 /* Which cell to copy from pCArray*/
  u32 j;                          /* Start of cell content area */
  int iEnd = i+nCell;             /* Loop terminator */
  u8 *pCellptr = pPg->aCellIdx;
  u8 *pTmp = sqlite3PagerTempSpace(pPg->pBt->pPager);
  u8 *pData;
  int k;                          /* Current slot in pCArray->apEnd[] */
  u8 *pSrcEnd;                    /* Current pCArray->apEnd[k] value */

  assert( i<iEnd );
  j = get2byte(&aData[hdr+5]);
  if( NEVER(j>(u32)usableSize) ){ j = 0; }
  memcpy(&pTmp[j], &aData[j], usableSize - j);

  for(k=0; pCArray->ixNx[k]<=i && ALWAYS(k<NB*2); k++){}
  pSrcEnd = pCArray->apEnd[k];

  pData = pEnd;
  while( 1/*exit by break*/ ){
    u8 *pCell = pCArray->apCell[i];
    u16 sz = pCArray->szCell[i];
    assert( sz>0 );
    if( SQLITE_WITHIN(pCell,aData,pEnd) ){
      if( ((uptr)(pCell+sz))>(uptr)pEnd ) return SQLITE_CORRUPT_BKPT;
      pCell = &pTmp[pCell - aData];
    }else if( (uptr)(pCell+sz)>(uptr)pSrcEnd
           && (uptr)(pCell)<(uptr)pSrcEnd
    ){
      return SQLITE_CORRUPT_BKPT;
    }

    pData -= sz;
    put2byte(pCellptr, (pData - aData));
    pCellptr += 2;
    if( pData < pCellptr ) return SQLITE_CORRUPT_BKPT;
    memcpy(pData, pCell, sz);
    assert( sz==pPg->xCellSize(pPg, pCell) || CORRUPT_DB );
    testcase( sz!=pPg->xCellSize(pPg,pCell) )
    i++;
    if( i>=iEnd ) break;
    if( pCArray->ixNx[k]<=i ){
      k++;
      pSrcEnd = pCArray->apEnd[k];
    }
  }

  /* The pPg->nFree field is now set incorrectly. The caller will fix it. */
  pPg->nCell = nCell;
  pPg->nOverflow = 0;

  put2byte(&aData[hdr+1], 0);
  put2byte(&aData[hdr+3], pPg->nCell);
  put2byte(&aData[hdr+5], pData - aData);
  aData[hdr+7] = 0x00;
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rax
movzbl 0x9(%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x38(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x30(%rbp), %rax
movslq -0x34(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movq (%rax), %rdi
callq 0x405500
movq %rax, -0x60(%rbp)
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
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x34(%rbp), %eax
jbe 0x407726
movl $0x0, -0x48(%rbp)
movq -0x60(%rbp), %rdi
movl -0x48(%rbp), %eax
addq %rax, %rdi
movq -0x30(%rbp), %rsi
movl -0x48(%rbp), %eax
addq %rax, %rsi
movl -0x34(%rbp), %eax
subl -0x48(%rbp), %eax
movl %eax, %eax
movl %eax, %edx
callq 0x19610
movl $0x0, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl 0x50(%rax,%rcx,4), %ecx
xorl %eax, %eax
cmpl -0x44(%rbp), %ecx
movb %al, -0x83(%rbp)
jg 0x407776
cmpl $0x6, -0x6c(%rbp)
setl %al
movb %al, -0x83(%rbp)
movb -0x83(%rbp), %al
testb $0x1, %al
jne 0x407782
jmp 0x40778f
jmp 0x407784
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x407750
movq -0x10(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq 0x20(%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movslq -0x44(%rbp), %rcx
movw (%rax,%rcx,2), %ax
movw %ax, -0x82(%rbp)
movq -0x80(%rbp), %rax
movq -0x30(%rbp), %rcx
cmpq %rcx, %rax
jb 0x407831
movq -0x80(%rbp), %rax
movq -0x40(%rbp), %rcx
cmpq %rcx, %rax
jae 0x407831
movq -0x80(%rbp), %rax
movzwl -0x82(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x40(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x407819
movl $0x1171f, %edi          # imm = 0x1171F
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x4079fa
movq -0x60(%rbp), %rax
movq -0x80(%rbp), %rcx
movq -0x30(%rbp), %rdx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
jmp 0x40786c
movq -0x80(%rbp), %rax
movzwl -0x82(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq -0x78(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x40786a
movq -0x80(%rbp), %rax
movq -0x78(%rbp), %rcx
cmpq %rcx, %rax
jae 0x40786a
movl $0x11724, %edi          # imm = 0x11724
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x4079fa
jmp 0x40786c
movzwl -0x82(%rbp), %ecx
movq -0x68(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
sarq $0x8, %rax
movb %al, %cl
movq -0x58(%rbp), %rax
movb %cl, (%rax)
movq -0x68(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movb %al, %cl
movq -0x58(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x58(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x58(%rbp), %rax
jae 0x4078d9
movl $0x1172a, %edi          # imm = 0x1172A
callq 0x3dff80
movl %eax, -0x4(%rbp)
jmp 0x4079fa
movq -0x68(%rbp), %rdi
movq -0x80(%rbp), %rsi
movzwl -0x82(%rbp), %eax
movl %eax, %edx
callq 0x19610
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jl 0x407902
jmp 0x407932
movq -0x10(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl 0x50(%rax,%rcx,4), %eax
cmpl -0x44(%rbp), %eax
jg 0x40792d
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movq -0x10(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movq 0x20(%rax,%rcx,8), %rax
movq %rax, -0x78(%rbp)
jmp 0x4077a8
movl -0x18(%rbp), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, 0x18(%rax)
movq -0x20(%rbp), %rax
movb $0x0, 0xc(%rax)
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb $0x0, 0x1(%rax,%rcx)
movq -0x20(%rbp), %rax
movzwl 0x18(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
movw 0x18(%rax), %ax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
movq -0x68(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
sarq $0x8, %rax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x68(%rbp), %rax
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movb %al, %dl
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x5, %ecx
movslq %ecx, %rcx
movb %dl, 0x1(%rax,%rcx)
movq -0x30(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x7, %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)