// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: walRestartLog
static int walRestartLog(Wal *pWal){
  int rc = SQLITE_OK;
  int cnt;

  if( pWal->readLock==0 ){
    volatile WalCkptInfo *pInfo = walCkptInfo(pWal);
    assert( pInfo->nBackfill==pWal->hdr.mxFrame );
    if( pInfo->nBackfill>0 ){
      u32 salt1;
      sqlite3_randomness(4, &salt1);
      rc = walLockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
      if( rc==SQLITE_OK ){
        /* If all readers are using WAL_READ_LOCK(0) (in other words if no
        ** readers are currently using the WAL), then the transactions
        ** frames will overwrite the start of the existing log. Update the
        ** wal-index header to reflect this.
        **
        ** In theory it would be Ok to update the cache of the header only
        ** at this point. But updating the actual wal-index header is also
        ** safe and means there is no special case for sqlite3WalUndo()
        ** to handle if this transaction is rolled back.
        */
        int i;                    /* Loop counter */
        u32 *aSalt = pWal->hdr.aSalt;       /* Big-endian salt values */

        pWal->nCkpt++;
        pWal->hdr.mxFrame = 0;
        sqlite3Put4byte((u8*)&aSalt[0], 1 + sqlite3Get4byte((u8*)&aSalt[0]));
        aSalt[1] = salt1;
        walIndexWriteHdr(pWal);
        pInfo->nBackfill = 0;
        pInfo->aReadMark[1] = 0;
        for(i=2; i<WAL_NREADER; i++) pInfo->aReadMark[i] = READMARK_NOT_USED;
        assert( pInfo->aReadMark[0]==0 );
        walUnlockExclusive(pWal, WAL_READ_LOCK(1), WAL_NREADER-1);
      }else if( rc!=SQLITE_BUSY ){
        return rc;
      }
    }
    walUnlockShared(pWal, WAL_READ_LOCK(0));
    pWal->readLock = -1;
    cnt = 0;
    do{
      int notUsed;
      rc = walTryBeginRead(pWal, &notUsed, 1, ++cnt);
    }while( rc==WAL_RETRY );
    assert( (rc&0xff)!=SQLITE_BUSY ); /* BUSY not possible when useWal==1 */
    testcase( (rc&0xff)==SQLITE_IOERR );
    testcase( rc==SQLITE_PROTOCOL );
    testcase( rc==SQLITE_OK );
  }
  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq -0x10(%rbp), %rax
movswl 0x3c(%rax), %eax
cmpl $0x0, %eax
jne 0x22b61
movq -0x10(%rbp), %rdi
callq 0x23000
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
cmpl $0x0, %eax
jbe 0x22b1c
movl $0x4, %edi
leaq -0x24(%rbp), %rsi
callq 0xc740
movq -0x10(%rbp), %rdi
movl $0x4, %edx
movl %edx, %esi
callq 0x23020
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x22b0a
movq -0x10(%rbp), %rax
addq $0x48, %rax
addq $0x20, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x80(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x80(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x58(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x30(%rbp), %rdi
callq 0x20a50
movq -0x40(%rbp), %rdi
movl %eax, %esi
addl $0x1, %esi
callq 0x22060
movl -0x24(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rdi
callq 0x22f60
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x8(%rax)
movl $0x2, -0x28(%rbp)
cmpl $0x5, -0x28(%rbp)
jge 0x22af8
movq -0x20(%rbp), %rax
movslq -0x28(%rbp), %rcx
movl $0xffffffff, 0x4(%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x22ad7
movq -0x10(%rbp), %rdi
movl $0x4, %edx
movl %edx, %esi
callq 0x23070
jmp 0x22b1a
cmpl $0x5, -0x14(%rbp)
je 0x22b18
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x22b67
jmp 0x22b1a
jmp 0x22b1c
movq -0x10(%rbp), %rdi
movl $0x3, %esi
callq 0x230b0
movq -0x10(%rbp), %rax
movw $0xffff, 0x3c(%rax)     # imm = 0xFFFF
movl $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x18(%rbp)
leaq -0x34(%rbp), %rsi
movl $0x1, %edx
callq 0x230f0
movl %eax, -0x14(%rbp)
cmpl $-0x1, -0x14(%rbp)
je 0x22b3b
jmp 0x22b61
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq