// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/external/sqlite-3.33.0/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 ){
    assert( rc!=SQLITE_READONLY ); /* READONLY changed to OK in walIndexPage */
    if( rc==SQLITE_READONLY_CANTINIT ){
      /* The SQLITE_READONLY_CANTINIT return means that the shared-memory
      ** was openable but is not writable, and this thread is unable to
      ** confirm that another write-capable connection has the shared-memory
      ** open, and hence the content of the shared-memory is unreliable,
      ** since the shared-memory might be inconsistent with the WAL file
      ** and there is no writer on hand to fix it. */
      assert( page0==0 );
      assert( pWal->writeLock==0 );
      assert( pWal->readOnly & WAL_SHM_RDONLY );
      pWal->bShmUnreliable = 1;
      pWal->exclusiveMode = WAL_HEAPMEMORY_MODE;
      *pChanged = 1;
    }else{
      return rc; /* Any other non-OK return is just an error */
    }
  }else{
    /* page0 can be NULL if the SHM is zero bytes in size and pWal->writeLock
    ** is zero, which prevents the SHM from growing */
    testcase( page0!=0 );
  }
  assert( page0!=0 || 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.
  */
  if( badHdr ){
    if( pWal->bShmUnreliable==0 && (pWal->readOnly & WAL_SHM_RDONLY) ){
      if( SQLITE_OK==(rc = walLockShared(pWal, WAL_WRITE_LOCK)) ){
        walUnlockShared(pWal, WAL_WRITE_LOCK);
        rc = SQLITE_READONLY_RECOVERY;
      }
    }else{
      int bWriteLock = pWal->writeLock;
      if( bWriteLock || SQLITE_OK==(rc = walLockWriter(pWal)) ){
        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;
          }
        }
        if( bWriteLock==0 ){
          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;
  }
  if( pWal->bShmUnreliable ){
    if( rc!=SQLITE_OK ){
      walIndexClose(pWal, 0);
      pWal->bShmUnreliable = 0;
      assert( pWal->nWiData>0 && pWal->apWiData[0]==0 );
      /* walIndexRecover() might have returned SHORT_READ if a concurrent
      ** writer truncated the WAL out from under it.  If that happens, it
      ** indicates that a writer has fixed the SHM file for us, so retry */
      if( rc==SQLITE_IOERR_SHORT_READ ) rc = WAL_RETRY;
    }
    pWal->exclusiveMode = WAL_NORMAL_MODE;
  }

  return rc;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x78(%rsp), %rdx
xorl %esi, %esi
callq 0x23211e
movl %eax, %r12d
testl %eax, %eax
je 0x231ae6
cmpl $0x508, %r12d           # imm = 0x508
jne 0x2320b7
movb $0x1, 0x46(%rbx)
movb $0x2, 0x3f(%rbx)
movl $0x1, (%r14)
cmpq $0x0, 0x78(%rsp)
je 0x231b01
movq %rbx, %rdi
movq %r14, %rsi
callq 0x232141
testl %eax, %eax
je 0x23206f
cmpb $0x0, 0x46(%rbx)
jne 0x231b11
testb $0x2, 0x42(%rbx)
jne 0x231f1d
movb 0x40(%rbx), %bpl
testb %bpl, %bpl
je 0x231b3f
movb $0x1, 0x40(%rbx)
xorl %r12d, %r12d
leaq 0x78(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x23211e
testl %eax, %eax
je 0x231b56
xorl %r14d, %r14d
movl %eax, %r12d
jmp 0x232054
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x231569
testl %eax, %eax
jne 0x232082
jmp 0x231b1a
movq %rbx, %rdi
movq %r14, %rsi
callq 0x232141
testl %eax, %eax
je 0x231f4e
movzbl 0x41(%rbx), %r15d
pushq $0x2
popq %r13
subl %r15d, %r13d
incl %r15d
movq %rbx, %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x231569
movl %eax, %r12d
testl %eax, %eax
jne 0x23204a
xorps %xmm1, %xmm1
movups %xmm1, 0x68(%rbx)
movups %xmm1, 0x58(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movups %xmm1, 0x48(%rbx)
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
leaq 0x80(%rsp), %rsi
callq *0x30(%rax)
movl %eax, %r12d
testl %eax, %eax
jne 0x23203c
cmpq $0x21, 0x80(%rsp)
jl 0x231f5b
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
leaq 0x50(%rsp), %rsi
pushq $0x20
popq %rdx
xorl %ecx, %ecx
callq *0x10(%rax)
movl %eax, %r12d
testl %eax, %eax
jne 0x23203c
movl %r13d, 0xc(%rsp)
movl 0x50(%rsp), %eax
shll $0x18, %eax
movzbl 0x51(%rsp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl 0x52(%rsp), %eax
shll $0x8, %eax
orl %ecx, %eax
movzbl 0x53(%rsp), %edi
movl %edi, %ecx
andl $-0x2, %ecx
orl %eax, %ecx
cmpl $0x377f0682, %ecx       # imm = 0x377F0682
jne 0x231f56
movl 0x58(%rsp), %eax
shll $0x18, %eax
movzbl 0x59(%rsp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl 0x5a(%rsp), %r12d
shll $0x8, %r12d
movzbl 0x5b(%rsp), %r13d
movl %ecx, 0x14(%rsp)
orl %ecx, %r13d
orl %r12d, %r13d
leal -0x1(%r13), %eax
testl %eax, %r13d
setne %al
leal -0x10001(%r13), %ecx
cmpl $0xffff01ff, %ecx       # imm = 0xFFFF01FF
setb %cl
orb %al, %cl
jne 0x231f56
andl $0x1, %edi
movb %dil, 0x55(%rbx)
movl %r13d, 0x38(%rbx)
movl %r15d, 0x10(%rsp)
leaq 0x50(%rsp), %r15
movl 0xc(%r15), %eax
bswapl %eax
movl %eax, 0x88(%rbx)
movq 0x10(%r15), %rax
movq %rax, 0x68(%rbx)
xorl $0x1, %edi
leaq 0x60(%rbx), %r8
pushq $0x18
popq %rdx
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x2311b9
movl 0x18(%r15), %eax
movl 0x10(%rsp), %r15d
bswapl %eax
cmpl %eax, 0x60(%rbx)
jne 0x231f56
movl 0x6c(%rsp), %eax
bswapl %eax
cmpl %eax, 0x64(%rbx)
jne 0x231f56
movl 0x54(%rsp), %eax
bswapl %eax
cmpl $0x2de218, %eax         # imm = 0x2DE218
jne 0x23201f
movl %r13d, %r15d
leaq 0x8018(%r15), %rdi
callq 0x21f7df
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x23202e
leaq 0x18(%r15), %rcx
movq 0x20(%rsp), %rax
leaq (%rax,%r15), %rdx
addq $0x18, %rdx
movq %rdx, 0x18(%rsp)
addq $0x18, %rax
movq %rax, 0xa8(%rsp)
movq 0x80(%rsp), %rax
addq $-0x20, %rax
cqto
movq %rcx, 0x28(%rsp)
idivq %rcx
leal 0x1000(%rax), %ecx
movabsq $0xffffffff021, %rdx    # imm = 0xFFFFFFFF021
addq %rcx, %rdx
shrq $0xc, %rdx
movq %rdx, 0x90(%rsp)
movl %eax, %eax
movq %rax, 0x88(%rsp)
movl 0x14(%rsp), %eax
shrl $0x10, %eax
orl %r12d, %eax
movl %eax, 0x14(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
xorl %r15d, %r15d
xorl %r12d, %r12d
cmpl 0x90(%rsp), %r15d
ja 0x2320cf
movq %rbx, %rdi
movl %r15d, %esi
leaq 0xb0(%rsp), %rdx
callq 0x23211e
testl %eax, %eax
jne 0x2320cc
movl %r15d, %r13d
shll $0xc, %r13d
leal 0xfde(%r13), %edx
movq 0x88(%rsp), %rax
cmpq %rdx, %rax
cmovbq %rax, %rdx
movq %rdx, 0x70(%rsp)
addl $-0x21, %r13d
testl %r15d, %r15d
pushq $0x1
popq %rax
cmovel %eax, %r13d
movq 0x30(%rbx), %rax
movq %r15, 0xa0(%rsp)
movl %r15d, %edx
movq 0x18(%rsp), %rcx
movq %rdx, 0x98(%rsp)
movq %rcx, (%rax,%rdx,8)
leaq -0x1(%r13), %rcx
imulq 0x28(%rsp), %rcx
addq $0x20, %rcx
movq 0x20(%rsp), %r15
cmpq 0x70(%rsp), %r13
ja 0x231eae
movq %r13, 0x30(%rsp)
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movq 0x28(%rsp), %rdx
movq %rcx, %r13
callq *0x10(%rax)
testl %eax, %eax
jne 0x231ea9
movq %rbx, %rdi
leaq 0x3c(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movq 0xa8(%rsp), %rcx
movq %r15, %r8
callq 0x2323ce
testl %eax, %eax
je 0x231eb8
movl 0x3c(%rsp), %edx
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
callq 0x23140c
testl %eax, %eax
jne 0x231ea9
movl 0x38(%rsp), %eax
testl %eax, %eax
movq 0x20(%rsp), %r15
movq %r13, %rcx
movq 0x30(%rsp), %r13
je 0x231e9c
movl %r13d, 0x58(%rbx)
movl %eax, 0x5c(%rbx)
movl 0x14(%rsp), %eax
movw %ax, 0x56(%rbx)
movsd 0x60(%rbx), %xmm0
movaps %xmm0, 0x40(%rsp)
incq %r13
addq 0x28(%rsp), %rcx
jmp 0x231e0f
movl %eax, %r12d
jmp 0x231ebb
xorl %r12d, %r12d
movq 0x18(%rsp), %rdx
jmp 0x231ec5
xorl %r12d, %r12d
movq 0x18(%rsp), %rdx
movq 0x30(%rsp), %r13
movq 0xa0(%rsp), %r15
testl %r15d, %r15d
movq 0xb0(%rsp), %rdi
movq 0x30(%rbx), %rax
movq 0x98(%rsp), %rcx
movq %rdi, (%rax,%rcx,8)
movl $0x0, %eax
movl $0x88, %ecx
cmoveq %rcx, %rax
addq %rax, %rdi
leaq (%rdx,%rax), %rsi
movl $0x8000, %edx           # imm = 0x8000
subq %rax, %rdx
callq 0x17630
cmpq 0x70(%rsp), %r13
jbe 0x2320cf
incl %r15d
jmp 0x231d83
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2320f1
testl %eax, %eax
jne 0x232082
movq %rbx, %rdi
xorl %esi, %esi
callq 0x23160d
movl $0x108, %r12d           # imm = 0x108
cmpb $0x0, 0x46(%rbx)
jne 0x232090
jmp 0x2320b7
movb $0x1, %r14b
jmp 0x232054
movl 0xc(%rsp), %r13d
movl %r13d, 0xc(%rsp)
movl %r15d, 0x10(%rsp)
movaps 0x40(%rsp), %xmm0
movlps %xmm0, 0x60(%rbx)
movq %rbx, %rdi
callq 0x2314f6
movq 0x30(%rbx), %rax
movq (%rax), %rcx
xorl %r13d, %r13d
movl %r13d, 0x60(%rcx)
movl 0x58(%rbx), %eax
movl %eax, 0x80(%rcx)
movq %rcx, 0x40(%rsp)
movl %r13d, 0x64(%rcx)
xorl %r12d, %r12d
cmpq $0x4, %r13
je 0x231ff5
leaq 0x4(%r13), %r15
movq %rbx, %rdi
movl %r15d, %esi
pushq $0x1
popq %rdx
callq 0x231569
movl %eax, %r12d
cmpl $0x5, %eax
je 0x231ff0
testl %r12d, %r12d
jne 0x232032
testq %r13, %r13
je 0x231fd3
movq 0x40(%rsp), %rax
movl $0xffffffff, 0x68(%rax,%r13,4) # imm = 0xFFFFFFFF
jmp 0x231fe2
movl 0x58(%rbx), %eax
testl %eax, %eax
je 0x231fc3
movq 0x40(%rsp), %rcx
movl %eax, 0x68(%rcx)
movq %rbx, %rdi
movl %r15d, %esi
pushq $0x1
popq %rdx
callq 0x2315f6
incq %r13
jmp 0x231f99
cmpl $0x0, 0x5c(%rbx)
movl 0x10(%rsp), %r15d
je 0x232037
movl 0x58(%rbx), %edx
movq 0x80(%rbx), %rcx
leaq 0x1440c6(%rip), %rsi    # 0x3760d7
movl $0x11b, %edi            # imm = 0x11B
xorl %eax, %eax
callq 0x2214a3
jmp 0x232037
movl $0xecdb, %edi           # imm = 0xECDB
callq 0x22e760
movl %eax, %r12d
jmp 0x232037
pushq $0x7
popq %r12
movl 0x10(%rsp), %r15d
movl 0xc(%rsp), %r13d
movq %rbx, %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0x2315f6
movl $0x1, (%r14)
xorl %r14d, %r14d
testb %bpl, %bpl
jne 0x23206a
movb $0x0, 0x40(%rbx)
pushq $0x1
popq %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2315f6
testb %r14b, %r14b
je 0x232085
cmpl $0x2de218, 0x48(%rbx)   # imm = 0x2DE218
je 0x232085
movl $0xf149, %edi           # imm = 0xF149
callq 0x22e760
movl %eax, %r12d
cmpb $0x0, 0x46(%rbx)
je 0x2320b7
testl %r12d, %r12d
je 0x2320ae
movq %rbx, %rdi
xorl %esi, %esi
callq 0x232257
movb $0x0, 0x46(%rbx)
cmpl $0x20a, %r12d           # imm = 0x20A
pushq $-0x1
popq %rax
cmovnel %r12d, %eax
jmp 0x2320b0
xorl %eax, %eax
movb $0x0, 0x3f(%rbx)
movl %eax, %r12d
movl %r12d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %r12d
movq 0x20(%rsp), %rdi
callq 0x21f7f9
testl %r12d, %r12d
movl 0x10(%rsp), %r15d
movl 0xc(%rsp), %r13d
jne 0x23203c
jmp 0x231f5b