// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq -0x98(%rbp), %rdx
xorl %esi, %esi
callq 0x19e51
testl %eax, %eax
je 0x19928
movl %eax, %r13d
movl %r13d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, -0x98(%rbp)
je 0x19941
movq %rbx, %rdi
movq %r14, %rsi
callq 0x19f2e
testl %eax, %eax
je 0x199a2
testb $0x2, 0x42(%rbx)
jne 0x1997f
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1961e
testl %eax, %eax
jne 0x19910
movb $0x1, 0x40(%rbx)
xorl %r13d, %r13d
leaq -0x98(%rbp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x19e51
testl %eax, %eax
je 0x199aa
xorl %r14d, %r14d
movl %eax, %r13d
jmp 0x19dae
movq %rbx, %rdi
xorl %esi, %esi
callq 0x19e14
testl %eax, %eax
jne 0x19910
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1965e
movl $0x108, %r13d           # imm = 0x108
jmp 0x19913
xorl %r13d, %r13d
jmp 0x19dc8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x19f2e
testl %eax, %eax
je 0x19d2a
movzbl 0x41(%rbx), %r15d
pushq $0x7
popq %r12
subl %r15d, %r12d
incl %r15d
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x1961e
movl %eax, %r13d
testl %eax, %eax
jne 0x19da4
movl %r15d, -0x60(%rbp)
pushq $0x7
popq %r15
movl %r12d, -0x64(%rbp)
xorps %xmm0, %xmm0
movups %xmm0, 0x68(%rbx)
movups %xmm0, 0x58(%rbx)
movups %xmm0, 0x48(%rbx)
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
leaq -0xa0(%rbp), %rsi
callq *0x30(%rax)
movl %eax, %r13d
testl %eax, %eax
jne 0x19d96
xorl %r12d, %r12d
cmpq $0x21, -0xa0(%rbp)
movl $0x0, %eax
movl $0x0, %ecx
jl 0x19d33
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
leaq -0x90(%rbp), %rsi
pushq $0x20
popq %rdx
xorl %ecx, %ecx
callq *0x10(%rax)
movl %eax, %r13d
testl %eax, %eax
jne 0x19d96
movl -0x90(%rbp), %eax
shll $0x18, %eax
movzbl -0x8f(%rbp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl -0x8e(%rbp), %eax
shll $0x8, %eax
orl %ecx, %eax
movzbl -0x8d(%rbp), %edi
movl %edi, %ecx
andl $-0x2, %ecx
orl %eax, %ecx
cmpl $0x377f0682, %ecx       # imm = 0x377F0682
jne 0x19d2f
movl -0x88(%rbp), %eax
shll $0x18, %eax
movzbl -0x87(%rbp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl -0x86(%rbp), %eax
shll $0x8, %eax
movzbl -0x85(%rbp), %edx
movl %ecx, -0x34(%rbp)
orl %ecx, %edx
movl %eax, -0x48(%rbp)
orl %eax, %edx
leal -0x1(%rdx), %eax
testl %eax, %edx
setne %al
leal -0x10001(%rdx), %ecx
cmpl $0xffff01ff, %ecx       # imm = 0xFFFF01FF
setb %cl
orb %al, %cl
jne 0x19d2f
andl $0x1, %edi
movb %dil, 0x55(%rbx)
movl %edx, 0x38(%rbx)
leaq -0x90(%rbp), %r13
movl 0xc(%r13), %eax
bswapl %eax
movl %eax, 0x80(%rbx)
movq 0x10(%r13), %rax
movq %rax, 0x68(%rbx)
xorl $0x1, %edi
leaq 0x60(%rbx), %r8
movq %rdx, -0x58(%rbp)
pushq $0x18
popq %rdx
movq %r13, %rsi
xorl %ecx, %ecx
movq %r8, -0xe0(%rbp)
callq 0x192e3
movl 0x18(%r13), %eax
bswapl %eax
cmpl %eax, 0x60(%rbx)
jne 0x19d2f
movl -0x74(%rbp), %eax
bswapl %eax
cmpl %eax, 0x64(%rbx)
jne 0x19d2f
movl -0x8c(%rbp), %eax
bswapl %eax
cmpl $0x2de218, %eax         # imm = 0x2DE218
jne 0x19de8
movq -0x58(%rbp), %rdi
addl $0x18, %edi
movq %rdi, -0x58(%rbp)
callq 0x9c1c
movl %r15d, %r13d
movq %rax, -0x40(%rbp)
testq %rax, %rax
je 0x19d96
leaq 0x68(%rbx), %rax
movq %rax, -0xd0(%rbp)
movq -0x40(%rbp), %rax
leaq 0x18(%rax), %rcx
movq %rcx, -0xc0(%rbp)
leaq 0x8(%rax), %rcx
movq %rcx, -0xc8(%rbp)
leaq 0x4(%rax), %rcx
movq %rcx, -0xa8(%rbp)
movl -0x58(%rbp), %ecx
movq %rcx, -0xd8(%rbp)
leaq 0x10(%rax), %rcx
movq %rcx, -0xb8(%rbp)
addq $0x14, %rax
movq %rax, -0xb0(%rbp)
movl -0x34(%rbp), %eax
shrl $0x10, %eax
orl -0x48(%rbp), %eax
movl %eax, -0x34(%rbp)
pushq $0x20
popq %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x48(%rbp), %rcx
movq -0xd8(%rbp), %rax
addq %rcx, %rax
xorl %r13d, %r13d
movq %rax, -0x48(%rbp)
cmpq -0xa0(%rbp), %rax
jg 0x19dfb
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
movq -0x40(%rbp), %rsi
movq -0x58(%rbp), %rdx
callq *0x10(%rax)
testl %eax, %eax
jne 0x19df8
movq -0xd0(%rbp), %rax
movq (%rax), %rax
movq -0xc8(%rbp), %rcx
cmpq (%rcx), %rax
jne 0x19dfb
movq -0x40(%rbp), %rdi
callq 0x180a3
movl %eax, -0x5c(%rbp)
testl %eax, %eax
je 0x19dfb
xorl %edi, %edi
cmpb $0x0, 0x55(%rbx)
sete %dil
movl %edi, -0x2c(%rbp)
movq -0x40(%rbp), %rsi
pushq $0x8
popq %rdx
movq -0xe0(%rbp), %r15
movq %r15, %rcx
movq %r15, %r8
callq 0x192e3
movl 0x38(%rbx), %edx
movl -0x2c(%rbp), %edi
movq -0xc0(%rbp), %rsi
movq %r15, %rcx
movq %r15, %r8
callq 0x192e3
movl 0x60(%rbx), %r15d
movq -0xb8(%rbp), %rdi
callq 0x180a3
cmpl %eax, %r15d
jne 0x19dfb
movl 0x64(%rbx), %r15d
movq -0xb0(%rbp), %rdi
callq 0x180a3
cmpl %eax, %r15d
jne 0x19dfb
movl -0x30(%rbp), %r13d
incl %r13d
movq -0xa8(%rbp), %rdi
callq 0x180a3
movl %eax, -0x2c(%rbp)
movq %rbx, %rdi
movl %r13d, -0x30(%rbp)
movl %r13d, %esi
movl -0x5c(%rbp), %edx
callq 0x194b8
testl %eax, %eax
jne 0x19df8
movq -0x48(%rbp), %rcx
cmpl $0x0, -0x2c(%rbp)
je 0x19bf2
movl -0x30(%rbp), %eax
movl %eax, 0x58(%rbx)
movl -0x2c(%rbp), %eax
movl %eax, 0x5c(%rbx)
movl -0x34(%rbp), %eax
movw %ax, 0x56(%rbx)
movl 0x60(%rbx), %eax
movl %eax, -0x4c(%rbp)
movl 0x64(%rbx), %eax
movl %eax, -0x50(%rbp)
jmp 0x19bee
movb $0x1, %r14b
jmp 0x19dae
xorl %eax, %eax
xorl %ecx, %ecx
movl %eax, 0x60(%rbx)
movl %ecx, 0x64(%rbx)
movq %rbx, %rdi
callq 0x195ab
movq 0x30(%rbx), %rax
movq (%rax), %rax
movl %r12d, 0x60(%rax)
movl %r12d, 0x64(%rax)
cmpq $0x4, %r12
je 0x19d64
movl $0xffffffff, 0x68(%rax,%r12,4) # imm = 0xFFFFFFFF
incq %r12
jmp 0x19d50
movl 0x58(%rbx), %ecx
testl %ecx, %ecx
je 0x19d6e
movl %ecx, 0x68(%rax)
cmpl $0x0, 0x5c(%rbx)
je 0x19d93
movl 0x58(%rbx), %edx
movq 0x78(%rbx), %rcx
leaq 0x51a73(%rip), %rsi     # 0x6b7f5
xorl %r13d, %r13d
movl $0x11b, %edi            # imm = 0x11B
xorl %eax, %eax
callq 0xaf99
jmp 0x19d96
xorl %r13d, %r13d
movq %rbx, %rdi
movl -0x60(%rbp), %esi
movl -0x64(%rbp), %edx
callq 0x1963f
movl $0x1, (%r14)
xorl %r14d, %r14d
movb $0x0, 0x40(%rbx)
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1963f
testb %r14b, %r14b
je 0x19913
cmpl $0x2de218, 0x48(%rbx)   # imm = 0x2DE218
je 0x19913
pushq $0xe
popq %r13
movl $0xb9b2, %edi           # imm = 0xB9B2
callq 0x16cb0
jmp 0x19913
movl $0xb64b, %edi           # imm = 0xB64B
callq 0x16cb0
pushq $0xe
popq %r13
jmp 0x19d96
movl %eax, %r13d
movq -0x40(%rbp), %rdi
callq 0x9c7b
testl %r13d, %r13d
movl -0x4c(%rbp), %eax
movl -0x50(%rbp), %ecx
jne 0x19d96
jmp 0x19d33