// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %ebp
movl %esi, %r12d
movq %rdi, %r15
movzbl 0x9(%rcx), %esi
movq 0x48(%rcx), %rax
movq 0x50(%rcx), %r8
movslq 0x38(%rax), %rdx
movq %rdx, %rdi
addq %r8, %rdi
movq %rdi, 0x8(%rsp)
movq %rcx, 0x18(%rsp)
movq 0x60(%rcx), %r13
movq (%rax), %rax
movq %rsi, 0x20(%rsp)
movzwl 0x5(%r8,%rsi), %ecx
rolw $0x8, %cx
movzwl %cx, %ecx
xorl %r14d, %r14d
cmpl %edx, %ecx
cmoval %r14d, %ecx
movq 0x110(%rax), %rax
movq %rax, 0x28(%rsp)
leaq (%rax,%rcx), %rdi
movq %r8, (%rsp)
leaq (%r8,%rcx), %rsi
subl %ecx, %edx
callq 0x17660
leaq 0x1(%r14), %rbx
cmpq $0x5, %r14
ja 0x2a34fe
cmpl %r12d, 0x50(%r15,%r14,4)
movq %rbx, %r14
jle 0x2a34ea
movq %rbp, 0x10(%rsp)
leal (%r12,%rbp), %eax
movslq %r12d, %rbp
cltq
movq %rax, 0x40(%rsp)
decq %rbx
movq 0x8(%rsp), %r14
movq (%rsp), %rdi
movq 0x20(%r15,%rbx,8), %rax
movq %rax, 0x30(%rsp)
movslq %ebx, %rax
movq %rax, 0x38(%rsp)
movq 0x10(%r15), %rax
movq 0x18(%r15), %rcx
movq (%rax,%rbp,8), %rsi
movzwl (%rcx,%rbp,2), %edx
leaq (%rsi,%rdx), %rcx
movq %rsi, %rax
subq %rdi, %rax
jb 0x2a3567
cmpq 0x8(%rsp), %rsi
jae 0x2a3567
cmpq 0x8(%rsp), %rcx
ja 0x2a363c
addq 0x28(%rsp), %rax
movq %rax, %rsi
jmp 0x2a357a
movq 0x30(%rsp), %rax
cmpq %rax, %rsi
jae 0x2a357a
cmpq %rax, %rcx
ja 0x2a3662
subq %rdx, %r14
movq %r14, %r12
subq %rdi, %r12
movl %r12d, %eax
rolw $0x8, %ax
movw %ax, (%r13)
addq $0x2, %r13
cmpq %r13, %r14
jb 0x2a35cb
movq %r14, %rdi
callq 0x17660
incq %rbp
cmpq 0x40(%rsp), %rbp
jge 0x2a35f4
movq 0x38(%rsp), %rax
movslq 0x50(%r15,%rax,4), %rax
cmpq %rax, %rbp
movq (%rsp), %rdi
jl 0x2a352f
incl %ebx
movslq %ebx, %rbx
jmp 0x2a351d
leaq 0x1325f9(%rip), %rsi    # 0x3d5bcb
leaq 0x132703(%rip), %rdx    # 0x3d5cdc
leaq 0x132451(%rip), %r8     # 0x3d5a31
movl $0xb, %ebp
movl $0xb, %edi
movl $0x1172a, %ecx          # imm = 0x1172A
jmp 0x2a3686
movl %r12d, %eax
shrl $0x8, %eax
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rcx
movw %cx, 0x18(%rsi)
xorl %ebp, %ebp
movb %bpl, 0xc(%rsi)
movq 0x20(%rsp), %rdx
movq (%rsp), %rdi
movw $0x0, 0x1(%rdi,%rdx)
movb 0x19(%rsi), %cl
movb %cl, 0x3(%rdi,%rdx)
movb 0x18(%rsi), %cl
movb %cl, 0x4(%rdi,%rdx)
movb %al, 0x5(%rdi,%rdx)
movb %r12b, 0x6(%rdi,%rdx)
movb %bpl, 0x7(%rdi,%rdx)
jmp 0x2a368d
leaq 0x132588(%rip), %rsi    # 0x3d5bcb
leaq 0x132692(%rip), %rdx    # 0x3d5cdc
leaq 0x1323e0(%rip), %r8     # 0x3d5a31
movl $0xb, %ebp
movl $0xb, %edi
movl $0x1171f, %ecx          # imm = 0x1171F
jmp 0x2a3686
leaq 0x132562(%rip), %rsi    # 0x3d5bcb
leaq 0x13266c(%rip), %rdx    # 0x3d5cdc
leaq 0x1323ba(%rip), %r8     # 0x3d5a31
movl $0xb, %ebp
movl $0xb, %edi
movl $0x11724, %ecx          # imm = 0x11724
xorl %eax, %eax
callq 0x274d08
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq