// File: /workspace/github_c_makefile_star2_O0/shifengbin[P]bishe/Output/../Persistence/sqlite3.c
// Function: sqlite3WalCheckpoint
SQLITE_PRIVATE int sqlite3WalCheckpoint(
  Wal *pWal,                      /* Wal connection */
  int eMode,                      /* PASSIVE, FULL, RESTART, or TRUNCATE */
  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() */
  int (*xBusy2)(void*) = xBusy;   /* Busy handler for eMode2 */

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

  /* EVIDENCE-OF: R-62920-47450 The busy-handler callback is never invoked
  ** in the SQLITE_CHECKPOINT_PASSIVE mode. */
  assert( eMode!=SQLITE_CHECKPOINT_PASSIVE || xBusy==0 );

  if( pWal->readOnly ) return SQLITE_READONLY;
  WALTRACE(("WAL%p: checkpoint begins\n", pWal));

  /* IMPLEMENTATION-OF: R-62028-47212 All calls obtain an exclusive 
  ** "checkpoint" lock on the database file. */
  rc = walLockExclusive(pWal, WAL_CKPT_LOCK, 1);
  if( rc ){
    /* EVIDENCE-OF: R-10421-19736 If any other process is running a
    ** checkpoint operation at the same time, the lock cannot be obtained and
    ** SQLITE_BUSY is returned.
    ** EVIDENCE-OF: R-53820-33897 Even if there is a busy-handler configured,
    ** it will not be invoked in this case.
    */
    testcase( rc==SQLITE_BUSY );
    testcase( xBusy!=0 );
    return rc;
  }
  pWal->ckptLock = 1;

  /* IMPLEMENTATION-OF: R-59782-36818 The SQLITE_CHECKPOINT_FULL, RESTART and
  ** TRUNCATE modes also obtain the exclusive "writer" lock on the database
  ** file.
  **
  ** EVIDENCE-OF: R-60642-04082 If the writer lock cannot be obtained
  ** immediately, and a busy-handler is configured, it is invoked and the
  ** writer lock retried until either the busy-handler returns 0 or the
  ** lock is successfully obtained.
  */
  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;
      xBusy2 = 0;
      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, xBusy2, 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 $0x50, %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 -0x20(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x42(%rax)
je 0x2c6f6
movl $0x8, -0x4(%rbp)
jmp 0x2c8a1
movq -0x10(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x29170
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x2c71a
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x2c8a1
movq -0x10(%rbp), %rax
movb $0x1, 0x41(%rax)
cmpl $0x0, -0x14(%rbp)
je 0x2c774
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x2c960
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x2c754
movq -0x10(%rbp), %rax
movb $0x1, 0x40(%rax)
jmp 0x2c772
cmpl $0x5, -0x34(%rbp)
jne 0x2c770
movl $0x0, -0x3c(%rbp)
movq $0x0, -0x48(%rbp)
movl $0x0, -0x34(%rbp)
jmp 0x2c772
jmp 0x2c774
cmpl $0x0, -0x34(%rbp)
jne 0x2c7b6
movq -0x10(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x296d0
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x2c7b4
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
cmpl $0x3, (%rax)
jl 0x2c7b4
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, %rsi
callq 0x2c9d0
jmp 0x2c7b6
cmpl $0x0, -0x34(%rbp)
jne 0x2c842
movq -0x10(%rbp), %rax
cmpl $0x0, 0x58(%rax)
je 0x2c7e7
movq -0x10(%rbp), %rdi
callq 0x2ca10
cmpl -0x30(%rbp), %eax
je 0x2c7e7
movl $0xd2b4, %edi           # imm = 0xD2B4
callq 0x2a650
movl %eax, -0x34(%rbp)
jmp 0x2c806
movq -0x10(%rbp), %rdi
movl -0x3c(%rbp), %esi
movq -0x48(%rbp), %rdx
movq -0x28(%rbp), %rcx
movl -0x2c(%rbp), %r8d
movq 0x10(%rbp), %r9
callq 0x2ca40
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
je 0x2c812
cmpl $0x5, -0x34(%rbp)
jne 0x2c840
cmpq $0x0, 0x18(%rbp)
je 0x2c826
movq -0x10(%rbp), %rax
movl 0x58(%rax), %ecx
movq 0x18(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, 0x20(%rbp)
je 0x2c83e
movq -0x10(%rbp), %rdi
callq 0x29150
movl (%rax), %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x2c840
jmp 0x2c842
cmpl $0x0, -0x38(%rbp)
je 0x2c85c
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
xorl %esi, %esi
movl $0x30, %edx
callq 0xb2b0
movq -0x10(%rbp), %rdi
callq 0x2cec0
movq -0x10(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x29290
movq -0x10(%rbp), %rax
movb $0x0, 0x41(%rax)
cmpl $0x0, -0x34(%rbp)
jne 0x2c895
movl -0x14(%rbp), %eax
cmpl -0x3c(%rbp), %eax
je 0x2c895
movl $0x5, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2c89b
movl -0x34(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)