// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: sqlite3WalCheckpoint
SQLITE_PRIVATE int sqlite3WalCheckpoint(
  Wal *pWal,                      /* Wal connection */
  int eMode,                      /* PASSIVE, FULL or RESTART */
  int (*xBusy)(void*),            /* Function to call when busy */
  void *pBusyArg,                 /* Context argument for xBusyHandler */
  int sync_flags,                 /* Flags to sync db file with (or 0) */
  int nBuf,                       /* Size of temporary buffer */
  u8 *zBuf,                       /* Temporary buffer to use */
  int *pnLog,                     /* OUT: Number of frames in WAL */
  int *pnCkpt                     /* OUT: Number of backfilled frames in WAL */
){
  int rc;                         /* Return code */
  int isChanged = 0;              /* True if a new wal-index header is loaded */
  int eMode2 = eMode;             /* Mode to pass to walCheckpoint() */

  assert( pWal->ckptLock==0 );
  assert( pWal->writeLock==0 );

  if( pWal->readOnly ) return SQLITE_READONLY;
  WALTRACE(("WAL%p: checkpoint begins\n", pWal));
  rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
  if( rc ){
    /* Usually this is SQLITE_BUSY meaning that another thread or process
    ** is already running a checkpoint, or maybe a recovery.  But it might
    ** also be SQLITE_IOERR. */
    return rc;
  }
  pWal->ckptLock = 1;

  /* If this is a blocking-checkpoint, then obtain the write-lock as well
  ** to prevent any writers from running while the checkpoint is underway.
  ** This has to be done before the call to walIndexReadHdr() below.
  **
  ** If the writer lock cannot be obtained, then a passive checkpoint is
  ** run instead. Since the checkpointer is not holding the writer lock,
  ** there is no point in blocking waiting for any readers. Assuming no 
  ** other error occurs, this function will return SQLITE_BUSY to the caller.
  */
  if( eMode!=SQLITE_CHECKPOINT_PASSIVE ){
    rc = walBusyLock(pWal, xBusy, pBusyArg, WAL_WRITE_LOCK, 1);
    if( rc==SQLITE_OK ){
      pWal->writeLock = 1;
    }else if( rc==SQLITE_BUSY ){
      eMode2 = SQLITE_CHECKPOINT_PASSIVE;
      rc = SQLITE_OK;
    }
  }

  /* Read the wal-index header. */
  if( rc==SQLITE_OK ){
    rc = walIndexReadHdr(pWal, &isChanged);
    if( isChanged && pWal->pDbFd->pMethods->iVersion>=3 ){
      sqlite3OsUnfetch(pWal->pDbFd, 0, 0);
    }
  }

  /* Copy data from the log to the database file. */
  if( rc==SQLITE_OK ){
    if( pWal->hdr.mxFrame && walPagesize(pWal)!=nBuf ){
      rc = SQLITE_CORRUPT_BKPT;
    }else{
      rc = walCheckpoint(pWal, eMode2, xBusy, pBusyArg, sync_flags, zBuf);
    }

    /* If no error occurred, set the output variables. */
    if( rc==SQLITE_OK || rc==SQLITE_BUSY ){
      if( pnLog ) *pnLog = (int)pWal->hdr.mxFrame;
      if( pnCkpt ) *pnCkpt = (int)(walCkptInfo(pWal)->nBackfill);
    }
  }

  if( isChanged ){
    /* If a new wal-index header was loaded before the checkpoint was 
    ** performed, then the pager-cache associated with pWal is now
    ** out of date. So zero the cached wal-index header to ensure that
    ** next time the pager opens a snapshot on this database it knows that
    ** the cache needs to be reset.
    */
    memset(&pWal->hdr, 0, sizeof(WalIndexHdr));
  }

  /* Release the locks. */
  sqlite3WalEndWriteTransaction(pWal);
  walUnlockExclusive(pWal, WAL_CKPT_LOCK, 1);
  pWal->ckptLock = 0;
  WALTRACE(("WAL%p: checkpoint %s\n", pWal, rc ? "failed" : "ok"));
  return (rc==SQLITE_OK && eMode!=eMode2 ? SQLITE_BUSY : rc);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movl %r9d, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x42(%rax)
je 0x2579e
movl $0x8, -0x4(%rbp)
jmp 0x25941
movq -0x10(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x23020
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x257c2
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x25941
movq -0x10(%rbp), %rax
movb $0x1, 0x41(%rax)
cmpl $0x0, -0x14(%rbp)
je 0x25814
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x25a00
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x257fc
movq -0x10(%rbp), %rax
movb $0x1, 0x40(%rax)
jmp 0x25812
cmpl $0x5, -0x34(%rbp)
jne 0x25810
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x34(%rbp)
jmp 0x25812
jmp 0x25814
cmpl $0x0, -0x34(%rbp)
jne 0x25856
movq -0x10(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x234a0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x25854
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
cmpl $0x3, (%rax)
jl 0x25854
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x25a70
jmp 0x25856
cmpl $0x0, -0x34(%rbp)
jne 0x258e2
movq -0x10(%rbp), %rax
cmpl $0x0, 0x58(%rax)
je 0x25887
movq -0x10(%rbp), %rdi
callq 0x25ab0
cmpl -0x30(%rbp), %eax
je 0x25887
movl $0xbd6c, %edi           # imm = 0xBD6C
callq 0x24410
movl %eax, -0x34(%rbp)
jmp 0x258a6
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %esi
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x2c(%rbp), %r8d
movq 0x10(%rbp), %r9
callq 0x25ae0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x258b2
cmpl $0x5, -0x34(%rbp)
jne 0x258e0
cmpq $0x0, 0x18(%rbp)
je 0x258c6
movq -0x10(%rbp), %rax
movl 0x58(%rax), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x20(%rbp)
je 0x258de
movq -0x10(%rbp), %rdi
callq 0x23000
movl (%rax), %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x258e0
jmp 0x258e2
cmpl $0x0, -0x38(%rbp)
je 0x258fc
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0x8200
movq -0x10(%rbp), %rdi
callq 0x25f30
movq -0x10(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x23070
movq -0x10(%rbp), %rax
movb $0x0, 0x41(%rax)
cmpl $0x0, -0x34(%rbp)
jne 0x25935
movl -0x14(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0x25935
movl $0x5, %eax
movl %eax, -0x40(%rbp)
jmp 0x2593b
movl -0x34(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)