// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
andl $0x0, -0xbc(%rbp)
cmpb $0x0, 0x42(%rdi)
je 0x1aba2
pushq $0x8
popq %rax
jmp 0x1b3bc
movl %r9d, %ebx
movq %rcx, %r13
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %r12
movl %r8d, -0x44(%rbp)
pushq $0x1
popq %rdx
movl %edx, %esi
callq 0x1961e
testl %eax, %eax
jne 0x1b3bc
movb $0x1, 0x41(%r12)
testl %r15d, %r15d
je 0x1ac02
movl $0x0, -0x2c(%rbp)
pushq $0x1
popq %r8
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
xorl %ecx, %ecx
callq 0x1b41e
cmpl $0x5, %eax
je 0x1ac09
testl %eax, %eax
jne 0x1ac4f
movb $0x1, 0x40(%r12)
movl %r15d, -0x2c(%rbp)
jmp 0x1ac09
movl $0x0, -0x2c(%rbp)
movq %r14, -0x50(%rbp)
leaq -0xbc(%rbp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x198e4
cmpl $0x0, (%r14)
je 0x1ac46
movq 0x8(%r12), %rdi
movq (%rdi), %rcx
cmpl $0x3, (%rcx)
jl 0x1ac42
xorl %esi, %esi
xorl %edx, %edx
movl %eax, %r14d
callq *0x90(%rcx)
movl %r14d, %eax
xorl %esi, %esi
jmp 0x1ac49
movb $0x1, %sil
movq -0x50(%rbp), %r14
jmp 0x1ac56
movb $0x1, %sil
movl %r15d, -0x2c(%rbp)
testl %eax, %eax
jne 0x1b376
movl 0x58(%r12), %edx
movzwl 0x56(%r12), %eax
movl %eax, %ecx
shll $0x10, %ecx
orl %eax, %ecx
andl $0x1fe00, %ecx          # imm = 0x1FE00
movq %rdx, -0x98(%rbp)
testl %edx, %edx
je 0x1ac9d
cmpl %ebx, %ecx
je 0x1ac9d
movl $0xbd6c, %edi           # imm = 0xBD6C
movq %rsi, %rbx
callq 0x1a1fc
movq %rbx, %rsi
pushq $0xb
popq %rax
jmp 0x1b376
movl %ecx, -0x40(%rbp)
movq 0x30(%r12), %rax
movq (%rax), %rax
movq %rax, -0x78(%rbp)
movl 0x60(%rax), %ecx
xorl %eax, %eax
movq -0x98(%rbp), %rdx
cmpl %edx, %ecx
jae 0x1b34c
movq %r14, -0x50(%rbp)
movq %rsi, -0xc8(%rbp)
leal 0x1000(%rdx), %eax
movabsq $0xffffffff021, %r14    # imm = 0xFFFFFFFF021
addq %rax, %r14
shrq $0xc, %r14
movl %r14d, %eax
shll $0x5, %eax
leal (%rax,%rdx,2), %ebx
addl $0x28, %ebx
movl %ebx, %edi
callq 0x15019
testq %rax, %rax
je 0x1b062
movl %r15d, -0x3c(%rbp)
leal 0x1(%r14), %ecx
movl %ecx, -0x58(%rbp)
movslq %ebx, %rdx
movq %rax, %rdi
xorl %esi, %esi
movq %rax, %r15
callq 0x81e0
movl -0x58(%rbp), %eax
movl %eax, 0x4(%r15)
movl $0x1000, %edi           # imm = 0x1000
movq -0x98(%rbp), %rax
cmpl %edi, %eax
cmovbl %eax, %edi
addl %edi, %edi
callq 0x15019
movq %rax, %rbx
testq %rax, %rax
pushq $0x7
popq %rax
movl $0x0, %ecx
movq %rcx, -0x88(%rbp)
movl $0x0, %ecx
cmovnel %ecx, %eax
movq %r15, -0x70(%rbp)
addq $0x8, %r15
movq %r15, -0xa8(%rbp)
movslq %r14d, %rcx
movq %rcx, -0xa0(%rbp)
movl %ecx, %ecx
movq %rcx, -0xd8(%rbp)
movq %r12, -0x38(%rbp)
movq %r13, -0x90(%rbp)
movq -0x50(%rbp), %r14
testl %eax, %eax
movq -0x88(%rbp), %r15
jne 0x1af9c
cmpq -0xa0(%rbp), %r15
jg 0x1af9c
movq %r12, %rdi
movl %r15d, %esi
leaq -0xe0(%rbp), %rdx
leaq -0xd0(%rbp), %rcx
leaq -0x64(%rbp), %r8
callq 0x1a0ec
testl %eax, %eax
jne 0x1af8d
movq -0xd0(%rbp), %r14
addq $0x4, %r14
movq %r14, -0xd0(%rbp)
cmpq -0xd8(%rbp), %r15
movl %eax, -0xb8(%rbp)
jne 0x1adf8
movl -0x64(%rbp), %esi
movq -0x98(%rbp), %rax
movl %eax, %edx
subl %esi, %edx
jmp 0x1ae09
movq -0xe0(%rbp), %rdx
subq %r14, %rdx
shrq $0x2, %rdx
movl -0x64(%rbp), %esi
movq -0x70(%rbp), %rax
movslq 0x4(%rax), %rax
shlq $0x5, %rax
addq -0xa8(%rbp), %rax
movl %esi, %ecx
leaq (%rax,%rcx,2), %rax
movq %rax, -0x58(%rbp)
incl %esi
movl %esi, -0x64(%rbp)
testl %edx, %edx
movl $0x0, %r15d
cmovgl %edx, %r15d
xorl %eax, %eax
cmpq %rax, %r15
je 0x1ae4b
movq -0x58(%rbp), %rcx
movw %ax, (%rcx,%rax,2)
incq %rax
jmp 0x1ae39
movl %esi, -0xb4(%rbp)
movq %rdx, -0x80(%rbp)
andl $0x0, -0x30(%rbp)
andq $0x0, -0x60(%rbp)
movl $0xd0, %edx
leaq -0x1b0(%rbp), %rdi
xorl %esi, %esi
callq 0x81e0
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %r15, -0xb0(%rbp)
cmpq %r15, %r13
je 0x1aef2
movl $0x1, -0x30(%rbp)
movq -0x58(%rbp), %rax
leaq (%rax,%r13,2), %rax
movq %rax, -0x60(%rbp)
leaq -0x1a8(%rbp), %r15
xorl %r12d, %r12d
btl %r12d, %r13d
jae 0x1aec9
movq (%r15), %rsi
movl -0x8(%r15), %edx
movq %r14, %rdi
leaq -0x60(%rbp), %rcx
leaq -0x30(%rbp), %r8
movq %rbx, %r9
callq 0x1b498
incq %r12
addq $0x10, %r15
jmp 0x1aea0
movq -0x60(%rbp), %rax
movl %r12d, %ecx
shlq $0x4, %rcx
movq %rax, -0x1a8(%rbp,%rcx)
movl -0x30(%rbp), %eax
movl %eax, -0x1b0(%rbp,%rcx)
incq %r13
movq -0xb0(%rbp), %r15
jmp 0x1ae7e
movl %r12d, %r13d
movq %r13, %r12
shlq $0x4, %r12
leaq -0x198(%rbp), %rax
addq %rax, %r12
movq -0x80(%rbp), %rdx
cmpq $0xb, %r13
ja 0x1af44
movl %edx, %eax
movl %r13d, %ecx
shrl %cl, %eax
testb $0x2, %al
je 0x1af3b
movq (%r12), %rsi
movl -0x8(%r12), %edx
movq %r14, %rdi
leaq -0x60(%rbp), %rcx
leaq -0x30(%rbp), %r8
movq %rbx, %r9
callq 0x1b498
movq -0x80(%rbp), %rdx
incq %r13
addq $0x10, %r12
jmp 0x1af0a
movl -0x30(%rbp), %eax
movq -0x88(%rbp), %r15
movq %r15, %rcx
shlq $0x5, %rcx
movq -0xa8(%rbp), %rdx
movl -0xb4(%rbp), %esi
movl %esi, 0x1c(%rdx,%rcx)
movl %eax, 0x18(%rdx,%rcx)
movq -0x58(%rbp), %rax
movq %rax, 0x8(%rdx,%rcx)
movq %r14, 0x10(%rdx,%rcx)
movq -0x38(%rbp), %r12
movq -0x90(%rbp), %r13
movq -0x50(%rbp), %r14
movl -0xb8(%rbp), %eax
incq %r15
movq %r15, -0x88(%rbp)
jmp 0x1ad86
movq %rbx, %rdi
movl %eax, %ebx
callq 0x150da
testl %ebx, %ebx
movl -0x3c(%rbp), %r15d
jne 0x1b331
movq %r12, %rax
xorl %r12d, %r12d
cmpl $0x0, -0x2c(%rbp)
cmoveq %r12, %r14
movl 0x58(%rax), %r15d
movl 0x5c(%rax), %eax
movq %rax, -0x58(%rbp)
xorl %ecx, %ecx
cmpq $0x4, %r12
je 0x1b071
movq -0x78(%rbp), %rax
movl 0x68(%rax,%r12,4), %r13d
cmpl %r13d, %r15d
jbe 0x1b048
movq %r14, %rsi
leaq 0x4(%r12), %r14
movq -0x38(%rbp), %rdi
movq %rsi, %rbx
movq -0x90(%rbp), %rdx
movl %r14d, %ecx
pushq $0x1
popq %r8
callq 0x1b41e
movl %eax, %ecx
cmpl $0x5, %eax
je 0x1b04d
testl %ecx, %ecx
jne 0x1b0d3
movq %r12, %rax
negq %rax
movl $0x0, %eax
sbbl %eax, %eax
orl %r15d, %eax
movq -0x78(%rbp), %rcx
movl %eax, 0x68(%rcx,%r12,4)
movq -0x38(%rbp), %rdi
movl %r14d, %esi
pushq $0x1
popq %rdx
callq 0x1963f
xorl %ecx, %ecx
movl %r15d, %r13d
movq %rbx, %r14
jmp 0x1b050
movl %r15d, %r13d
jmp 0x1b050
xorl %r14d, %r14d
incq %r12
movl %r13d, %r15d
movq -0x90(%rbp), %r13
jmp 0x1afcd
pushq $0x7
popq %rax
movq -0xc8(%rbp), %rsi
jmp 0x1b376
movq -0x78(%rbp), %rax
movl 0x60(%rax), %eax
cmpl %r15d, %eax
movq -0x38(%rbp), %r12
jae 0x1b2cf
pushq $0x3
popq %rcx
pushq $0x1
popq %r8
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x1b41e
movl %eax, %ecx
testl %eax, %eax
jne 0x1b2cf
movq -0x78(%rbp), %rax
movl 0x60(%rax), %r13d
movl -0x40(%rbp), %eax
movq %rax, -0x80(%rbp)
cmpl $0x0, -0x44(%rbp)
movq %r14, -0x50(%rbp)
je 0x1b0e0
movq 0x10(%r12), %rdi
movq (%rdi), %rax
movl -0x44(%rbp), %esi
callq *0x28(%rax)
testl %eax, %eax
je 0x1b0e0
movl %eax, %ecx
jmp 0x1b128
movl -0x3c(%rbp), %r15d
movq -0x38(%rbp), %r12
jmp 0x1b32f
movq -0x58(%rbp), %rax
imulq -0x80(%rbp), %rax
movq %rax, -0x60(%rbp)
movq 0x8(%r12), %rdi
movq (%rdi), %rax
leaq -0x1b0(%rbp), %rsi
callq *0x30(%rax)
movl %eax, %ecx
testl %eax, %eax
jne 0x1b128
movq -0x1b0(%rbp), %rax
cmpq -0x60(%rbp), %rax
jge 0x1b128
movq 0x8(%r12), %rdi
movq (%rdi), %rax
pushq $0x5
popq %rsi
leaq -0x60(%rbp), %rdx
movl %ecx, %ebx
callq *0x50(%rax)
movl %ebx, %ecx
movl -0x40(%rbp), %eax
orl $0x18, %eax
movq %rax, -0x88(%rbp)
xorl %r12d, %r12d
pushq $-0x1
popq %rbx
movl %r13d, -0xa0(%rbp)
testl %ecx, %ecx
jne 0x1b2ae
movq -0x70(%rbp), %rcx
movl (%rcx), %eax
movl 0x4(%rcx), %ecx
movl %ebx, %r14d
testl %ecx, %ecx
jle 0x1b1b3
decq %rcx
movq %rcx, %rdi
shlq $0x5, %rdi
movq -0xa8(%rbp), %r8
leaq (%r8,%rdi), %rdx
movslq 0x18(%r8,%rdi), %rsi
movslq (%r8,%rdi), %rdi
leal 0x1(%rdi), %r8d
cmpq %rsi, %rdi
jge 0x1b156
movq 0x8(%rdx), %r9
movq 0x10(%rdx), %r11
movzwl (%r9,%rdi,2), %r10d
movl (%r11,%r10,4), %r9d
cmpl %eax, %r9d
ja 0x1b1a2
incq %rdi
movl %r8d, (%rdx)
incl %r8d
jmp 0x1b17c
cmpl %r14d, %r9d
jae 0x1b156
addl 0x1c(%rdx), %r10d
movl %r10d, %r12d
movl %r9d, %r14d
jmp 0x1b156
movq -0x70(%rbp), %rax
movl %r14d, (%rax)
cmpl $-0x1, %r14d
je 0x1b257
xorl %ecx, %ecx
cmpl %r13d, %r12d
jbe 0x1b142
cmpl %r15d, %r12d
ja 0x1b142
cmpl -0x58(%rbp), %r14d
ja 0x1b142
movq %r12, -0xb0(%rbp)
leal -0x1(%r12), %ecx
imulq -0x88(%rbp), %rcx
addq $0x38, %rcx
movq -0x38(%rbp), %rbx
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
movq 0x10(%rbp), %r12
movq %r12, %rsi
movl -0x40(%rbp), %r13d
movl %r13d, %edx
callq *0x10(%rax)
testl %eax, %eax
jne 0x1b253
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
movl -0xa0(%rbp), %r13d
pushq $-0x1
popq %rbx
movq -0xb0(%rbp), %r12
je 0x1b142
movl %eax, %ecx
jmp 0x1b2ae
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movq (%rax), %rax
cmpl 0x10(%rax), %r15d
jne 0x1b2a4
movq -0x38(%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, -0x44(%rbp)
je 0x1b2a0
testl %ecx, %ecx
jne 0x1b2a0
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
movq (%rdi), %rax
movl -0x44(%rbp), %esi
callq *0x28(%rax)
movl %eax, %ecx
testl %ecx, %ecx
jne 0x1b2ae
movq -0x78(%rbp), %rax
movl %r15d, 0x60(%rax)
xorl %ecx, %ecx
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq -0x38(%rbp), %r12
movq %r12, %rdi
movl %ecx, %ebx
callq 0x1963f
movl %ebx, %ecx
movq -0x90(%rbp), %r13
movq -0x50(%rbp), %r14
movl %ecx, %eax
xorl %ecx, %ecx
cmpl $0x5, %eax
cmovnel %eax, %ecx
cmpl $0x0, -0x2c(%rbp)
je 0x1b32b
testl %ecx, %ecx
movl -0x3c(%rbp), %r15d
jne 0x1b32f
movq -0x78(%rbp), %rax
movl 0x60(%rax), %eax
pushq $0x5
popq %rcx
cmpl 0x58(%r12), %eax
jb 0x1b32f
xorl %ecx, %ecx
cmpl $0x2, -0x2c(%rbp)
jne 0x1b32f
pushq $0x4
popq %rcx
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
movl %ecx, %r8d
callq 0x1b41e
movl %eax, %ecx
testl %eax, %eax
jne 0x1b32f
pushq $0x4
popq %rdx
movq %r12, %rdi
movl %edx, %esi
callq 0x1963f
xorl %ecx, %ecx
jmp 0x1b32f
movl -0x3c(%rbp), %r15d
movl %ecx, %ebx
movq -0x70(%rbp), %rdi
callq 0x150da
movl %ebx, %eax
cmpl $0x5, %ebx
movq -0xc8(%rbp), %rsi
je 0x1b34c
testl %eax, %eax
jne 0x1b376
movl %eax, %edi
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rcx
testq %rcx, %rcx
je 0x1b362
movl 0x58(%r12), %edx
movl %edx, (%rcx)
testq %rax, %rax
je 0x1b374
movq 0x30(%r12), %rcx
movq (%rcx), %rcx
movl 0x60(%rcx), %ecx
movl %ecx, (%rax)
movl %edi, %eax
movl %eax, %ebx
testb %sil, %sil
jne 0x1b392
xorps %xmm0, %xmm0
movups %xmm0, 0x68(%r12)
movups %xmm0, 0x58(%r12)
movups %xmm0, 0x48(%r12)
movq %r12, %rdi
callq 0x1b46e
pushq $0x1
popq %rdx
movq %r12, %rdi
movl %edx, %esi
callq 0x1963f
testl %ebx, %ebx
pushq $0x5
popq %rax
cmovnel %ebx, %eax
movb $0x0, 0x41(%r12)
cmpl %r15d, -0x2c(%rbp)
cmovel %ebx, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq