// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/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;
  CellInfo info;

  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 = 0;
  if( !pPage->leaf ){
    nHeader += 4;
  }
  if( pPage->hasData ){
    nHeader += putVarint(&pCell[nHeader], nData+nZero);
  }else{
    nData = nZero = 0;
  }
  nHeader += putVarint(&pCell[nHeader], *(u64*)&nKey);
  btreeParseCellPtr(pPage, pCell, &info);
  assert( info.nHeader==nHeader );
  assert( info.nKey==nKey );
  assert( info.nData==(u32)(nData+nZero) );
  
  /* Fill in the payload */
  nPayload = nData + nZero;
  if( pPage->intKey ){
    pSrc = pData;
    nSrc = nData;
    nData = 0;
  }else{ 
    if( NEVER(nKey>0x7fffffff || pKey==0) ){
      return SQLITE_CORRUPT_BKPT;
    }
    nPayload += (int)nKey;
    pSrc = pKey;
    nSrc = (int)nKey;
  }
  *pnSize = info.nSize;
  spaceLeft = info.nLocal;
  pPayload = &pCell[nHeader];
  pPrior = &pCell[info.iOverflow];

  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 $0xb0, %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)
movl $0x0, -0x80(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x3(%rax)
jne 0x418c7
movl -0x80(%rbp), %eax
addl $0x4, %eax
movl %eax, -0x80(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x4(%rax)
je 0x418f2
movq -0x18(%rbp), %rdi
movslq -0x80(%rbp), %rax
addq %rax, %rdi
movl -0x34(%rbp), %eax
addl 0x10(%rbp), %eax
movslq %eax, %rsi
callq 0x407e0
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
jmp 0x41900
movl $0x0, 0x10(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x18(%rbp), %rdi
movslq -0x80(%rbp), %rax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
callq 0x407e0
addl -0x80(%rbp), %eax
movl %eax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0xa0(%rbp), %rdx
callq 0x2c070
movl -0x34(%rbp), %eax
addl 0x10(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0x41958
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x34(%rbp)
jmp 0x41994
cmpq $0x7fffffff, -0x28(%rbp) # imm = 0x7FFFFFFF
jg 0x41969
cmpq $0x0, -0x20(%rbp)
jne 0x4197b
movl $0xd757, %edi           # imm = 0xD757
callq 0x24410
movl %eax, -0x4(%rbp)
jmp 0x41bed
movq -0x28(%rbp), %rax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rax
movl %eax, -0x44(%rbp)
movzwl -0x82(%rbp), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
movzwl -0x86(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movslq -0x80(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movzwl -0x84(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
cmpl $0x0, -0x38(%rbp)
jle 0x41bdd
cmpl $0x0, -0x50(%rbp)
jne 0x41b37
movl -0x7c(%rbp), %eax
movl %eax, -0xa4(%rbp)
movq -0x78(%rbp), %rax
cmpb $0x0, 0x21(%rax)
je 0x41a53
jmp 0x419f5
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movq -0x78(%rbp), %rdi
movl -0x7c(%rbp), %esi
callq 0x2b950
movl %eax, %ecx
movb $0x1, %al
cmpl -0x7c(%rbp), %ecx
movb %al, -0xa6(%rbp)
je 0x41a47
movl -0x7c(%rbp), %eax
movl %eax, -0xac(%rbp)
movl 0x8eea8(%rip), %eax     # 0xd08d0
movq -0x78(%rbp), %rcx
xorl %edx, %edx
divl 0x30(%rcx)
movl %eax, %ecx
movl -0xac(%rbp), %eax
addl $0x1, %ecx
cmpl %ecx, %eax
sete %al
movb %al, -0xa6(%rbp)
movb -0xa6(%rbp), %al
testb $0x1, %al
jne 0x419f5
jmp 0x41a53
movq -0x78(%rbp), %rdi
movl -0x7c(%rbp), %ecx
leaq -0x58(%rbp), %rsi
leaq -0x7c(%rbp), %rdx
xorl %r8d, %r8d
callq 0x2cef0
movl %eax, -0x4c(%rbp)
movq -0x78(%rbp), %rax
movzbl 0x21(%rax), %eax
cmpl $0x0, %eax
je 0x41acc
cmpl $0x0, -0x4c(%rbp)
jne 0x41acc
movl -0xa4(%rbp), %edx
movl $0x3, %eax
movl $0x4, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movb %al, -0xa5(%rbp)
movq -0x78(%rbp), %rdi
movl -0x7c(%rbp), %esi
movb -0xa5(%rbp), %al
movl -0xa4(%rbp), %ecx
leaq -0x4c(%rbp), %r8
movzbl %al, %edx
callq 0x2dd40
cmpl $0x0, -0x4c(%rbp)
je 0x41aca
movq -0x58(%rbp), %rdi
callq 0x29fd0
jmp 0x41acc
cmpl $0x0, -0x4c(%rbp)
je 0x41ae6
movq -0x60(%rbp), %rdi
callq 0x29fd0
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x41bed
movq -0x68(%rbp), %rdi
movl -0x7c(%rbp), %esi
callq 0x22060
movq -0x60(%rbp), %rdi
callq 0x29fd0
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 0x22060
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 0x41b4b
movl -0x50(%rbp), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x44(%rbp)
jle 0x41b72
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jle 0x41b5f
movl -0x44(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x70(%rbp), %rdi
movq -0x40(%rbp), %rsi
movslq -0x48(%rbp), %rdx
callq 0x82f0
jmp 0x41b81
movq -0x70(%rbp), %rdi
movslq -0x48(%rbp), %rdx
xorl %esi, %esi
callq 0x8200
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 0x41bd8
movl -0x34(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x419cc
movq -0x60(%rbp), %rdi
callq 0x29fd0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax)