// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3_backup_finish
SQLITE_API int sqlite3_backup_finish(sqlite3_backup *p){
  sqlite3_backup **pp;                 /* Ptr to head of pagers backup list */
  sqlite3 *pSrcDb;                     /* Source database connection */
  int rc;                              /* Value to return */

  /* Enter the mutexes */
  if( p==0 ) return SQLITE_OK;
  pSrcDb = p->pSrcDb;
  sqlite3_mutex_enter(pSrcDb->mutex);
  sqlite3BtreeEnter(p->pSrc);
  if( p->pDestDb ){
    sqlite3_mutex_enter(p->pDestDb->mutex);
  }

  /* Detach this backup from the source pager. */
  if( p->pDestDb ){
    p->pSrc->nBackup--;
  }
  if( p->isAttached ){
    pp = sqlite3PagerBackupPtr(sqlite3BtreePager(p->pSrc));
    while( *pp!=p ){
      pp = &(*pp)->pNext;
    }
    *pp = p->pNext;
  }

  /* If a transaction is still open on the Btree, roll it back. */
  sqlite3BtreeRollback(p->pDest, SQLITE_OK);

  /* Set the error code of the destination database handle. */
  rc = (p->rc==SQLITE_DONE) ? SQLITE_OK : p->rc;
  sqlite3Error(p->pDestDb, rc, 0);

  /* Exit the mutexes and free the backup context structure. */
  if( p->pDestDb ){
    sqlite3LeaveMutexAndCloseZombie(p->pDestDb);
  }
  sqlite3BtreeLeave(p->pSrc);
  if( p->pDestDb ){
    /* EVIDENCE-OF: R-64852-21591 The sqlite3_backup object is created by a
    ** call to sqlite3_backup_init() and is destroyed by a call to
    ** sqlite3_backup_finish(). */
    sqlite3_free(p);
  }
  sqlite3LeaveMutexAndCloseZombie(pSrcDb);
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xf6bf
movl $0x0, -0x4(%rbp)
jmp 0xf7cc
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0xe0f0
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0xf6e4
jmp 0xf6e4
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0xf6ff
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x18(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x3c(%rax)
je 0xf74f
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x98f0
movq %rax, %rdi
callq 0xf7e0
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpq -0x10(%rbp), %rax
je 0xf740
movq -0x18(%rbp), %rax
movq (%rax), %rax
addq $0x40, %rax
movq %rax, -0x18(%rbp)
jmp 0xf722
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
callq 0xf800
movq -0x10(%rbp), %rax
cmpl $0x65, 0x30(%rax)
jne 0xf76f
xorl %eax, %eax
movl %eax, -0x28(%rbp)
jmp 0xf779
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movl -0x24(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
movb $0x0, %al
callq 0xd720
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0xf7aa
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0xf900
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0xf7bd
movq -0x10(%rbp), %rdi
callq 0xa420
movq -0x20(%rbp), %rdi
callq 0xf900
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)