// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
andl $0x0, -0x94(%rbp)
cmpb $0x0, 0x42(%rdi)
je 0x1fc4b
pushq $0x8
popq %r14
jmp 0x200de
movl %r9d, %ebx
movq %rcx, %r13
movl %esi, %r15d
movq %rdi, %r12
movl %r8d, -0x5c(%rbp)
movq %rdx, -0x78(%rbp)
pushq $0x1
popq %rdx
movl %edx, %esi
callq 0x1df73
movl %eax, %r14d
testl %eax, %eax
jne 0x200de
movq %r13, -0xa0(%rbp)
movb $0x1, 0x41(%r12)
xorl %r13d, %r13d
testl %r15d, %r15d
je 0x1fcbe
pushq $0x1
popq %r8
movq %r12, %rdi
movq -0x78(%rbp), %rsi
movq -0xa0(%rbp), %rdx
xorl %ecx, %ecx
callq 0x2050a
cmpl $0x5, %eax
je 0x1fcb6
testl %eax, %eax
jne 0x1fcf5
movb $0x1, 0x40(%r12)
movl %r15d, %r13d
jmp 0x1fcbe
movq $0x0, -0x78(%rbp)
leaq -0x94(%rbp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x1e2e7
cmpl $0x0, (%r14)
je 0x1fcf8
movq 0x8(%r12), %rdi
movq (%rdi), %rcx
cmpl $0x3, (%rcx)
jl 0x1fcf8
xorl %esi, %esi
xorl %edx, %edx
movl %eax, %r14d
callq *0x90(%rcx)
movl %r14d, %eax
jmp 0x1fcf8
movl %r15d, %r13d
pushq $0x5
popq %r14
testl %eax, %eax
jne 0x20096
movl 0x58(%r12), %edx
movzwl 0x56(%r12), %eax
movl %eax, %ecx
shll $0x10, %ecx
orl %eax, %ecx
andl $0x1fe00, %ecx          # imm = 0x1FE00
movq %rdx, -0xa8(%rbp)
testl %edx, %edx
je 0x1fd3d
cmpl %ebx, %ecx
je 0x1fd3d
movl $0xd2b4, %edi           # imm = 0xD2B4
callq 0x1ec07
pushq $0xb
popq %rax
jmp 0x20096
movq 0x30(%r12), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movl 0x60(%rax), %eax
movq -0xa8(%rbp), %rdx
cmpl %edx, %eax
jae 0x20002
movl %ecx, -0x3c(%rbp)
leal 0x1000(%rdx), %eax
movabsq $0xffffffff021, %rbx    # imm = 0xFFFFFFFF021
addq %rax, %rbx
shrq $0xc, %rbx
movl %ebx, %eax
shll $0x5, %eax
leal (%rax,%rdx,2), %eax
addl $0x28, %eax
movslq %eax, %rdi
movq %rdi, -0x38(%rbp)
callq 0xa230
testq %rax, %rax
je 0x200f3
movq %rax, %r14
movq %r13, -0x90(%rbp)
movl %r15d, -0x54(%rbp)
leal 0x1(%rbx), %r15d
movq %rax, %rdi
xorl %esi, %esi
movq -0x38(%rbp), %rdx
callq 0xa270
movl %r15d, 0x4(%r14)
movl $0x1000, %edi           # imm = 0x1000
movq -0xa8(%rbp), %rax
cmpl %edi, %eax
cmovbl %eax, %edi
addl %edi, %edi
callq 0xa230
movq %rax, %r13
testq %rax, %rax
pushq $0x7
popq %rcx
movl $0x0, %eax
cmovnel %eax, %ecx
movq %r14, -0x48(%rbp)
addq $0x8, %r14
movslq %ebx, %rax
movq %r14, %rbx
xorl %r14d, %r14d
movq %rax, -0xb0(%rbp)
movl %eax, %eax
movq %rax, -0xc8(%rbp)
leaq -0x40(%rbp), %r15
movq %r12, -0x30(%rbp)
movq %rbx, -0x70(%rbp)
testl %ecx, %ecx
jne 0x2002c
cmpq -0xb0(%rbp), %r14
jg 0x2002c
movq %r12, %rdi
movl %r14d, %esi
leaq -0xd8(%rbp), %rdx
leaq -0xc0(%rbp), %rcx
leaq -0x60(%rbp), %r8
callq 0x1eaf7
movl %eax, %ecx
testl %eax, %eax
jne 0x1fffa
movq %r14, %rax
movq -0xc0(%rbp), %r14
addq $0x4, %r14
movq %r14, -0xc0(%rbp)
movq %rax, -0xd0(%rbp)
cmpq -0xc8(%rbp), %rax
movl %ecx, -0x58(%rbp)
jne 0x1fe83
movl -0x60(%rbp), %esi
movq -0xa8(%rbp), %rax
movl %eax, %edx
subl %esi, %edx
jmp 0x1fe94
movq -0xd8(%rbp), %rdx
subq %r14, %rdx
shrq $0x2, %rdx
movl -0x60(%rbp), %esi
movq -0x48(%rbp), %rax
movslq 0x4(%rax), %rax
shlq $0x5, %rax
addq %rbx, %rax
movl %esi, %ecx
leaq (%rax,%rcx,2), %rax
movq %rax, -0x88(%rbp)
incl %esi
movl %esi, -0x60(%rbp)
testl %edx, %edx
movl $0x0, %eax
cmovgl %edx, %eax
movq %rax, -0x38(%rbp)
xorl %eax, %eax
cmpq %rax, -0x38(%rbp)
je 0x1fedb
movq -0x88(%rbp), %rcx
movw %ax, (%rcx,%rax,2)
incq %rax
jmp 0x1fec5
movl %esi, -0xb4(%rbp)
movq %rdx, -0x80(%rbp)
andl $0x0, -0x40(%rbp)
andq $0x0, -0x50(%rbp)
xorl %r12d, %r12d
movl $0xd0, %edx
leaq -0x1b0(%rbp), %rdi
xorl %esi, %esi
callq 0xa270
xorl %ebx, %ebx
cmpq -0x38(%rbp), %r12
je 0x1ff74
movl $0x1, -0x40(%rbp)
movq -0x88(%rbp), %rax
leaq (%rax,%r12,2), %rax
movq %rax, -0x50(%rbp)
xorl %ebx, %ebx
btl %ebx, %r12d
movl %ebx, %eax
jae 0x1ff55
shlq $0x4, %rax
movq -0x1a8(%rbp,%rax), %rsi
movl -0x1b0(%rbp,%rax), %edx
movq %r14, %rdi
leaq -0x50(%rbp), %rcx
movq %r15, %r8
movq %r13, %r9
callq 0x20584
incl %ebx
jmp 0x1ff24
movq -0x50(%rbp), %rcx
shlq $0x4, %rax
movq %rcx, -0x1a8(%rbp,%rax)
movl -0x40(%rbp), %ecx
movl %ecx, -0x1b0(%rbp,%rax)
incq %r12
jmp 0x1ff06
incl %ebx
movq %rbx, %r12
shlq $0x4, %r12
leaq -0x1a8(%rbp), %rax
addq %rax, %r12
movq -0x80(%rbp), %rax
cmpl $0xc, %ebx
ja 0x1ffbc
btl %ebx, %eax
jae 0x1ffb4
movq (%r12), %rsi
movl -0x8(%r12), %edx
movq %r14, %rdi
leaq -0x50(%rbp), %rcx
movq %r15, %r8
movq %r13, %r9
callq 0x20584
movq -0x80(%rbp), %rax
addq $0x10, %r12
incl %ebx
jmp 0x1ff8b
movl -0x40(%rbp), %eax
movq -0xd0(%rbp), %rdx
movq %rdx, %rcx
shlq $0x5, %rcx
movq -0x70(%rbp), %rbx
movl -0xb4(%rbp), %esi
movl %esi, 0x1c(%rbx,%rcx)
movl %eax, 0x18(%rbx,%rcx)
movq -0x88(%rbp), %rax
movq %rax, 0x8(%rbx,%rcx)
movq %r14, 0x10(%rbx,%rcx)
movq %rdx, %r14
movq -0x30(%rbp), %r12
movl -0x58(%rbp), %ecx
incq %r14
jmp 0x1fe0f
movq $0x0, -0x48(%rbp)
xorl %ecx, %ecx
testl %r13d, %r13d
je 0x20058
testl %ecx, %ecx
jne 0x20058
movq -0x68(%rbp), %rax
movl 0x60(%rax), %eax
cmpl 0x58(%r12), %eax
jae 0x200fa
movl %r14d, %ebx
jmp 0x2005a
movq %r13, %rdi
movl %ecx, %ebx
callq 0xa828
testl %ebx, %ebx
pushq $0x5
popq %r14
je 0x2016c
movq -0x48(%rbp), %rdi
callq 0xa828
movl -0x54(%rbp), %r15d
movq -0x90(%rbp), %r13
jmp 0x20063
movl %ecx, %ebx
movq -0x48(%rbp), %rdi
callq 0xa828
cmpl $0x5, %ebx
je 0x2006e
movl %ebx, %eax
testl %ebx, %ebx
jne 0x20096
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rcx
testq %rcx, %rcx
je 0x20082
movl 0x58(%r12), %edx
movl %edx, (%rcx)
testq %rax, %rax
je 0x20094
movq 0x30(%r12), %rcx
movq (%rcx), %rcx
movl 0x60(%rcx), %ecx
movl %ecx, (%rax)
movl %ebx, %eax
movl %eax, %ebx
cmpl $0x0, -0x94(%rbp)
je 0x200b6
xorps %xmm0, %xmm0
movups %xmm0, 0x68(%r12)
movups %xmm0, 0x58(%r12)
movups %xmm0, 0x48(%r12)
movq %r12, %rdi
callq 0x2055a
pushq $0x1
popq %rdx
movq %r12, %rdi
movl %edx, %esi
callq 0x1e012
testl %ebx, %ebx
cmovnel %ebx, %r14d
movb $0x0, 0x41(%r12)
cmpl %r15d, %r13d
cmovel %ebx, %r14d
movl %r14d, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x7
jmp 0x1fd37
cmpl $0x2, %r13d
jl 0x2029a
pushq $0x4
popq %rbx
leaq -0x1b0(%rbp), %rsi
movl %ebx, %edi
callq 0xa420
movq %r12, %rdi
movq -0x78(%rbp), %rsi
movq -0xa0(%rbp), %rdx
movl %ebx, %ecx
movl %ebx, %r8d
callq 0x2050a
testl %eax, %eax
jne 0x20165
xorl %eax, %eax
cmpl $0x3, %r13d
jne 0x20154
movl -0x1b0(%rbp), %esi
movq %r12, %rdi
callq 0x1df94
movq 0x10(%r12), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x20(%rax)
pushq $0x4
popq %rdx
movq %r12, %rdi
movl %edx, %esi
movl %eax, %ebx
callq 0x1e012
movl %ebx, %eax
movl %eax, %ebx
jmp 0x2005a
movl 0x58(%r12), %r15d
movl 0x5c(%r12), %eax
movq %rax, -0x88(%rbp)
xorl %r12d, %r12d
xorl %ecx, %ecx
movq -0x90(%rbp), %r13
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rbx
cmpq $0x4, %r12
je 0x2022e
movq -0x68(%rbp), %rax
movl 0x68(%rax,%r12,4), %r13d
cmpl %r13d, %r15d
jbe 0x2020d
leaq 0x4(%r12), %r14
movq -0x30(%rbp), %rdi
movq %rsi, %rbx
movq -0xa0(%rbp), %rdx
movl %r14d, %ecx
pushq $0x1
popq %r8
callq 0x2050a
movl %eax, %ecx
cmpl $0x5, %eax
je 0x20212
testl %ecx, %ecx
jne 0x202a1
movq %r12, %rax
negq %rax
movl $0x0, %eax
sbbl %eax, %eax
orl %r15d, %eax
movq -0x68(%rbp), %rcx
movl %eax, 0x68(%rcx,%r12,4)
movq -0x30(%rbp), %rdi
movl %r14d, %esi
pushq $0x1
popq %rdx
callq 0x1e012
xorl %ecx, %ecx
movl %r15d, %r13d
pushq $0x5
popq %r14
movq %rbx, %rsi
jmp 0x20218
movl %r15d, %r13d
jmp 0x2021c
xorl %esi, %esi
pushq $0x5
popq %r14
movq -0x70(%rbp), %rbx
incq %r12
movl %r13d, %r15d
movq -0x90(%rbp), %r13
jmp 0x20191
movq %rsi, -0x78(%rbp)
movq -0x68(%rbp), %rax
movl 0x60(%rax), %eax
cmpl %r15d, %eax
movq -0x30(%rbp), %r12
jae 0x204a9
pushq $0x3
popq %rcx
pushq $0x1
popq %r8
movq %r12, %rdi
movq -0x78(%rbp), %rsi
movq -0xa0(%rbp), %rdx
callq 0x2050a
movl %eax, %ecx
testl %eax, %eax
jne 0x204a9
movq -0x68(%rbp), %rax
movl 0x60(%rax), %r13d
movl %r15d, 0x80(%rax)
movl -0x3c(%rbp), %eax
movq %rax, -0x80(%rbp)
movl -0x5c(%rbp), %esi
testl %esi, %esi
je 0x202bb
movq 0x10(%r12), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
testl %eax, %eax
je 0x202bb
movl %eax, %ecx
jmp 0x2030a
xorl %ebx, %ebx
jmp 0x2005a
movl %ecx, %ebx
movl -0x54(%rbp), %r15d
movq -0x30(%rbp), %r12
movq -0x90(%rbp), %r13
pushq $0x5
popq %r14
jmp 0x2005a
movq -0x88(%rbp), %rax
imulq -0x80(%rbp), %rax
movq %rax, -0x50(%rbp)
movq 0x8(%r12), %rdi
movq (%rdi), %rax
leaq -0x1b0(%rbp), %rsi
callq *0x30(%rax)
movl %eax, %ecx
testl %eax, %eax
jne 0x2030a
movq -0x1b0(%rbp), %rax
cmpq -0x50(%rbp), %rax
jge 0x2030a
movq 0x8(%r12), %rdi
movq (%rdi), %rax
pushq $0x5
popq %rsi
leaq -0x50(%rbp), %rdx
movl %ecx, %ebx
callq *0x50(%rax)
movl %ebx, %ecx
movq -0x70(%rbp), %rbx
movl -0x3c(%rbp), %eax
orl $0x18, %eax
movq %rax, -0xb0(%rbp)
movq $0x0, -0x38(%rbp)
pushq $-0x1
popq %r12
movl %r13d, -0x58(%rbp)
testl %ecx, %ecx
jne 0x20488
movq -0x48(%rbp), %rcx
movl (%rcx), %eax
movl 0x4(%rcx), %ecx
movl %r12d, %r14d
testl %ecx, %ecx
jle 0x20392
decq %rcx
movq %rcx, %rdi
shlq $0x5, %rdi
leaq (%rbx,%rdi), %rdx
movslq 0x18(%rbx,%rdi), %rsi
movslq (%rbx,%rdi), %rdi
leal 0x1(%rdi), %r8d
cmpq %rsi, %rdi
jge 0x2033b
movq 0x8(%rdx), %r9
movq 0x10(%rdx), %r11
movzwl (%r9,%rdi,2), %r10d
movl (%r11,%r10,4), %r9d
cmpl %eax, %r9d
ja 0x20380
incq %rdi
movl %r8d, (%rdx)
incl %r8d
jmp 0x2035a
cmpl %r14d, %r9d
jae 0x2033b
addl 0x1c(%rdx), %r10d
movq %r10, -0x38(%rbp)
movl %r9d, %r14d
jmp 0x2033b
movq -0x48(%rbp), %rax
movl %r14d, (%rax)
cmpl $-0x1, %r14d
je 0x20431
xorl %ecx, %ecx
cmpl %r13d, -0x38(%rbp)
jbe 0x20327
cmpl %r15d, -0x38(%rbp)
ja 0x20327
cmpl -0x88(%rbp), %r14d
ja 0x20327
movq -0x38(%rbp), %rax
leal -0x1(%rax), %ecx
imulq -0xb0(%rbp), %rcx
addq $0x38, %rcx
movq -0x30(%rbp), %rbx
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
movq 0x10(%rbp), %r12
movq %r12, %rsi
movl -0x3c(%rbp), %r13d
movl %r13d, %edx
callq *0x10(%rax)
testl %eax, %eax
jne 0x2042d
decl %r14d
imulq -0x80(%rbp), %r14
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
movq %r12, %rsi
movl %r13d, %edx
movq %r14, %rcx
callq *0x18(%rax)
testl %eax, %eax
movl $0x0, %ecx
movq -0x70(%rbp), %rbx
movl -0x58(%rbp), %r13d
pushq $-0x1
popq %r12
je 0x20327
movl %eax, %ecx
jmp 0x20488
movq -0x30(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
cmpl 0x10(%rax), %r15d
jne 0x2047e
movq -0x30(%rbp), %rcx
movl 0x5c(%rcx), %eax
movq -0x80(%rbp), %rsi
imulq %rax, %rsi
movq 0x8(%rcx), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
movl %eax, %ecx
cmpl $0x0, -0x5c(%rbp)
je 0x2047a
testl %ecx, %ecx
jne 0x2047a
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
movl -0x5c(%rbp), %esi
callq *0x28(%rax)
movl %eax, %ecx
testl %ecx, %ecx
jne 0x20488
movq -0x68(%rbp), %rax
movl %r15d, 0x60(%rax)
xorl %ecx, %ecx
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq -0x30(%rbp), %r12
movq %r12, %rdi
movl %ecx, %ebx
callq 0x1e012
movl %ebx, %ecx
movq -0x90(%rbp), %r13
pushq $0x5
popq %r14
xorl %eax, %eax
cmpl $0x5, %ecx
cmovel %eax, %ecx
movl -0x54(%rbp), %r15d
jmp 0x2000c