// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: pager_end_transaction
static int pager_end_transaction(Pager *pPager, int hasMaster, int bCommit){
  int rc = SQLITE_OK;      /* Error code from journal finalization operation */
  int rc2 = SQLITE_OK;     /* Error code from db file unlock operation */

  /* Do nothing if the pager does not have an open write transaction
  ** or at least a RESERVED lock. This function may be called when there
  ** is no write-transaction active but a RESERVED or greater lock is
  ** held under two circumstances:
  **
  **   1. After a successful hot-journal rollback, it is called with
  **      eState==PAGER_NONE and eLock==EXCLUSIVE_LOCK.
  **
  **   2. If a connection with locking_mode=exclusive holding an EXCLUSIVE 
  **      lock switches back to locking_mode=normal and then executes a
  **      read-transaction, this function is called with eState==PAGER_READER 
  **      and eLock==EXCLUSIVE_LOCK when the read-transaction is closed.
  */
  assert( assert_pager_state(pPager) );
  assert( pPager->eState!=PAGER_ERROR );
  if( pPager->eState<PAGER_WRITER_LOCKED && pPager->eLock<RESERVED_LOCK ){
    return SQLITE_OK;
  }

  releaseAllSavepoints(pPager);
  assert( isOpen(pPager->jfd) || pPager->pInJournal==0 );
  if( isOpen(pPager->jfd) ){
    assert( !pagerUseWal(pPager) );

    /* Finalize the journal file. */
    if( sqlite3IsMemJournal(pPager->jfd) ){
      assert( pPager->journalMode==PAGER_JOURNALMODE_MEMORY );
      sqlite3OsClose(pPager->jfd);
    }else if( pPager->journalMode==PAGER_JOURNALMODE_TRUNCATE ){
      if( pPager->journalOff==0 ){
        rc = SQLITE_OK;
      }else{
        rc = sqlite3OsTruncate(pPager->jfd, 0);
      }
      pPager->journalOff = 0;
    }else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
      || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
    ){
      rc = zeroJournalHdr(pPager, hasMaster);
      pPager->journalOff = 0;
    }else{
      /* This branch may be executed with Pager.journalMode==MEMORY if
      ** a hot-journal was just rolled back. In this case the journal
      ** file should be closed and deleted. If this connection writes to
      ** the database file, it will do so using an in-memory journal. 
      */
      int bDelete = (!pPager->tempFile && sqlite3JournalExists(pPager->jfd));
      assert( pPager->journalMode==PAGER_JOURNALMODE_DELETE 
           || pPager->journalMode==PAGER_JOURNALMODE_MEMORY 
           || pPager->journalMode==PAGER_JOURNALMODE_WAL 
      );
      sqlite3OsClose(pPager->jfd);
      if( bDelete ){
        rc = sqlite3OsDelete(pPager->pVfs, pPager->zJournal, 0);
      }
    }
  }

#ifdef SQLITE_CHECK_PAGES
  sqlite3PcacheIterateDirty(pPager->pPCache, pager_set_pagehash);
  if( pPager->dbSize==0 && sqlite3PcacheRefCount(pPager->pPCache)>0 ){
    PgHdr *p = pager_lookup(pPager, 1);
    if( p ){
      p->pageHash = 0;
      sqlite3PagerUnref(p);
    }
  }
#endif

  sqlite3BitvecDestroy(pPager->pInJournal);
  pPager->pInJournal = 0;
  pPager->nRec = 0;
  sqlite3PcacheCleanAll(pPager->pPCache);
  sqlite3PcacheTruncate(pPager->pPCache, pPager->dbSize);

  if( pagerUseWal(pPager) ){
    /* Drop the WAL write-lock, if any. Also, if the connection was in 
    ** locking_mode=exclusive mode but is no longer, drop the EXCLUSIVE 
    ** lock held on the database file.
    */
    rc2 = sqlite3WalEndWriteTransaction(pPager->pWal);
    assert( rc2==SQLITE_OK );
  }else if( rc==SQLITE_OK && bCommit && pPager->dbFileSize>pPager->dbSize ){
    /* This branch is taken when committing a transaction in rollback-journal
    ** mode if the database file on disk is larger than the database image.
    ** At this point the journal has been finalized and the transaction 
    ** successfully committed, but the EXCLUSIVE lock is still held on the
    ** file. So it is safe to truncate the database file to its minimum
    ** required size.  */
    assert( pPager->eLock==EXCLUSIVE_LOCK );
    rc = pager_truncate(pPager, pPager->dbSize);
  }

  if( !pPager->exclusiveMode 
   && (!pagerUseWal(pPager) || sqlite3WalExclusiveMode(pPager->pWal, 0))
  ){
    rc2 = pagerUnlockDb(pPager, SHARED_LOCK);
    pPager->changeCountDone = 0;
  }
  pPager->eState = PAGER_READER;
  pPager->setMaster = 0;

  return (rc==SQLITE_OK?rc2:rc);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzbl 0x13(%rax), %eax
cmpl $0x2, %eax
jge 0x269a6
movq -0x10(%rbp), %rax
movzbl 0x14(%rax), %eax
cmpl $0x2, %eax
jge 0x269a6
movl $0x0, -0x4(%rbp)
jmp 0x26bd8
movq -0x10(%rbp), %rdi
callq 0x26690
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, (%rax)
je 0x26ac7
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x267f0
cmpl $0x0, %eax
je 0x269e5
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x20ea0
jmp 0x26ac5
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x3, %eax
jne 0x26a2b
movq -0x10(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x26a06
movl $0x0, -0x1c(%rbp)
jmp 0x26a1a
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x241d0
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0x26ac3
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x1, %eax
je 0x26a52
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
je 0x26a6f
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x5, %eax
je 0x26a6f
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x28f30
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0x26ac1
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpb $0x0, 0x10(%rcx)
movb %al, -0x25(%rbp)
jne 0x26a85
movb $0x1, %al
movb %al, -0x25(%rbp)
jmp 0x26a85
movb -0x25(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x20ea0
cmpl $0x0, -0x24(%rbp)
je 0x26abf
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rsi
xorl %edx, %edx
callq 0x259d0
movl %eax, -0x1c(%rbp)
jmp 0x26ac1
jmp 0x26ac3
jmp 0x26ac5
jmp 0x26ac7
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x26630
movq -0x10(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x110(%rax), %rdi
callq 0x29030
movq -0x10(%rbp), %rax
movq 0x110(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %esi
callq 0x251a0
movq -0x10(%rbp), %rdi
callq 0x211a0
cmpl $0x0, %eax
je 0x26b35
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
callq 0x25f30
movl %eax, -0x20(%rbp)
jmp 0x26b66
cmpl $0x0, -0x1c(%rbp)
jne 0x26b64
cmpl $0x0, -0x18(%rbp)
je 0x26b64
movq -0x10(%rbp), %rax
movl 0x24(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jbe 0x26b64
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %esi
callq 0x28bb0
movl %eax, -0x1c(%rbp)
jmp 0x26b66
movq -0x10(%rbp), %rax
cmpb $0x0, 0x8(%rax)
jne 0x26bae
movq -0x10(%rbp), %rdi
callq 0x211a0
cmpl $0x0, %eax
je 0x26b95
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
xorl %esi, %esi
callq 0x29060
cmpl $0x0, %eax
je 0x26bae
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x26790
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movb $0x0, 0x15(%rax)
movq -0x10(%rbp), %rax
movb $0x1, 0x13(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x16(%rax)
cmpl $0x0, -0x1c(%rbp)
jne 0x26bcc
movl -0x20(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x26bd2
movl -0x1c(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)