// File: /workspace/github_c_makefile_star2_O0/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: fillInCell
static int fillInCell(
  MemPage *pPage,                /* The page that contains the cell */
  unsigned char *pCell,          /* Complete text of the cell */
  const void *pKey, i64 nKey,    /* The key */
  const void *pData,int nData,   /* The data */
  int nZero,                     /* Extra zero bytes to append to pData */
  int *pnSize                    /* Write cell size here */
){
  int nPayload;
  const u8 *pSrc;
  int nSrc, n, rc;
  int spaceLeft;
  MemPage *pOvfl = 0;
  MemPage *pToRelease = 0;
  unsigned char *pPrior;
  unsigned char *pPayload;
  BtShared *pBt = pPage->pBt;
  Pgno pgnoOvfl = 0;
  int nHeader;

  assert( sqlite3_mutex_held(pPage->pBt->mutex) );

  /* pPage is not necessarily writeable since pCell might be auxiliary
  ** buffer space that is separate from the pPage buffer area */
  assert( pCell<pPage->aData || pCell>=&pPage->aData[pBt->pageSize]
            || sqlite3PagerIswriteable(pPage->pDbPage) );

  /* Fill in the header. */
  nHeader = pPage->childPtrSize;
  nPayload = nData + nZero;
  if( pPage->intKeyLeaf ){
    nHeader += putVarint32(&pCell[nHeader], nPayload);
  }else{
    assert( nData==0 );
    assert( nZero==0 );
  }
  nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
  
  /* Fill in the payload size */
  if( pPage->intKey ){
    pSrc = pData;
    nSrc = nData;
    nData = 0;
  }else{ 
    assert( nKey<=0x7fffffff && pKey!=0 );
    nPayload = (int)nKey;
    pSrc = pKey;
    nSrc = (int)nKey;
  }
  if( nPayload<=pPage->maxLocal ){
    n = nHeader + nPayload;
    testcase( n==3 );
    testcase( n==4 );
    if( n<4 ) n = 4;
    *pnSize = n;
    spaceLeft = nPayload;
    pPrior = pCell;
  }else{
    int mn = pPage->minLocal;
    n = mn + (nPayload - mn) % (pPage->pBt->usableSize - 4);
    testcase( n==pPage->maxLocal );
    testcase( n==pPage->maxLocal+1 );
    if( n > pPage->maxLocal ) n = mn;
    spaceLeft = n;
    *pnSize = n + nHeader + 4;
    pPrior = &pCell[nHeader+n];
  }
  pPayload = &pCell[nHeader];

  /* At this point variables should be set as follows:
  **
  **   nPayload           Total payload size in bytes
  **   pPayload           Begin writing payload here
  **   spaceLeft          Space available at pPayload.  If nPayload>spaceLeft,
  **                      that means content must spill into overflow pages.
  **   *pnSize            Size of the local cell (not counting overflow pages)
  **   pPrior             Where to write the pgno of the first overflow page
  **
  ** Use a call to btreeParseCellPtr() to verify that the values above
  ** were computed correctly.
  */
#if SQLITE_DEBUG
  {
    CellInfo info;
    pPage->xParseCell(pPage, pCell, &info);
    assert( nHeader=(int)(info.pPayload - pCell) );
    assert( info.nKey==nKey );
    assert( *pnSize == info.nSize );
    assert( spaceLeft == info.nLocal );
  }
#endif

  /* Write the payload into the local Cell and any extra into overflow pages */
  while( nPayload>0 ){
    if( spaceLeft==0 ){
#ifndef SQLITE_OMIT_AUTOVACUUM
      Pgno pgnoPtrmap = pgnoOvfl; /* Overflow page pointer-map entry page */
      if( pBt->autoVacuum ){
        do{
          pgnoOvfl++;
        } while( 
          PTRMAP_ISPAGE(pBt, pgnoOvfl) || pgnoOvfl==PENDING_BYTE_PAGE(pBt) 
        );
      }
#endif
      rc = allocateBtreePage(pBt, &pOvfl, &pgnoOvfl, pgnoOvfl, 0);
#ifndef SQLITE_OMIT_AUTOVACUUM
      /* If the database supports auto-vacuum, and the second or subsequent
      ** overflow page is being allocated, add an entry to the pointer-map
      ** for that page now. 
      **
      ** If this is the first overflow page, then write a partial entry 
      ** to the pointer-map. If we write nothing to this pointer-map slot,
      ** then the optimistic overflow chain processing in clearCell()
      ** may misinterpret the uninitialized values and delete the
      ** wrong pages from the database.
      */
      if( pBt->autoVacuum && rc==SQLITE_OK ){
        u8 eType = (pgnoPtrmap?PTRMAP_OVERFLOW2:PTRMAP_OVERFLOW1);
        ptrmapPut(pBt, pgnoOvfl, eType, pgnoPtrmap, &rc);
        if( rc ){
          releasePage(pOvfl);
        }
      }
#endif
      if( rc ){
        releasePage(pToRelease);
        return rc;
      }

      /* If pToRelease is not zero than pPrior points into the data area
      ** of pToRelease.  Make sure pToRelease is still writeable. */
      assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );

      /* If pPrior is part of the data area of pPage, then make sure pPage
      ** is still writeable */
      assert( pPrior<pPage->aData || pPrior>=&pPage->aData[pBt->pageSize]
            || sqlite3PagerIswriteable(pPage->pDbPage) );

      put4byte(pPrior, pgnoOvfl);
      releasePage(pToRelease);
      pToRelease = pOvfl;
      pPrior = pOvfl->aData;
      put4byte(pPrior, 0);
      pPayload = &pOvfl->aData[4];
      spaceLeft = pBt->usableSize - 4;
    }
    n = nPayload;
    if( n>spaceLeft ) n = spaceLeft;

    /* If pToRelease is not zero than pPayload points into the data area
    ** of pToRelease.  Make sure pToRelease is still writeable. */
    assert( pToRelease==0 || sqlite3PagerIswriteable(pToRelease->pDbPage) );

    /* If pPayload is part of the data area of pPage, then make sure pPage
    ** is still writeable */
    assert( pPayload<pPage->aData || pPayload>=&pPage->aData[pBt->pageSize]
            || sqlite3PagerIswriteable(pPage->pDbPage) );

    if( nSrc>0 ){
      if( n>nSrc ) n = nSrc;
      assert( pSrc );
      memcpy(pPayload, pSrc, n);
    }else{
      memset(pPayload, 0, n);
    }
    nPayload -= n;
    pPayload += n;
    pSrc += n;
    nSrc -= n;
    spaceLeft -= n;
    if( nSrc==0 ){
      nSrc = nData;
      pSrc = pData;
    }
  }
  releasePage(pToRelease);
  return SQLITE_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq 0x18(%rbp), %rax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x7(%rax), %eax
