// File: /workspace/github_c_makefile_star2_O0/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
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
leaq -0x28(%rbp), %rdx
callq 0x236a0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x234d3
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x235f0
cmpq $0x0, -0x28(%rbp)
je 0x234ec
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x23830
movl %eax, -0x2c(%rbp)
jmp 0x234f6
movl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x234f6
movl -0x2c(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x235ca
movq -0x10(%rbp), %rax
movzbl 0x42(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x23543
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x23600
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x2353e
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x230b0
movl $0x108, -0x1c(%rbp)     # imm = 0x108
jmp 0x235c8
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x23020
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x235c6
movq -0x10(%rbp), %rax
movb $0x1, 0x40(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
leaq -0x28(%rbp), %rdx
callq 0x236a0
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x235ae
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x23830
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x235ac
movq -0x10(%rbp), %rdi
callq 0x23970
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x235ae
movq -0x10(%rbp), %rax
movb $0x0, 0x40(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x23070
jmp 0x235c8
jmp 0x235ca
cmpl $0x0, -0x20(%rbp)
jne 0x235ea
movq -0x10(%rbp), %rax
cmpl $0x2de218, 0x48(%rax)   # imm = 0x2DE218
je 0x235ea
movl $0xb9b2, %edi           # imm = 0xB9B2
callq 0x1d9a0
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)