// File: /workspace/github_c_makefile_star2_O3/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 $0xd8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
cmpl $0x0, 0x28(%rdi)
jle 0x287c1b
movq 0x30(%rbx), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
xorl %r12d, %r12d
testq %rax, %rax
jne 0x287c55
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2885c8
movl %eax, %r12d
testl %eax, %eax
je 0x287c4d
cmpl $0x508, %r12d           # imm = 0x508
jne 0x288412
movb $0x1, 0x46(%rbx)
movb $0x2, 0x3f(%rbx)
movl $0x1, (%r14)
cmpq $0x0, 0x30(%rsp)
je 0x287c68
movq %rbx, %rdi
movq %r14, %rsi
callq 0x28844a
testl %eax, %eax
je 0x28838f
cmpb $0x0, 0x46(%rbx)
jne 0x287c78
testb $0x2, 0x42(%rbx)
jne 0x28817c
movb 0x40(%rbx), %r13b
testb %r13b, %r13b
jne 0x287c8b
cmpb $0x0, 0x3f(%rbx)
je 0x2881d6
movb $0x1, 0x40(%rbx)
cmpl $0x0, 0x28(%rbx)
jle 0x287ca6
movq 0x30(%rbx), %rax
movq (%rax), %rax
movq %rax, 0x30(%rsp)
testq %rax, %rax
jne 0x287cc3
xorl %ebp, %ebp
leaq 0x30(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2885c8
testl %eax, %eax
je 0x287cc3
movl %eax, %r12d
jmp 0x288365
movq %rbx, %rdi
movq %r14, %rsi
callq 0x28844a
testl %eax, %eax
je 0x2881cb
movzbl 0x41(%rbx), %ebp
movl $0x2, %r15d
subl %ebp, %r15d
incl %ebp
cmpb $0x0, 0x3f(%rbx)
je 0x2881fc
xorps %xmm1, %xmm1
movups %xmm1, 0x68(%rbx)
movups %xmm1, 0x58(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movups %xmm1, 0x48(%rbx)
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
leaq 0x98(%rsp), %rsi
callq *0x30(%rax)
movl %eax, %r12d
testl %eax, %eax
jne 0x288342
cmpq $0x21, 0x98(%rsp)
jl 0x288270
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
leaq 0x60(%rsp), %rsi
movl $0x20, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
movl %eax, %r12d
testl %eax, %eax
jne 0x288342
movl 0x60(%rsp), %eax
shll $0x18, %eax
movzbl 0x61(%rsp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl 0x62(%rsp), %eax
shll $0x8, %eax
orl %ecx, %eax
movzbl 0x63(%rsp), %edi
movl %edi, %ecx
andl $-0x2, %ecx
orl %eax, %ecx
cmpl $0x377f0682, %ecx       # imm = 0x377F0682
jne 0x288270
movl 0x68(%rsp), %eax
shll $0x18, %eax
movzbl 0x69(%rsp), %ecx
shll $0x10, %ecx
movq %rax, 0x18(%rsp)
movq %rcx, 0x50(%rsp)
addl %ecx, %eax
movzbl 0x6a(%rsp), %ecx
shll $0x8, %ecx
movzbl 0x6b(%rsp), %edx
movq %rax, 0x58(%rsp)
movq %rdx, 0x40(%rsp)
addl %eax, %edx
movl %ecx, 0x48(%rsp)
orl %ecx, %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 0x288270
andl $0x1, %edi
movb %dil, 0x55(%rbx)
movl %edx, 0x38(%rbx)
leaq 0x60(%rsp), %r12
movl 0xc(%r12), %eax
bswapl %eax
movl %eax, 0x88(%rbx)
movq 0x10(%r12), %rax
movq %rax, 0x68(%rbx)
xorl $0x1, %edi
leaq 0x60(%rbx), %r8
movq %r12, %rsi
movq %rdx, 0x10(%rsp)
movl $0x18, %edx
xorl %ecx, %ecx
callq 0x28717d
movl 0x18(%r12), %eax
bswapl %eax
cmpl %eax, 0x60(%rbx)
jne 0x288270
movl 0x7c(%rsp), %eax
bswapl %eax
cmpl %eax, 0x64(%rbx)
jne 0x288270
movl 0x64(%rsp), %eax
bswapl %eax
cmpl $0x2de218, %eax         # imm = 0x2DE218
jne 0x288220
callq 0x2725a7
movl $0x7, %r12d
testl %eax, %eax
jne 0x288342
movq 0x10(%rsp), %rax
addl $0x18, %eax
movq %rax, 0x38(%rsp)
leaq 0x8000(%rax), %rdi
callq 0x272ae6
testq %rax, %rax
je 0x288342
movl %r15d, 0x8(%rsp)
movl %ebp, 0xc(%rsp)
movl 0x10(%rsp), %ecx
addq %rax, %rcx
addq $0x18, %rcx
movq %rcx, 0x10(%rsp)
movq %rax, 0x28(%rsp)
addq $0x18, %rax
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %rax
addq $-0x20, %rax
cqto
idivq 0x38(%rsp)
leal 0x1000(%rax), %ecx
movabsq $0xffffffff021, %rdx    # imm = 0xFFFFFFFF021
addq %rcx, %rdx
shrq $0xc, %rdx
movq %rdx, 0xb8(%rsp)
movl %eax, %eax
movq %rax, 0xc0(%rsp)
movq 0x58(%rsp), %rax
shrl $0x10, %eax
movl 0x48(%rsp), %ecx
orl %ecx, %eax
movq %rax, 0x58(%rsp)
movq 0x18(%rsp), %rax
addl 0x50(%rsp), %eax
addl %ecx, %eax
movq 0x40(%rsp), %rcx
addl %ecx, %eax
addl $0x18, %eax
movq %rax, 0x88(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
xorl %eax, %eax
xorl %edx, %edx
movq %rax, 0x50(%rsp)
movl %eax, %ecx
addq $0xfde, %rcx            # imm = 0xFDE
movq 0xc0(%rsp), %rax
cmpq %rax, %rcx
cmovaeq %rax, %rcx
movq %rcx, 0x48(%rsp)
movl %edx, %r15d
shll $0xc, %r15d
leal 0xfde(%r15), %ebp
cmpq %rbp, %rax
cmovbq %rax, %rbp
movq %rbx, %rdi
movl %edx, %esi
movl %edx, 0x18(%rsp)
leaq 0xd0(%rsp), %rdx
callq 0x288427
testl %eax, %eax
jne 0x288251
addl $-0x21, %r15d
movl 0x18(%rsp), %esi
testl %esi, %esi
movl $0x1, %eax
cmovel %eax, %r15d
movq 0x30(%rbx), %rax
movl %esi, %edx
movq 0x10(%rsp), %rcx
movq %rcx, (%rax,%rdx,8)
cmpl %ebp, %r15d
jbe 0x287fb3
xorl %r12d, %r12d
movb $0x1, %r15b
jmp 0x288101
movq %rbp, 0xc8(%rsp)
movq %rdx, 0x80(%rsp)
movl %r15d, %ebp
leaq -0x1(%rbp), %rcx
movq 0x38(%rsp), %rdx
imulq %rdx, %rcx
addq $0x20, %rcx
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
movq 0x28(%rsp), %rsi
callq *0x10(%rax)
xorl %r12d, %r12d
testl %eax, %eax
je 0x287ff8
xorl %r15d, %r15d
movl %eax, %r12d
jmp 0x2880f5
movq %rbx, %rdi
leaq 0x24(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq 0x90(%rsp), %rcx
movq 0x28(%rsp), %r8
callq 0x2886f2
testl %eax, %eax
je 0x2880e8
movq 0x88(%rsp), %r15
imulq %rbp, %r15
addq $0x20, %r15
movl $0x0, 0x4(%rsp)
movl 0x24(%rsp), %edx
movq %rbx, %rdi
movl %ebp, %esi
callq 0x28741e
testl %eax, %eax
jne 0x2880ed
movl 0x20(%rsp), %eax
testl %eax, %eax
je 0x288071
movl %ebp, 0x58(%rbx)
movl %eax, 0x5c(%rbx)
movq 0x58(%rsp), %rax
movw %ax, 0x56(%rbx)
movsd 0x60(%rbx), %xmm0
movaps %xmm0, 0xa0(%rsp)
cmpq 0xc8(%rsp), %rbp
setae %al
movl %eax, 0x4(%rsp)
movq %rbp, 0x40(%rsp)
cmpq %rbp, 0x48(%rsp)
je 0x288166
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
movq 0x28(%rsp), %rbp
movq %rbp, %rsi
movq 0x38(%rsp), %rdx
movq %r15, %rcx
callq *0x10(%rax)
testl %eax, %eax
jne 0x2880ed
movq %rbx, %rdi
leaq 0x24(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq 0x90(%rsp), %rcx
movq %rbp, %r8
callq 0x2886f2
addq 0x88(%rsp), %r15
movq 0x40(%rsp), %rbp
incq %rbp
testl %eax, %eax
jne 0x288037
xorl %r12d, %r12d
jmp 0x2880f0
xorl %r15d, %r15d
jmp 0x2880f5
movl %eax, %r12d
movl 0x4(%rsp), %r15d
movl 0x18(%rsp), %esi
movq 0x80(%rsp), %rdx
testl %esi, %esi
movq 0xd0(%rsp), %rdi
movq 0x30(%rbx), %rax
movq %rdi, (%rax,%rdx,8)
movl $0x0, %eax
movl $0x88, %ecx
cmoveq %rcx, %rax
addq %rax, %rdi
movq 0x10(%rsp), %rcx
movl %esi, %ebp
leaq (%rcx,%rax), %rsi
movl $0x8000, %edx           # imm = 0x8000
subq %rax, %rdx
callq 0x17660
testb $0x1, %r15b
je 0x288254
incl %ebp
movq 0x50(%rsp), %rax
addl $0x1000, %eax           # imm = 0x1000
cmpl 0xb8(%rsp), %ebp
movl %ebp, %edx
jbe 0x287f2c
jmp 0x288254
xorl %r12d, %r12d
movl 0x18(%rsp), %esi
movq 0x80(%rsp), %rdx
movl 0x4(%rsp), %r15d
jmp 0x288101
movl $0x108, %r12d           # imm = 0x108
cmpb $0x0, 0x3f(%rbx)
jne 0x288398
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl $0x1, %edx
movl $0x6, %ecx
callq *0x70(%rax)
testl %eax, %eax
jne 0x2881f4
cmpb $0x0, 0x3f(%rbx)
jne 0x288398
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl $0x1, %edx
movl $0x5, %ecx
callq *0x70(%rax)
jmp 0x288398
movb $0x1, %bpl
xorl %r12d, %r12d
jmp 0x288365
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl $0x1, %edx
movl $0xa, %ecx
callq *0x70(%rax)
testl %eax, %eax
je 0x287c8b
movl %eax, %r12d
jmp 0x288398
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
movl %ebp, %esi
movl %r15d, %edx
movl $0xa, %ecx
callq *0x70(%rax)
movl %eax, %r12d
testl %eax, %eax
jne 0x28835c
jmp 0x287cef
leaq 0x14d9a4(%rip), %rsi    # 0x3d5bcb
leaq 0x14d98c(%rip), %rdx    # 0x3d5bba
leaq 0x14d7fc(%rip), %r8     # 0x3d5a31
movl $0xe, %r12d
movl $0xe, %edi
movl $0xecdb, %ecx           # imm = 0xECDB
xorl %eax, %eax
callq 0x274d08
jmp 0x288342
movl %eax, %r12d
movq 0x28(%rsp), %rdi
callq 0x272c00
testl %r12d, %r12d
movl 0xc(%rsp), %ebp
movl 0x8(%rsp), %r15d
jne 0x288342
movl %r15d, 0x8(%rsp)
movl %ebp, 0xc(%rsp)
movaps 0xa0(%rsp), %xmm0
movlps %xmm0, 0x60(%rbx)
movq %rbx, %rdi
callq 0x287524
movq 0x30(%rbx), %rax
movq (%rax), %r15
xorl %ebp, %ebp
movl %ebp, 0x60(%r15)
movl 0x58(%rbx), %eax
movl %eax, 0x80(%r15)
movl %ebp, 0x64(%r15)
cmpb $0x0, 0x3f(%rbx)
jne 0x2882d2
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
leal 0x4(%rbp), %esi
movl $0x1, %edx
movl $0xa, %ecx
callq *0x70(%rax)
movl %eax, %r12d
cmpl $0x5, %eax
je 0x28830d
testl %r12d, %r12d
jne 0x288339
testq %rbp, %rbp
je 0x2882e2
movl $0xffffffff, 0x68(%r15,%rbp,4) # imm = 0xFFFFFFFF
jmp 0x2882ed
movl 0x58(%rbx), %eax
testl %eax, %eax
je 0x2882d7
movl %eax, 0x68(%r15)
xorl %r12d, %r12d
cmpb $0x0, 0x3f(%rbx)
jne 0x28830d
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
leal 0x4(%rbp), %esi
movl $0x1, %edx
movl $0x9, %ecx
callq *0x70(%rax)
incq %rbp
cmpq $0x4, %rbp
jne 0x2882a8
cmpl $0x0, 0x5c(%rbx)
je 0x288339
movl 0x58(%rbx), %edx
movq 0x80(%rbx), %rcx
leaq 0x14d98a(%rip), %rsi    # 0x3d5cb7
movl $0x11b, %edi            # imm = 0x11B
xorl %eax, %eax
callq 0x274d08
movl 0xc(%rsp), %ebp
movl 0x8(%rsp), %r15d
cmpb $0x0, 0x3f(%rbx)
jne 0x28835c
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
movl %ebp, %esi
movl %r15d, %edx
movl $0x9, %ecx
callq *0x70(%rax)
movl $0x1, (%r14)
xorl %ebp, %ebp
testb %r13b, %r13b
jne 0x28838a
movb $0x0, 0x40(%rbx)
cmpb $0x0, 0x3f(%rbx)
jne 0x28838a
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl $0x1, %edx
movl $0x9, %ecx
callq *0x70(%rax)
testb %bpl, %bpl
je 0x288398
cmpl $0x2de218, 0x48(%rbx)   # imm = 0x2DE218
jne 0x2883c3
cmpb $0x0, 0x46(%rbx)
je 0x288412
testl %r12d, %r12d
je 0x28840b
movq %rbx, %rdi
xorl %esi, %esi
callq 0x28855c
movb $0x0, 0x46(%rbx)
cmpl $0x20a, %r12d           # imm = 0x20A
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovel %eax, %r12d
jmp 0x28840e
leaq 0x14d801(%rip), %rsi    # 0x3d5bcb
leaq 0x14d7e9(%rip), %rdx    # 0x3d5bba
leaq 0x14d659(%rip), %r8     # 0x3d5a31
movl $0xe, %r12d
movl $0xe, %edi
movl $0xf149, %ecx           # imm = 0xF149
xorl %eax, %eax
callq 0x274d08
cmpb $0x0, 0x46(%rbx)
je 0x288412
movq %rbx, %rdi
xorl %esi, %esi
callq 0x28855c
movb $0x0, 0x46(%rbx)
movl $0xe, %r12d
jmp 0x28840e
xorl %r12d, %r12d
movb $0x0, 0x3f(%rbx)
movl %r12d, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq