// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: pager_end_transaction
static int pager_end_transaction(Pager *pPager, int hasSuper, 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
      || (sqlite3OsDeviceCharacteristics(pPager->fd)&SQLITE_IOCAP_BATCH_ATOMIC)
  );
  if( isOpen(pPager->jfd) ){
    assert( !pagerUseWal(pPager) );

    /* Finalize the journal file. */
    if( sqlite3JournalIsInMemory(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);
        if( rc==SQLITE_OK && pPager->fullSync ){
          /* Make sure the new file size is written into the inode right away.
          ** Otherwise the journal might resurrect following a power loss and
          ** cause the last transaction to roll back.  See
          ** https://bugzilla.mozilla.org/show_bug.cgi?id=1072773
          */
          rc = sqlite3OsSync(pPager->jfd, pPager->syncFlags);
        }
      }
      pPager->journalOff = 0;
    }else if( pPager->journalMode==PAGER_JOURNALMODE_PERSIST
      || (pPager->exclusiveMode && pPager->journalMode!=PAGER_JOURNALMODE_WAL)
    ){
      rc = zeroJournalHdr(pPager, hasSuper||pPager->tempFile);
      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;
      assert( sqlite3JournalIsInMemory(pPager->jfd)==0 );
      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, pPager->extraSync);
      }
    }
  }

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

  sqlite3BitvecDestroy(pPager->pInJournal);
  pPager->pInJournal = 0;
  pPager->nRec = 0;
  if( rc==SQLITE_OK ){
    if( MEMDB || pagerFlushOnCommit(pPager, bCommit) ){
      sqlite3PcacheCleanAll(pPager->pPCache);
    }else{
      sqlite3PcacheClearWritable(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( rc==SQLITE_OK && bCommit ){
    rc = sqlite3OsFileControl(pPager->fd, SQLITE_FCNTL_COMMIT_PHASETWO, 0);
    if( rc==SQLITE_NOTFOUND ) rc = SQLITE_OK;
  }

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

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

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %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 0x14(%rax), %eax
cmpl $0x2, %eax
jge 0x3e18f6
movq -0x10(%rbp), %rax
movzbl 0x15(%rax), %eax
cmpl $0x2, %eax
jge 0x3e18f6
movl $0x0, -0x4(%rbp)
jmp 0x3e1bda
movq -0x10(%rbp), %rdi
callq 0x3e3c40
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, (%rax)
je 0x3e1a67
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x3e22f0
cmpl $0x0, %eax
je 0x3e1935
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x3dbe40
jmp 0x3e1a65
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x3, %eax
jne 0x3e19a8
movq -0x10(%rbp), %rax
cmpq $0x0, 0x60(%rax)
jne 0x3e1956
movl $0x0, -0x1c(%rbp)
jmp 0x3e1997
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3e01f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x3e1995
movq -0x10(%rbp), %rax
movzbl 0xc(%rax), %eax
cmpl $0x0, %eax
je 0x3e1995
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x10(%rbp), %rax
movzbl 0xe(%rax), %esi
callq 0x3ddf70
movl %eax, -0x1c(%rbp)
jmp 0x3e1997
movq -0x10(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0x3e1a63
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x1, %eax
je 0x3e19cf
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
cmpl $0x0, %eax
je 0x3e1a15
movq -0x10(%rbp), %rax
movzbl 0x9(%rax), %eax
cmpl $0x5, %eax
je 0x3e1a15
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movb $0x1, %al
cmpl $0x0, -0x14(%rbp)
movb %al, -0x25(%rbp)
jne 0x3e19f3
movq -0x10(%rbp), %rax
movzbl 0x10(%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x25(%rbp)
movq -0x30(%rbp), %rdi
movb -0x25(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x3e3cf0
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x60(%rax)
jmp 0x3e1a61
movq -0x10(%rbp), %rax
cmpb $0x0, 0x10(%rax)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x3dbe40
cmpl $0x0, -0x24(%rbp)
je 0x3e1a5f
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0xd8(%rax), %rsi
movq -0x10(%rbp), %rax
movzbl 0xd(%rax), %edx
callq 0x3e3c10
movl %eax, -0x1c(%rbp)
jmp 0x3e1a61
jmp 0x3e1a63
jmp 0x3e1a65
jmp 0x3e1a67
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x3e2290
movq -0x10(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x30(%rax)
cmpl $0x0, -0x1c(%rbp)
jne 0x3e1ae8
movq -0x10(%rbp), %rax
movzbl 0x13(%rax), %eax
cmpl $0x0, %eax
jne 0x3e1aaf
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x3e3df0
cmpl $0x0, %eax
je 0x3e1ac1
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
callq 0x3e3e70
jmp 0x3e1ad1
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
callq 0x3e3ea0
movq -0x10(%rbp), %rax
movq 0x118(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %esi
callq 0x3e3b40
movq -0x10(%rbp), %rax
cmpq $0x0, 0x120(%rax)
je 0x3e1b0b
movq -0x10(%rbp), %rax
movq 0x120(%rax), %rdi
callq 0x3dfe30
movl %eax, -0x20(%rbp)
jmp 0x3e1b3c
cmpl $0x0, -0x1c(%rbp)
jne 0x3e1b3a
cmpl $0x0, -0x18(%rbp)
je 0x3e1b3a
movq -0x10(%rbp), %rax
movl 0x24(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jbe 0x3e1b3a
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %esi
callq 0x3e3730
movl %eax, -0x1c(%rbp)
jmp 0x3e1b3c
cmpl $0x0, -0x1c(%rbp)
jne 0x3e1b70
cmpl $0x0, -0x18(%rbp)
je 0x3e1b70
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movl $0x16, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x3d4130
movl %eax, -0x1c(%rbp)
cmpl $0xc, -0x1c(%rbp)
jne 0x3e1b6e
movl $0x0, -0x1c(%rbp)
jmp 0x3e1b70
movq -0x10(%rbp), %rax
cmpb $0x0, 0x8(%rax)
jne 0x3e1bb0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x120(%rax)
je 0x3e1b9f
movq -0x10(%rbp), %rax
movq 0x120(%rax), %rdi
xorl %esi, %esi
callq 0x3e3ef0
cmpl $0x0, %eax
je 0x3e1bb0
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x3e3fb0
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movb $0x1, 0x14(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x17(%rax)
cmpl $0x0, -0x1c(%rbp)
jne 0x3e1bce
movl -0x20(%rbp), %eax
movl %eax, -0x34(%rbp)
jmp 0x3e1bd4
movl -0x1c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)