// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x110(%rax), %rax
movq %rax, -0x18(%rbp)
callq 0x3e01d0
movq -0x8(%rbp), %rdi
callq 0x3e5150
movq -0x8(%rbp), %rax
movb $0x0, 0x8(%rax)
movq $0x0, -0x20(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3db993
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
andq $0x800, %rcx            # imm = 0x800
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x3db993
movq -0x8(%rbp), %rdi
callq 0x3e51a0
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x3db993
movq -0x18(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x120(%rax), %rdi
movq -0x10(%rbp), %rsi
movq -0x8(%rbp), %rax
movzbl 0xf(%rax), %edx
movq -0x8(%rbp), %rax
movl 0xbc(%rax), %ecx
movq -0x20(%rbp), %r8
callq 0x3e5230
movq -0x8(%rbp), %rax
movq $0x0, 0x120(%rax)
movq -0x8(%rbp), %rdi
callq 0x3e3850
movq -0x8(%rbp), %rax
cmpb $0x0, 0x13(%rax)
je 0x3db9ea
movq -0x8(%rbp), %rdi
callq 0x3e1bf0
jmp 0x3dba1d
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rax
cmpq $0x0, (%rax)
je 0x3dba14
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
callq 0x3e53a0
movq -0x28(%rbp), %rdi
movl %eax, %esi
callq 0x3dc6f0
movq -0x8(%rbp), %rdi
callq 0x3e1700
callq 0x3e0220
movq -0x8(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0x3dbe40
movq -0x8(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x3dbe40
movq -0x18(%rbp), %rdi
callq 0x3dbe80
movq -0x8(%rbp), %rax
movq 0x118(%rax), %rdi
callq 0x3e5400
movq -0x8(%rbp), %rdi
callq 0x3c0800
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)