// File: /workspace/github_c_makefile_star2_O1/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 0x1d072
movq %rcx, %r15
movl %edx, %r12d
movl %esi, %r13d
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
movq (%rdi), %rax
movl $0x4, %esi
callq *0x38(%rax)
testl %eax, %eax
je 0x1d07a
movl %eax, %r14d
xorl %r15d, %r15d
jmp 0x1d0f3
xorl %r14d, %r14d
jmp 0x1d157
cmpb $0x0, 0x3f(%rbx)
jne 0x1d084
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 0x1d321
movl %eax, %r14d
testl %eax, %eax
jne 0x1d0f3
leaq -0x2c(%rbp), %r14
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
movl $0xa, %esi
movq %r14, %rdx
callq *0x50(%rax)
movl $0x1, %r15d
cmpl $0x1, (%r14)
jne 0x1d0f0
cmpq $0x0, 0x20(%rbx)
js 0x1d0ed
xorl %r15d, %r15d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1b9e1
jmp 0x1d0f0
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %rbx, %rdi
movl %r15d, %esi
callq 0x1ddee
movq 0x10(%rbx), %r12
movq (%r12), %rax
testq %rax, %rax
je 0x1d119
movq %r12, %rdi
callq *0x8(%rax)
movq $0x0, (%r12)
testl %r15d, %r15d
je 0x1d146
movq 0x78e3b(%rip), %rax     # 0x95f60
testq %rax, %rax
je 0x1d12c
callq *%rax
movq (%rbx), %rdi
movq 0x78(%rbx), %rsi
xorl %edx, %edx
callq *0x30(%rdi)
movq 0x78e29(%rip), %rax     # 0x95f68
testq %rax, %rax
je 0x1d146
callq *%rax
movq 0x30(%rbx), %rdi
callq 0xa2e8
movq %rbx, %rdi
callq 0xa2e8
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq