// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3BtreeCopyFile
SQLITE_PRIVATE int sqlite3BtreeCopyFile(Btree *pTo, Btree *pFrom){
  int rc;
  sqlite3_file *pFd;              /* File descriptor for database pTo */
  sqlite3_backup b;
  sqlite3BtreeEnter(pTo);
  sqlite3BtreeEnter(pFrom);

  assert( sqlite3BtreeIsInTrans(pTo) );
  pFd = sqlite3PagerFile(sqlite3BtreePager(pTo));
  if( pFd->pMethods ){
    i64 nByte = sqlite3BtreeGetPageSize(pFrom)*(i64)sqlite3BtreeLastPage(pFrom);
    rc = sqlite3OsFileControl(pFd, SQLITE_FCNTL_OVERWRITE, &nByte);
    if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
    if( rc ) goto copy_finished;
  }

  /* Set up an sqlite3_backup object. sqlite3_backup.pDestDb must be set
  ** to 0. This is used by the implementations of sqlite3_backup_step()
  ** and sqlite3_backup_finish() to detect that they are being called
  ** from this function, not directly by the user.
  */
  memset(&b, 0, sizeof(b));
  b.pSrcDb = pFrom->db;
  b.pSrc = pFrom;
  b.pDest = pTo;
  b.iNext = 1;

  /* 0x7FFFFFFF is the hard limit for the number of pages in a database
  ** file. By passing this as the number of pages to copy to
  ** sqlite3_backup_step(), we can guarantee that the copy finishes 
  ** within a single call (unless an error occurs). The assert() statement
  ** checks this assumption - (p->rc) should be set to either SQLITE_DONE 
  ** or an error code.
  */
  sqlite3_backup_step(&b, 0x7FFFFFFF);
  assert( b.rc!=SQLITE_OK );
  rc = sqlite3_backup_finish(&b);
  if( rc==SQLITE_OK ){
    pTo->pBt->btsFlags &= ~BTS_PAGESIZE_FIXED;
  }else{
    sqlite3PagerClearCache(sqlite3BtreePager(b.pDest));
  }

  assert( sqlite3BtreeIsInTrans(pTo)==0 );
copy_finished:
  sqlite3BtreeLeave(pFrom);
  sqlite3BtreeLeave(pTo);
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0xe0f0
movq -0x10(%rbp), %rdi
callq 0xe0f0
movq -0x8(%rbp), %rdi
callq 0x98f0
movq %rax, %rdi
callq 0xef40
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
je 0x49058
movq -0x10(%rbp), %rdi
callq 0xe590
cltq
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
callq 0xe5d0
movl %eax, %ecx
movq -0x78(%rbp), %rax
movl %ecx, %ecx
imulq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x20(%rbp), %rdi
movl $0xb, %esi
leaq -0x70(%rbp), %rdx
callq 0x1a4c0
movl %eax, -0x14(%rbp)
cmpl $0xc, -0x14(%rbp)
jne 0x4904e
movl $0x0, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x49056
jmp 0x490d2
jmp 0x49058
leaq -0x68(%rbp), %rdi
xorl %esi, %esi
movl $0x48, %edx
callq 0x8200
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x1, -0x50(%rbp)
leaq -0x68(%rbp), %rdi
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
callq 0xda20
leaq -0x68(%rbp), %rdi
callq 0xf6a0
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x490bf
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movzwl 0x26(%rax), %ecx
andl $-0x3, %ecx
movw %cx, 0x26(%rax)
jmp 0x490d0
movq -0x60(%rbp), %rdi
callq 0x98f0
movq %rax, %rdi
callq 0x49140
jmp 0x490d2
movl -0x14(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop