// File: /workspace/github_c_makefile_star2_O0/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
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x254ad
movl $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x4, %esi
callq 0x24860
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x25458
movq -0x8(%rbp), %rax
movzbl 0x3f(%rax), %eax
cmpl $0x0, %eax
jne 0x253d3
movq -0x8(%rbp), %rax
movb $0x1, 0x3f(%rax)
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %r8d
movl -0x10(%rbp), %r9d
movq -0x18(%rbp), %rax
xorl %esi, %esi
xorl %ecx, %ecx
movq %rcx, %rdx
movq %rax, (%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x25750
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x25456
movl $0xffffffff, -0x24(%rbp) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0xa, %esi
leaq -0x24(%rbp), %rdx
callq 0x24890
cmpl $0x1, -0x24(%rbp)
je 0x2543a
movl $0x1, -0x20(%rbp)
jmp 0x25454
movq -0x8(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jl 0x25452
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x22db0
jmp 0x25454
jmp 0x25456
jmp 0x25458
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
callq 0x25950
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x20ea0
cmpl $0x0, -0x20(%rbp)
je 0x25497
callq 0x241b0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x78(%rax), %rsi
xorl %edx, %edx
callq 0x259d0
callq 0x24200
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0xa420
movq -0x8(%rbp), %rdi
callq 0xa420
movl -0x1c(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)