// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/sqlite3.c
// Function: sqlite3PagerClose
SQLITE_PRIVATE int sqlite3PagerClose(Pager *pPager, sqlite3 *db){
  u8 *pTmp = (u8*)pPager->pTmpSpace;
  assert( db || pagerUseWal(pPager)==0 );
  assert( assert_pager_state(pPager) );
  disable_simulated_io_errors();
  sqlite3BeginBenignMalloc();
  pagerFreeMapHdrs(pPager);
  /* pPager->errCode = 0; */
  pPager->exclusiveMode = 0;
#ifndef SQLITE_OMIT_WAL
  {
    u8 *a = 0;
    assert( db || pPager->pWal==0 );
    if( db && 0==(db->flags & SQLITE_NoCkptOnClose)
     && SQLITE_OK==databaseIsUnmoved(pPager)
    ){
      a = pTmp;
    }
    sqlite3WalClose(pPager->pWal, db, pPager->walSyncFlags, pPager->pageSize,a);
    pPager->pWal = 0;
  }
#endif
  pager_reset(pPager);
  if( MEMDB ){
    pager_unlock(pPager);
  }else{
    /* If it is open, sync the journal file before calling UnlockAndRollback.
    ** If this is not done, then an unsynced portion of the open journal
    ** file may be played back into the database. If a power failure occurs
    ** while this is happening, the database could become corrupt.
    **
    ** If an error occurs while trying to sync the journal, shift the pager
    ** into the ERROR state. This causes UnlockAndRollback to unlock the
    ** database and close the journal file without attempting to roll it
    ** back or finalize it. The next database user will have to do hot-journal
    ** rollback before accessing the database file.
    */
    if( isOpen(pPager->jfd) ){
      pager_error(pPager, pagerSyncHotJournal(pPager));
    }
    pagerUnlockAndRollback(pPager);
  }
  sqlite3EndBenignMalloc();
  enable_simulated_io_errors();
  PAGERTRACE(("CLOSE %d\n", PAGERID(pPager)));
  IOTRACE(("CLOSE %p\n", pPager))
  sqlite3OsClose(pPager->jfd);
  sqlite3OsClose(pPager->fd);
  sqlite3PageFree(pTmp);
  sqlite3PcacheClose(pPager->pPCache);
  assert( !pPager->aSavepoint && !pPager->pInJournal );
  assert( !isOpen(pPager->jfd) && !isOpen(pPager->sjfd) );

  sqlite3_free(pPager);
  return SQLITE_OK;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
movq 0x110(%rdi), %r14
movq 0x20e055(%rip), %rax    # 0x43ddf8
testq %rax, %rax
je 0x22fdaa
callq *%rax
movq 0xa8(%rbx), %rdi
testq %rdi, %rdi
je 0x22fdc4
movq 0x20(%rdi), %r12
callq 0x21f7f9
movq %r12, %rdi
jmp 0x22fdb1
movb $0x0, 0x8(%rbx)
testq %r15, %r15
je 0x22fde7
testb $0x8, 0x31(%r15)
jne 0x22fde7
movq %rbx, %rdi
callq 0x235091
xorl %r8d, %r8d
testl %eax, %eax
cmoveq %r14, %r8
jmp 0x22fdea
xorl %r8d, %r8d
movq 0x120(%rbx), %rdi
movzbl 0xf(%rbx), %edx
movl 0xbc(%rbx), %ecx
movq %r15, %rsi
callq 0x2350e1
andq $0x0, 0x120(%rbx)
movq %rbx, %rdi
callq 0x234787
cmpb $0x0, 0x13(%rbx)
je 0x22fe23
movq %rbx, %rdi
callq 0x2333c8
jmp 0x22fe47
movq 0x50(%rbx), %rax
cmpq $0x0, (%rax)
je 0x22fe3f
movq %rbx, %rdi
callq 0x23521c
movq %rbx, %rdi
movl %eax, %esi
callq 0x230bcb
movq %rbx, %rdi
callq 0x232ff5
movq 0x20dfb2(%rip), %rax    # 0x43de00
testq %rax, %rax
je 0x22fe55
callq *%rax
movq 0x50(%rbx), %r15
movq (%r15), %rax
testq %rax, %rax
je 0x22fe6b
movq %r15, %rdi
callq *0x8(%rax)
andq $0x0, (%r15)
movq 0x48(%rbx), %r15
movq (%r15), %rax
testq %rax, %rax
je 0x22fe81
movq %r15, %rdi
callq *0x8(%rax)
andq $0x0, (%r15)
movq %r14, %rdi
callq 0x232a10
movq 0x118(%rbx), %rax
movq 0x40(%rax), %rdi
callq *0x20a876(%rip)         # 0x43a710
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x21f7f9