// File: /workspace/github_c_makefile_star2_O3/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: walIndexReadHdr
static int walIndexReadHdr(Wal *pWal, int *pChanged){
  int rc;                         /* Return code */
  int badHdr;                     /* True if a header read failed */
  volatile u32 *page0;            /* Chunk of wal-index containing header */

  /* Ensure that page 0 of the wal-index (the page that contains the 
  ** wal-index header) is mapped. Return early if an error occurs here.
  */
  assert( pChanged );
  rc = walIndexPage(pWal, 0, &page0);
  if( rc!=SQLITE_OK ){
    return rc;
  };
  assert( page0 || pWal->writeLock==0 );

  /* If the first page of the wal-index has been mapped, try to read the
  ** wal-index header immediately, without holding any lock. This usually
  ** works, but may fail if the wal-index header is corrupt or currently 
  ** being modified by another thread or process.
  */
  badHdr = (page0 ? walIndexTryHdr(pWal, pChanged) : 1);

  /* If the first attempt failed, it might have been due to a race
  ** with a writer.  So get a WRITE lock and try again.
  */
  assert( badHdr==0 || pWal->writeLock==0 );
  if( badHdr ){
    if( pWal->readOnly & WAL_SHM_RDONLY ){
      if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){
        walUnlockShared(pWal, WAL_WRITE_LOCK);
        rc = SQLITE_READONLY_RECOVERY;
      }
    }else if( SQLITE_OK==(rc = walLockExclusive(pWal, WAL_WRITE_LOCK, 1)) ){
      pWal->writeLock = 1;
      if( SQLITE_OK==(rc = walIndexPage(pWal, 0, &page0)) ){
        badHdr = walIndexTryHdr(pWal, pChanged);
        if( badHdr ){
          /* If the wal-index header is still malformed even while holding
          ** a WRITE lock, it can only mean that the header is corrupted and
          ** needs to be reconstructed.  So run recovery to do exactly that.
          */
          rc = walIndexRecover(pWal);
          *pChanged = 1;
        }
      }
      pWal->writeLock = 0;
      walUnlockExclusive(pWal, WAL_WRITE_LOCK, 1);
    }
  }

  /* If the header is read successfully, check the version number to make
  ** sure the wal-index was not constructed with some future format that
  ** this version of SQLite cannot understand.
  */
  if( badHdr==0 && pWal->hdr.iVersion!=WALINDEX_MAX_VERSION ){
    rc = SQLITE_CANTOPEN_BKPT;
  }

  return rc;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
leaq -0x20(%rbp), %rdx
xorl %esi, %esi
callq 0x1bf63
testl %eax, %eax
je 0x1be05
movl %eax, %r14d
movl %r14d, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, -0x20(%rbp)
je 0x1be1f
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1c0c9
testl %eax, %eax
je 0x1bef1
testb $0x2, 0x42(%rbx)
movb 0x3f(%rbx), %al
jne 0x1bea0
testb %al, %al
je 0x1bf2b
movb $0x1, 0x40(%rbx)
leaq -0x20(%rbp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1bf63
movl %eax, %r14d
testl %eax, %eax
jne 0x1be6e
movq %rbx, %rdi
movq %r15, %rsi
callq 0x1c0c9
testl %eax, %eax
je 0x1bf4e
movq %rbx, %rdi
callq 0x1c1d6
movl %eax, %r14d
movl $0x1, (%r15)
movb $0x0, 0x40(%rbx)
cmpb $0x0, 0x3f(%rbx)
jne 0x1bdf7
xorl %r15d, %r15d
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl $0x1, %edx
movl $0x9, %ecx
callq *0x70(%rax)
testb %r15b, %r15b
je 0x1bdf7
jmp 0x1bef4
movl $0x108, %r14d           # imm = 0x108
testb %al, %al
jne 0x1bdf7
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl $0x1, %edx
movl $0x6, %ecx
callq *0x70(%rax)
testl %eax, %eax
jne 0x1bdf4
cmpb $0x0, 0x3f(%rbx)
jne 0x1bdf7
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl $0x1, %edx
movl $0x5, %ecx
callq *0x70(%rax)
jmp 0x1bdf7
xorl %r14d, %r14d
cmpl $0x2de218, 0x48(%rbx)   # imm = 0x2DE218
je 0x1bdf7
leaq 0x5d7d4(%rip), %rsi     # 0x796dc
leaq 0x5d62a(%rip), %rcx     # 0x79539
movl $0xe, %r14d
movl $0xe, %edi
movl $0xb9b2, %edx           # imm = 0xB9B2
xorl %eax, %eax
callq 0xb9c7
jmp 0x1bdf7
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl $0x1, %edx
movl $0xa, %ecx
callq *0x70(%rax)
testl %eax, %eax
jne 0x1bdf4
jmp 0x1be30
movb $0x0, 0x40(%rbx)
xorl %r14d, %r14d
cmpb $0x0, 0x3f(%rbx)
jne 0x1bef4
movb $0x1, %r15b
jmp 0x1be7f