// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %edx, %ebp
movl %esi, %r15d
movq %rdi, %rbx
cmpb $0x1, 0x14(%rdi)
ja 0x233121
xorl %r12d, %r12d
cmpb $0x2, 0x15(%rbx)
jb 0x233363
movq %rbx, %rdi
callq 0x234822
movq 0x50(%rbx), %r12
movq (%r12), %rax
xorl %r14d, %r14d
testq %rax, %rax
je 0x2332a0
leaq 0x2029bc(%rip), %rcx    # 0x435b00
cmpq %rcx, %rax
je 0x23319c
movzbl 0x9(%rbx), %ecx
cmpl $0x1, %ecx
je 0x2331b9
cmpl $0x3, %ecx
jne 0x2331ae
cmpq $0x0, 0x60(%rbx)
je 0x2331ec
movq %r12, %rdi
xorl %esi, %esi
callq *0x20(%rax)
movl %eax, %r14d
testl %eax, %eax
jne 0x23329b
cmpb $0x0, 0xc(%rbx)
je 0x2331ec
movzbl 0xe(%rbx), %esi
movl $0x0, %r14d
testl %esi, %esi
je 0x23329b
movq 0x50(%rbx), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
jmp 0x233298
movq %r12, %rdi
callq 0x230ff0
andq $0x0, (%r12)
jmp 0x2332a0
cmpb $0x5, %cl
je 0x2331f4
cmpb $0x0, 0x8(%rbx)
je 0x2331f4
movb $0x1, %cl
testl %r15d, %r15d
jne 0x2331c7
cmpb $0x0, 0x10(%rbx)
setne %cl
cmpq $0x0, 0x60(%rbx)
je 0x2331ec
movq 0xc8(%rbx), %r15
testq %r15, %r15
sete %dl
orb %dl, %cl
cmpb $0x1, %cl
jne 0x233222
movq %r12, %rdi
xorl %esi, %esi
callq *0x20(%rax)
jmp 0x233234
xorl %r14d, %r14d
jmp 0x23329b
movb 0x10(%rbx), %r15b
movq %r12, %rdi
callq *0x8(%rax)
andq $0x0, (%r12)
testb %r15b, %r15b
jne 0x2332a0
movq (%rbx), %rdi
movq 0xd8(%rbx), %rsi
movzbl 0xd(%rbx), %edx
callq *0x30(%rdi)
movl %eax, %r14d
jmp 0x2332a0
leaq 0x13ecd7(%rip), %rsi    # 0x371f00
pushq $0x1c
popq %rdx
movq %r12, %rdi
xorl %ecx, %ecx
callq *0x18(%rax)
movl %eax, %r14d
testl %eax, %eax
jne 0x23329b
xorl %r14d, %r14d
cmpb $0x0, 0xb(%rbx)
jne 0x233258
movq 0x50(%rbx), %rdi
movzbl 0xe(%rbx), %esi
orl $0x10, %esi
movq (%rdi), %rax
callq *0x28(%rax)
movl %eax, %r14d
testl %r14d, %r14d
sete %al
testq %r15, %r15
setg %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x23329b
movq 0x50(%rbx), %rdi
movq (%rdi), %rax
leaq 0x8(%rsp), %rsi
callq *0x30(%rax)
movl %eax, %r14d
testl %eax, %eax
jne 0x23329b
xorl %r14d, %r14d
cmpq %r15, 0x8(%rsp)
jle 0x23329b
movq 0x50(%rbx), %rdi
movq (%rdi), %rax
movq %r15, %rsi
callq *0x20(%rax)
movl %eax, %r14d
andq $0x0, 0x60(%rbx)
movq 0x40(%rbx), %rdi
callq 0x233e95
andq $0x0, 0x40(%rbx)
andl $0x0, 0x30(%rbx)
testl %r14d, %r14d
jne 0x2332ea
cmpb $0x0, 0x13(%rbx)
jne 0x2332cf
movq %rbx, %rdi
movl %ebp, %esi
callq 0x23489f
testl %eax, %eax
je 0x23339f
movq 0x118(%rbx), %rdi
callq 0x2348fb
movq 0x118(%rbx), %rdi
movl 0x1c(%rbx), %esi
callq 0x2347a6
movq 0x120(%rbx), %rdi
testq %rdi, %rdi
je 0x233373
callq 0x2324cf
testl %ebp, %ebp
je 0x233323
testl %r14d, %r14d
jne 0x233323
movq 0x48(%rbx), %rdi
movq (%rdi), %rax
testq %rax, %rax
je 0x233320
pushq $0x16
popq %rsi
xorl %edx, %edx
callq *0x50(%rax)
movl %eax, %r14d
cmpl $0xc, %eax
jne 0x233323
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpb $0x0, 0x8(%rbx)
jne 0x233354
movq 0x120(%rbx), %rdi
testq %rdi, %rdi
je 0x233346
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x234910
testl %eax, %eax
je 0x233354
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x234962
movl %eax, %r12d
movb $0x1, 0x14(%rbx)
movb $0x0, 0x17(%rbx)
testl %r14d, %r14d
cmovnel %r14d, %r12d
movl %r12d, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
testl %ebp, %ebp
je 0x2332fb
testl %r14d, %r14d
jne 0x2332fb
movl 0x1c(%rbx), %esi
xorl %r14d, %r14d
cmpl %esi, 0x24(%rbx)
jbe 0x2332fb
movq %rbx, %rdi
callq 0x2346d6
movl %eax, %r14d
jmp 0x2332fb
movq 0x118(%rbx), %rdi
movq %rdi, %rax
movq (%rax), %rax
testq %rax, %rax
je 0x2333bb
andb $-0xd, 0x34(%rax)
addq $0x38, %rax
jmp 0x2333a9
movq 0x8(%rdi), %rax
movq %rax, 0x10(%rdi)
jmp 0x2332e2