// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x8(%rdi), %rdx
movq %rax, 0x8(%rdx)
movq (%rsi), %rax
movq 0x8(%rsi), %rcx
movq %rax, 0x8(%rcx)
movq (%rdx), %rax
movq 0x48(%rax), %rdi
movq (%rdi), %rax
testq %rax, %rax
je 0x35a24
movslq 0x30(%rcx), %rdx
movl 0x3c(%rcx), %ecx
imulq %rdx, %rcx
leaq -0x60(%rbp), %rdx
movq %rcx, (%rdx)
movl $0xb, %esi
callq *0x50(%rax)
cmpl $0xc, %eax
je 0x35a24
movl %eax, %r14d
testl %eax, %eax
jne 0x35ab2
xorps %xmm0, %xmm0
leaq -0x60(%rbp), %r14
movaps %xmm0, 0x30(%r14)
movaps %xmm0, 0x20(%r14)
movaps %xmm0, 0x10(%r14)
movaps %xmm0, (%r14)
movq $0x0, 0x40(%r14)
movq (%r15), %rax
movq %rax, 0x20(%r14)
movq %r15, 0x28(%r14)
movq %rbx, 0x8(%r14)
movl $0x1, 0x18(%r14)
movq %r14, %rdi
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
callq 0xcc67
movq %r14, %rdi
callq 0xe6a9
testl %eax, %eax
je 0x35aa6
movl %eax, %r14d
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
cmpb $0x0, 0x12(%rax)
jne 0x35ab2
cmpb $0x0, 0x10(%rax)
jne 0x35ab2
movq 0x70(%rax), %rcx
testq %rcx, %rcx
je 0x35ac0
movl $0x1, 0x18(%rcx)
movq 0x40(%rcx), %rcx
jmp 0x35a94
movq 0x8(%rbx), %rax
andw $-0x3, 0x26(%rax)
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x110(%rax), %rdi
xorl %esi, %esi
callq 0x1cd4d
jmp 0x35ab2