// File: /workspace/github_c_makefile_star2_O1/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), %rcx
movq %rax, 0x8(%rcx)
movq (%rsi), %rdx
movq 0x8(%rsi), %rax
movq %rdx, 0x8(%rax)
movq (%rcx), %rcx
movq 0x48(%rcx), %rdi
cmpq $0x0, (%rdi)
je 0x35321
movslq 0x30(%rax), %rcx
movl 0x3c(%rax), %eax
imulq %rcx, %rax
leaq -0x60(%rbp), %rdx
movq %rax, (%rdx)
movq (%rdi), %rax
movl $0xb, %esi
callq *0x50(%rax)
xorl %r14d, %r14d
cmpl $0xc, %eax
cmovnel %eax, %r14d
testl %r14d, %r14d
jne 0x353af
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 0xcb46
movq %r14, %rdi
callq 0xe5c8
testl %eax, %eax
je 0x353a3
movl %eax, %r14d
movq -0x58(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
cmpb $0x0, 0x12(%rax)
jne 0x353af
cmpb $0x0, 0x10(%rax)
jne 0x353af
movq 0x70(%rax), %rcx
testq %rcx, %rcx
je 0x353bd
movl $0x1, 0x18(%rcx)
movq 0x40(%rcx), %rcx
jmp 0x35391
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 0x1cf10
jmp 0x353af