movl %eax, -0x80(%rbp)
movl -0x34(%rbp), %eax
addl 0x10(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x3(%rax)
je 0x4aeac
cmpl $0x80, -0x38(%rbp)
jae 0x4ae81
movl -0x38(%rbp), %eax
movb %al, %dl
movq -0x18(%rbp), %rax
movslq -0x80(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl $0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x4ae9b
movq -0x18(%rbp), %rdi
movslq -0x80(%rbp), %rax
addq %rax, %rdi
movslq -0x38(%rbp), %rsi
callq 0x43a70
movl %eax, -0x90(%rbp)
movl -0x90(%rbp), %eax
movzbl %al, %eax
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x4aeae
jmp 0x4aeae
movq -0x18(%rbp), %rdi
movslq -0x80(%rbp), %rax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x43a70
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x4aee9
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x34(%rbp)
jmp 0x4aeff
movq -0x28(%rbp), %rax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movl %eax, -0x44(%rbp)
movl -0x38(%rbp), %eax
movq -0x10(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
cmpl %ecx, %eax
jg 0x4af40
movl -0x80(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x4, -0x48(%rbp)
jge 0x4af24
movl $0x4, -0x48(%rbp)
movl -0x48(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movl -0x38(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0x4afc1
movq -0x10(%rbp), %rax
movzwl 0xc(%rax), %eax
movl %eax, -0x84(%rbp)
movl -0x84(%rbp), %eax
movl %eax, -0x94(%rbp)
movl -0x38(%rbp), %eax
subl -0x84(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl 0x34(%rcx), %ecx
subl $0x4, %ecx
xorl %edx, %edx
divl %ecx
movl -0x94(%rbp), %eax
addl %edx, %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x10(%rbp), %rcx
movzwl 0xa(%rcx), %ecx
cmpl %ecx, %eax
jle 0x4af98
movl -0x84(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x48(%rbp), %ecx
addl -0x80(%rbp), %ecx
addl $0x4, %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl -0x80(%rbp), %ecx
addl -0x48(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
movslq -0x80(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
cmpl $0x0, -0x38(%rbp)
jle 0x4b1e1
cmpl $0x0, -0x50(%rbp)
jne 0x4b13b
movl -0x7c(%rbp), %eax
movl %eax, -0x88(%rbp)
movq -0x78(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x4b057
jmp 0x4aff9
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movq -0x78(%rbp), %rdi
movl -0x7c(%rbp), %esi
callq 0x32d20
movl %eax, %ecx
movb $0x1, %al
cmpl -0x7c(%rbp), %ecx
movb %al, -0x95(%rbp)
je 0x4b04b
movl -0x7c(%rbp), %eax
movl %eax, -0x9c(%rbp)
movl 0x748e4(%rip), %eax     # 0xbf910
movq -0x78(%rbp), %rcx
xorl %edx, %edx
divl 0x30(%rcx)
movl %eax, %ecx
movl -0x9c(%rbp), %eax
addl $0x1, %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0x95(%rbp)
movb -0x95(%rbp), %al
testb $0x1, %al
jne 0x4aff9
jmp 0x4b057
movq -0x78(%rbp), %rdi
movl -0x7c(%rbp), %ecx
leaq -0x58(%rbp), %rsi
leaq -0x7c(%rbp), %rdx
xorl %r8d, %r8d
callq 0x33c40
movl %eax, -0x4c(%rbp)
movq -0x78(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x0, %eax
je 0x4b0d0
cmpl $0x0, -0x4c(%rbp)
jne 0x4b0d0
movl -0x88(%rbp), %edx
movl $0x3, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, -0x89(%rbp)
movq -0x78(%rbp), %rdi
movl -0x7c(%rbp), %esi
movb -0x89(%rbp), %al
movl -0x88(%rbp), %ecx
leaq -0x4c(%rbp), %r8
movzbl %al, %edx
callq 0x34b20
cmpl $0x0, -0x4c(%rbp)
je 0x4b0ce
movq -0x58(%rbp), %rdi
callq 0x30e20
jmp 0x4b0d0
cmpl $0x0, -0x4c(%rbp)
je 0x4b0ea
movq -0x60(%rbp), %rdi
callq 0x30e20
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4b1f1
movq -0x68(%rbp), %rdi
movl -0x7c(%rbp), %esi
callq 0x28290
movq -0x60(%rbp), %rdi
callq 0x30e20
movq -0x58(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
xorl %esi, %esi
callq 0x28290
movq -0x58(%rbp), %rax
movq 0x50(%rax), %rax
addq $0x4, %rax
movq %rax, -0x70(%rbp)
movq -0x78(%rbp), %rax
movl 0x34(%rax), %eax
subl $0x4, %eax
movl %eax, -0x50(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x50(%rbp), %eax
jle 0x4b14f
movl -0x50(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x44(%rbp)
jle 0x4b176
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jle 0x4b163
movl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x70(%rbp), %rdi
movq -0x40(%rbp), %rsi
movslq -0x48(%rbp), %rdx
callq 0xb420
jmp 0x4b185
movq -0x70(%rbp), %rdi
movslq -0x48(%rbp), %rdx
xorl %esi, %esi
callq 0xb2b0
movl -0x48(%rbp), %ecx
movl -0x38(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x48(%rbp), %ecx
movq -0x70(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movl -0x48(%rbp), %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x48(%rbp), %ecx
movl -0x44(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x48(%rbp), %ecx
movl -0x50(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x50(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x4b1dc
movl -0x34(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x4afd0
movq -0x60(%rbp), %rdi
callq 0x30e20
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax)