// File: /workspace/github_c_makefile_star2_O2/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3WalClose
SQLITE_PRIVATE int sqlite3WalClose(
  Wal *pWal,                      /* Wal to close */
  int sync_flags,                 /* Flags to pass to OsSync() (or 0) */
  int nBuf,
  u8 *zBuf                        /* Buffer of at least nBuf bytes */
){
  int rc = SQLITE_OK;
  if( pWal ){
    int isDelete = 0;             /* True to unlink wal and wal-index files */

    /* If an EXCLUSIVE lock can be obtained on the database file (using the
    ** ordinary, rollback-mode locking methods, this guarantees that the
    ** connection associated with this log file is the only connection to
    ** the database. In this case checkpoint the database and unlink both
    ** the wal and wal-index files.
    **
    ** The EXCLUSIVE lock is not released before returning.
    */
    rc = sqlite3OsLock(pWal->pDbFd, SQLITE_LOCK_EXCLUSIVE);
    if( rc==SQLITE_OK ){
      if( pWal->exclusiveMode==WAL_NORMAL_MODE ){
        pWal->exclusiveMode = WAL_EXCLUSIVE_MODE;
      }
      rc = sqlite3WalCheckpoint(
          pWal, SQLITE_CHECKPOINT_PASSIVE, 0, 0, sync_flags, nBuf, zBuf, 0, 0
      );
      if( rc==SQLITE_OK ){
        int bPersist = -1;
        sqlite3OsFileControlHint(
            pWal->pDbFd, SQLITE_FCNTL_PERSIST_WAL, &bPersist
        );
        if( bPersist!=1 ){
          /* Try to delete the WAL file if the checkpoint completed and
          ** fsyned (rc==SQLITE_OK) and if we are not in persistent-wal
          ** mode (!bPersist) */
          isDelete = 1;
        }else if( pWal->mxWalSize>=0 ){
          /* Try to truncate the WAL file to zero bytes if the checkpoint
          ** completed and fsynced (rc==SQLITE_OK) and we are in persistent
          ** WAL mode (bPersist) and if the PRAGMA journal_size_limit is a
          ** non-negative value (pWal->mxWalSize>=0).  Note that we truncate
          ** to zero bytes as truncating to the journal_size_limit might
          ** leave a corrupt WAL file on disk. */
          walLimitSize(pWal, 0);
        }
      }
    }

    walIndexClose(pWal, isDelete);
    sqlite3OsClose(pWal->pWalFd);
    if( isDelete ){
      sqlite3BeginBenignMalloc();
      sqlite3OsDelete(pWal->pVfs, pWal->zWalName, 0);
      sqlite3EndBenignMalloc();
    }
    WALTRACE(("WAL%p: closed\n", pWal));
    sqlite3_free((void *)pWal->apWiData);
    sqlite3_free(pWal);
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
testq %rdi, %rdi
je 0x1a910
movq %rcx, %r15
movl %edx, %r12d
movl %esi, %r13d
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
movq (%rdi), %rax
pushq $0x4
popq %rsi
callq *0x38(%rax)
testl %eax, %eax
je 0x1a918
movl %eax, %r14d
xorl %r15d, %r15d
jmp 0x1a98c
xorl %r14d, %r14d
jmp 0x1a9ed
cmpb $0x0, 0x3f(%rbx)
jne 0x1a922
movb $0x1, 0x3f(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rsp)
movq %r15, (%rsp)
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl %r13d, %r8d
movl %r12d, %r9d
callq 0x1ab79
movl %eax, %r14d
testl %eax, %eax
jne 0x1a98c
leaq -0x2c(%rbp), %r14
orl $-0x1, (%r14)
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
pushq $0xa
popq %rsi
movq %r14, %rdx
callq *0x50(%rax)
cmpl $0x1, (%r14)
jne 0x1a980
cmpq $0x0, 0x20(%rbx)
js 0x1a986
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x19439
jmp 0x1a989
pushq $0x1
popq %r15
jmp 0x1a989
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1b3ce
movq 0x10(%rbx), %r12
movq (%r12), %rax
testq %rax, %rax
je 0x1a9af
movq %r12, %rdi
callq *0x8(%rax)
andq $0x0, (%r12)
testl %r15d, %r15d
je 0x1a9dc
movq 0x6e5a5(%rip), %rax     # 0x88f60
testq %rax, %rax
je 0x1a9c2
callq *%rax
movq (%rbx), %rdi
movq 0x78(%rbx), %rsi
xorl %edx, %edx
callq *0x30(%rdi)
movq 0x6e593(%rip), %rax     # 0x88f68
testq %rax, %rax
je 0x1a9dc
callq *%rax
movq 0x30(%rbx), %rdi
callq 0x9c7b
movq %rbx, %rdi
callq 0x9c7b
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq