// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: backupOnePage
static int backupOnePage(
  sqlite3_backup *p,              /* Backup handle */
  Pgno iSrcPg,                    /* Source database page to backup */
  const u8 *zSrcData,             /* Source database page data */
  int bUpdate                     /* True for an update, false otherwise */
){
  Pager * const pDestPager = sqlite3BtreePager(p->pDest);
  const int nSrcPgsz = sqlite3BtreeGetPageSize(p->pSrc);
  int nDestPgsz = sqlite3BtreeGetPageSize(p->pDest);
  const int nCopy = MIN(nSrcPgsz, nDestPgsz);
  const i64 iEnd = (i64)iSrcPg*(i64)nSrcPgsz;
#ifdef SQLITE_HAS_CODEC
  /* Use BtreeGetReserveNoMutex() for the source b-tree, as although it is
  ** guaranteed that the shared-mutex is held by this thread, handle
  ** p->pSrc may not actually be the owner.  */
  int nSrcReserve = sqlite3BtreeGetReserveNoMutex(p->pSrc);
  int nDestReserve = sqlite3BtreeGetReserve(p->pDest);
#endif
  int rc = SQLITE_OK;
  i64 iOff;

  assert( sqlite3BtreeGetReserveNoMutex(p->pSrc)>=0 );
  assert( p->bDestLocked );
  assert( !isFatalError(p->rc) );
  assert( iSrcPg!=PENDING_BYTE_PAGE(p->pSrc->pBt) );
  assert( zSrcData );

  /* Catch the case where the destination is an in-memory database and the
  ** page sizes of the source and destination differ. 
  */
  if( nSrcPgsz!=nDestPgsz && sqlite3PagerIsMemdb(pDestPager) ){
    rc = SQLITE_READONLY;
  }

#ifdef SQLITE_HAS_CODEC
  /* Backup is not possible if the page size of the destination is changing
  ** and a codec is in use.
  */
  if( nSrcPgsz!=nDestPgsz && sqlite3PagerGetCodec(pDestPager)!=0 ){
    rc = SQLITE_READONLY;
  }

  /* Backup is not possible if the number of bytes of reserve space differ
  ** between source and destination.  If there is a difference, try to
  ** fix the destination to agree with the source.  If that is not possible,
  ** then the backup cannot proceed.
  */
  if( nSrcReserve!=nDestReserve ){
    u32 newPgsz = nSrcPgsz;
    rc = sqlite3PagerSetPagesize(pDestPager, &newPgsz, nSrcReserve);
    if( rc==SQLITE_OK && newPgsz!=nSrcPgsz ) rc = SQLITE_READONLY;
  }
#endif

  /* This loop runs once for each destination page spanned by the source 
  ** page. For each iteration, variable iOff is set to the byte offset
  ** of the destination page.
  */
  for(iOff=iEnd-(i64)nSrcPgsz; rc==SQLITE_OK && iOff<iEnd; iOff+=nDestPgsz){
    DbPage *pDestPg = 0;
    Pgno iDest = (Pgno)(iOff/nDestPgsz)+1;
    if( iDest==PENDING_BYTE_PAGE(p->pDest->pBt) ) continue;
    if( SQLITE_OK==(rc = sqlite3PagerGet(pDestPager, iDest, &pDestPg))
     && SQLITE_OK==(rc = sqlite3PagerWrite(pDestPg))
    ){
      const u8 *zIn = &zSrcData[iOff%nSrcPgsz];
      u8 *zDestData = sqlite3PagerGetData(pDestPg);
      u8 *zOut = &zDestData[iOff%nDestPgsz];

      /* Copy the data from the source page into the destination page.
      ** Then clear the Btree layer MemPage.isInit flag. Both this module
      ** and the pager code use this trick (clearing the first byte
      ** of the page 'extra' space to invalidate the Btree layers
      ** cached parse of the page). MemPage.isInit is marked 
      ** "MUST BE FIRST" for this purpose.
      */
      memcpy(zOut, zIn, nCopy);
      ((u8 *)sqlite3PagerGetExtra(pDestPg))[0] = 0;
      if( iOff==0 && bUpdate==0 ){
        sqlite3Put4byte(&zOut[28], sqlite3BtreeLastPage(p->pSrc));
      }
    }
    sqlite3PagerUnref(pDestPg);
  }

  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x98f0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0xe590
movl %eax, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xe590
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0xea3a
movl -0x2c(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0xea40
movl -0x30(%rbp), %eax
movl %eax, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0xc(%rbp), %eax
movslq -0x2c(%rbp), %rcx
imulq %rcx, %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
je 0xea79
movq -0x28(%rbp), %rdi
callq 0x2ad00
cmpl $0x0, %eax
je 0xea79
movl $0x8, -0x44(%rbp)
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x50(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x44(%rbp)
movb %al, -0x7d(%rbp)
jne 0xeaa1
movq -0x50(%rbp), %rax
cmpq -0x40(%rbp), %rax
setl %al
movb %al, -0x7d(%rbp)
movb -0x7d(%rbp), %al
testb $0x1, %al
jne 0xeaad
jmp 0xebfe
movq $0x0, -0x58(%rbp)
movq -0x50(%rbp), %rax
movslq -0x30(%rbp), %rcx
cqto
idivq %rcx
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x84(%rbp)
movl 0xc1df9(%rip), %eax     # 0xd08d0
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
xorl %edx, %edx
divl 0x30(%rcx)
movl %eax, %ecx
movl -0x84(%rbp), %eax
addl $0x1, %ecx
cmpl %ecx, %eax
jne 0xeafc
jmp 0xebed
movq -0x28(%rbp), %rdi
movl -0x5c(%rbp), %esi
leaq -0x58(%rbp), %rdx
xorl %ecx, %ecx
callq 0xe5f0
movl %eax, %ecx
movl %ecx, -0x44(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xebe4
movq -0x58(%rbp), %rdi
callq 0xef80
movl %eax, %ecx
movl %ecx, -0x44(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0xebe4
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x50(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cqto
idivq %rcx
movq -0x98(%rbp), %rax
addq %rdx, %rax
movq %rax, -0x68(%rbp)
movq -0x58(%rbp), %rdi
callq 0xec10
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x50(%rbp), %rax
movslq -0x30(%rbp), %rcx
cqto
idivq %rcx
movq -0x90(%rbp), %rax
addq %rdx, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movq -0x68(%rbp), %rsi
movslq -0x34(%rbp), %rdx
callq 0x82f0
movq -0x58(%rbp), %rdi
callq 0x24a20
movb $0x0, (%rax)
cmpq $0x0, -0x50(%rbp)
jne 0xebe2
cmpl $0x0, -0x1c(%rbp)
jne 0xebe2
movq -0x78(%rbp), %rax
addq $0x1c, %rax
movq %rax, -0xa0(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0xe5d0
movq -0xa0(%rbp), %rdi
movl %eax, %esi
callq 0x22060
jmp 0xebe4
movq -0x58(%rbp), %rdi
callq 0xec30
movslq -0x30(%rbp), %rax
addq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0xea88
movl -0x44(%rbp), %eax
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)