// File: /workspace/github_c_makefile_star2_O1/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 0x291995
movq 0x30(%rbx), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
xorl %r13d, %r13d
testq %rax, %rax
jne 0x2919a7
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2923d2
movl %eax, %r13d
testl %r13d, %r13d
je 0x2919c8
cmpl $0x508, %r13d           # imm = 0x508
jne 0x291eb4
movb $0x1, 0x46(%rbx)
movb $0x2, 0x3f(%rbx)
movl $0x1, (%r14)
cmpq $0x0, 0x38(%rsp)
je 0x2919e3
movq %rbx, %rdi
movq %r14, %rsi
callq 0x292256
testl %eax, %eax
je 0x291b0a
cmpb $0x0, 0x46(%rbx)
jne 0x2919f3
testb $0x2, 0x42(%rbx)
jne 0x291b47
movb 0x40(%rbx), %r12b
testb %r12b, %r12b
je 0x291b12
movb $0x1, 0x40(%rbx)
cmpl $0x0, 0x28(%rbx)
jle 0x291a1e
movq 0x30(%rbx), %rax
movq (%rax), %rax
movq %rax, 0x38(%rsp)
xorl %r13d, %r13d
testq %rax, %rax
jne 0x291a30
leaq 0x38(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2923d2
movl %eax, %r13d
movl $0x1, %ebp
testl %r13d, %r13d
jne 0x291e1d
movq %rbx, %rdi
movq %r14, %rsi
callq 0x292256
testl %eax, %eax
je 0x291b81
movl %eax, %ebp
movzbl 0x41(%rbx), %r15d
movl $0x2, %eax
subl %r15d, %eax
movl %eax, 0x24(%rsp)
incl %r15d
xorl %r13d, %r13d
cmpb $0x0, 0x3f(%rbx)
jne 0x291a89
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
movl %r15d, %esi
movl 0x24(%rsp), %edx
movl $0xa, %ecx
callq *0x70(%rax)
movl %eax, %r13d
testl %r13d, %r13d
jne 0x291e16
xorps %xmm0, %xmm0
movups %xmm0, 0x68(%rbx)
movups %xmm0, 0x58(%rbx)
movups %xmm0, 0x48(%rbx)
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
leaq 0xa0(%rsp), %rsi
callq *0x30(%rax)
movl %eax, %r13d
testl %eax, %eax
jne 0x291dfa
xorl %edx, %edx
cmpq $0x21, 0xa0(%rsp)
movl $0x0, %esi
movl $0x0, %r13d
jl 0x291d19
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
leaq 0x70(%rsp), %rsi
movl $0x20, %edx
xorl %ecx, %ecx
callq *0x10(%rax)
movl %eax, %r13d
movl $0x2, %eax
testl %r13d, %r13d
je 0x291ba8
xorl %esi, %esi
xorl %edx, %edx
jmp 0x291d07
movb $0x1, %bpl
jmp 0x291e48
xorl %r13d, %r13d
cmpb $0x0, 0x3f(%rbx)
jne 0x291b34
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl $0x1, %edx
movl $0xa, %ecx
callq *0x70(%rax)
movl %eax, %r13d
movl $0x1, %ebp
testl %r13d, %r13d
jne 0x291e42
jmp 0x291a00
xorl %r13d, %r13d
cmpb $0x0, 0x3f(%rbx)
jne 0x291b69
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl $0x1, %edx
movl $0x6, %ecx
callq *0x70(%rax)
movl %eax, %r13d
testl %r13d, %r13d
jne 0x291b7a
movl $0x108, %r13d           # imm = 0x108
cmpb $0x0, 0x3f(%rbx)
je 0x291b8b
xorl %ebp, %ebp
jmp 0x291e48
xorl %r13d, %r13d
xorl %ebp, %ebp
jmp 0x291e1d
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %ebp, %ebp
xorl %esi, %esi
movl $0x1, %edx
movl $0x5, %ecx
callq *0x70(%rax)
jmp 0x291e48
movl 0x70(%rsp), %eax
shll $0x18, %eax
movzbl 0x71(%rsp), %ecx
shll $0x10, %ecx
orl %eax, %ecx
movzbl 0x72(%rsp), %eax
shll $0x8, %eax
orl %ecx, %eax
movzbl 0x73(%rsp), %edi
movl %edi, %ecx
andl $-0x2, %ecx
orl %eax, %ecx
xorl %edx, %edx
movl $0x3, %eax
cmpl $0x377f0682, %ecx       # imm = 0x377F0682
jne 0x291c34
movl 0x78(%rsp), %r8d
shll $0x18, %r8d
movzbl 0x79(%rsp), %r9d
shll $0x10, %r9d
leal (%r9,%r8), %esi
movzbl 0x7a(%rsp), %r10d
shll $0x8, %r10d
movzbl 0x7b(%rsp), %r11d
leal (%rsi,%r11), %r13d
orl %r10d, %r13d
leal -0x1(%r13), %eax
testl %eax, %r13d
setne %al
leal -0x10001(%r13), %ecx
cmpl $0xffff01ff, %ecx       # imm = 0xFFFF01FF
setb %cl
orb %al, %cl
je 0x291c3e
xorl %esi, %esi
xorl %r13d, %r13d
jmp 0x291d02
xorl %esi, %esi
xorl %r13d, %r13d
jmp 0x291d07
movq %r11, 0x28(%rsp)
movl %r10d, 0x10(%rsp)
movq %r9, 0x30(%rsp)
movq %r8, 0x58(%rsp)
movq %rsi, 0x40(%rsp)
andl $0x1, %edi
movb %dil, 0x55(%rbx)
movq %r13, 0x8(%rsp)
movl %r13d, 0x38(%rbx)
leaq 0x70(%rsp), %r13
movl 0xc(%r13), %eax
bswapl %eax
movl %eax, 0x88(%rbx)
movq 0x10(%r13), %rax
movq %rax, 0x68(%rbx)
xorl $0x1, %edi
leaq 0x60(%rbx), %r8
movq %r13, %rsi
movl $0x18, %edx
xorl %ecx, %ecx
callq 0x290e69
movl 0x18(%r13), %eax
bswapl %eax
cmpl %eax, 0x60(%rbx)
jne 0x291cfb
movl 0x8c(%rsp), %eax
bswapl %eax
movl $0x0, %esi
movl $0x0, %r13d
cmpl %eax, 0x64(%rbx)
movl $0x0, %edx
movl $0x3, %eax
jne 0x291d07
movl 0x74(%rsp), %eax
bswapl %eax
cmpl $0x2de218, %eax         # imm = 0x2DE218
jne 0x291ec9
movl %r15d, 0x4(%rsp)
movq 0x8(%rsp), %rax
addl $0x18, %eax
movq %rax, 0x48(%rsp)
callq 0x27bed9
testl %eax, %eax
je 0x291f10
xorl %eax, %eax
jmp 0x291f21
xorl %esi, %esi
xorl %r13d, %r13d
xorl %edx, %edx
movl $0x3, %eax
movl %eax, %eax
leaq 0x147c74(%rip), %rcx    # 0x3d9984
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testl %r13d, %r13d
jne 0x291dfa
movl %r15d, 0x4(%rsp)
movl %esi, 0x60(%rbx)
movl %edx, 0x64(%rbx)
movq %rbx, %rdi
callq 0x291278
movq 0x30(%rbx), %rax
movq (%rax), %rcx
xorl %r15d, %r15d
movl %r15d, 0x60(%rcx)
movl 0x58(%rbx), %eax
movl %eax, 0x80(%rcx)
movq %rcx, 0x8(%rsp)
movl %r15d, 0x64(%rcx)
cmpb $0x0, 0x3f(%rbx)
movl $0x0, %r13d
jne 0x291d7c
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
leal 0x4(%r15), %esi
movl $0x1, %edx
movl $0xa, %ecx
callq *0x70(%rax)
movl %eax, %r13d
cmpl $0x5, %r13d
je 0x291dc9
testl %r13d, %r13d
jne 0x291df5
testq %r15, %r15
je 0x291d9c
movq 0x8(%rsp), %rax
movl $0xffffffff, 0x68(%rax,%r15,4) # imm = 0xFFFFFFFF
jmp 0x291dab
movl 0x58(%rbx), %eax
testl %eax, %eax
je 0x291d8c
movq 0x8(%rsp), %rcx
movl %eax, 0x68(%rcx)
cmpb $0x0, 0x3f(%rbx)
jne 0x291dc9
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
leal 0x4(%r15), %esi
movl $0x1, %edx
movl $0x9, %ecx
callq *0x70(%rax)
incq %r15
cmpq $0x4, %r15
jne 0x291d55
cmpl $0x0, 0x5c(%rbx)
je 0x291df5
movl 0x58(%rbx), %edx
movq 0x80(%rbx), %rcx
leaq 0x14d622(%rip), %rsi    # 0x3df40b
movl $0x11b, %edi            # imm = 0x11B
xorl %eax, %eax
callq 0x27e637
movl 0x4(%rsp), %r15d
cmpb $0x0, 0x3f(%rbx)
jne 0x291e16
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
movl %r15d, %esi
movl 0x24(%rsp), %edx
movl $0x9, %ecx
callq *0x70(%rax)
movl $0x1, (%r14)
testb %r12b, %r12b
jne 0x291e42
movb $0x0, 0x40(%rbx)
cmpb $0x0, 0x3f(%rbx)
jne 0x291e42
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
xorl %esi, %esi
movl $0x1, %edx
movl $0x9, %ecx
callq *0x70(%rax)
testl %ebp, %ebp
sete %bpl
testb %bpl, %bpl
je 0x291e82
cmpl $0x2de218, 0x48(%rbx)   # imm = 0x2DE218
je 0x291e82
leaq 0x14d4c2(%rip), %rsi    # 0x3df31f
leaq 0x14d4aa(%rip), %rdx    # 0x3df30e
leaq 0x14d31a(%rip), %r8     # 0x3df185
movl $0xe, %r13d
movl $0xe, %edi
movl $0xf149, %ecx           # imm = 0xF149
xorl %eax, %eax
callq 0x27e637
cmpb $0x0, 0x46(%rbx)
je 0x291eb4
testl %r13d, %r13d
je 0x291ead
movq %rbx, %rdi
xorl %esi, %esi
callq 0x292368
movb $0x0, 0x46(%rbx)
cmpl $0x20a, %r13d           # imm = 0x20A
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovel %eax, %r13d
jmp 0x291eb0
xorl %r13d, %r13d
movb $0x0, 0x3f(%rbx)
movl %r13d, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14d44f(%rip), %rsi    # 0x3df31f
leaq 0x14d437(%rip), %rdx    # 0x3df30e
leaq 0x14d2a7(%rip), %r8     # 0x3df185
movl $0xe, %r13d
movl $0xe, %edi
movl $0xecdb, %ecx           # imm = 0xECDB
xorl %eax, %eax
callq 0x27e637
xorl %edx, %edx
movl $0x3, %eax
movl %eax, %eax
leaq 0x147a7f(%rip), %rcx    # 0x3d9984
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
xorl %esi, %esi
jmpq *%rax
movq 0x48(%rsp), %rax
leaq 0x8000(%rax), %rdi
callq 0x27c381
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x29221c
movq 0x50(%rsp), %rcx
leaq 0x18(%rcx), %rax
movq %rax, 0xc0(%rsp)
movl 0x8(%rsp), %eax
addq %rcx, %rax
addq $0x18, %rax
movq %rax, 0x98(%rsp)
movq 0xa0(%rsp), %rax
addq $-0x20, %rax
cqto
idivq 0x48(%rsp)
leal 0x1000(%rax), %ecx
movabsq $0xffffffff021, %rdx    # imm = 0xFFFFFFFF021
addq %rcx, %rdx
shrq $0xc, %rdx
movq %rdx, 0xb0(%rsp)
movl %eax, %eax
movq %rax, 0xb8(%rsp)
movq 0x40(%rsp), %rax
shrl $0x10, %eax
movl 0x10(%rsp), %ecx
orl %ecx, %eax
movq %rax, 0x40(%rsp)
movq 0x58(%rsp), %rax
addl 0x30(%rsp), %eax
addl %ecx, %eax
movq 0x28(%rsp), %rcx
addl %ecx, %eax
addl $0x18, %eax
movq %rax, 0x28(%rsp)
xorl %eax, %eax
movl $0x0, 0x20(%rsp)
movq $0x0, 0x90(%rsp)
xorl %esi, %esi
movq %rax, 0xc8(%rsp)
movl %eax, %r15d
addq $0xfde, %r15            # imm = 0xFDE
movq 0xb8(%rsp), %rax
cmpq %rax, %r15
cmovaeq %rax, %r15
movl %esi, %ecx
shll $0xc, %ecx
movq %rcx, 0x8(%rsp)
addl $0xfde, %ecx            # imm = 0xFDE
cmpq %rcx, %rax
cmovbq %rax, %rcx
movq %rcx, 0x30(%rsp)
movq %rbx, %rdi
movl %esi, 0x1c(%rsp)
leaq 0xd0(%rsp), %rdx
callq 0x292233
xorl %r13d, %r13d
testl %eax, %eax
je 0x292037
xorl %r15d, %r15d
movl %eax, %r13d
jmp 0x2921d4
movq %r15, 0x10(%rsp)
movq 0x8(%rsp), %rsi
addl $-0x21, %esi
movl 0x1c(%rsp), %ecx
testl %ecx, %ecx
movl $0x1, %eax
cmovel %eax, %esi
movq 0x30(%rbx), %rax
movl %ecx, %edx
movq 0x98(%rsp), %rcx
movq %rcx, (%rax,%rdx,8)
movq 0x30(%rsp), %rax
cmpl %eax, %esi
seta %r15b
movq %rdx, 0xa8(%rsp)
ja 0x29218d
incq 0x10(%rsp)
movl %esi, %eax
movq %rax, 0x8(%rsp)
leaq -0x1(%rax), %rcx
imulq 0x28(%rsp), %rcx
addq $0x20, %rcx
xorl %r15d, %r15d
movl %r15d, 0x64(%rsp)
movq 0x10(%rbx), %rdi
movq (%rdi), %rax
movq 0x50(%rsp), %r15
movq %r15, %rsi
movq 0x48(%rsp), %rdx
movq %rcx, 0x58(%rsp)
callq *0x10(%rax)
xorl %r13d, %r13d
testl %eax, %eax
je 0x2920ff
xorl %ecx, %ecx
movl %eax, %r13d
movq 0x10(%rsp), %rdx
movq 0x8(%rsp), %r15
testb %cl, %cl
je 0x292188
cmpq 0x30(%rsp), %r15
leaq 0x1(%r15), %rax
setae %r15b
movq 0x58(%rsp), %rcx
addq 0x28(%rsp), %rcx
movq %rax, 0x8(%rsp)
cmpq %rax, %rdx
jne 0x29209a
jmp 0x29218d
movq %rbx, %rdi
leaq 0x6c(%rsp), %rsi
leaq 0x68(%rsp), %rdx
movq 0xc0(%rsp), %rcx
movq %r15, %r8
callq 0x2924fa
testl %eax, %eax
je 0x292147
movl 0x6c(%rsp), %edx
movq %rbx, %rdi
movq 0x8(%rsp), %r15
movl %r15d, %esi
callq 0x291158
xorl %r13d, %r13d
testl %eax, %eax
je 0x29214e
xorl %ecx, %ecx
movl %eax, %r13d
movq 0x10(%rsp), %rdx
jmp 0x2920d1
xorl %ecx, %ecx
jmp 0x2920c7
movl 0x68(%rsp), %eax
movb $0x1, %cl
testl %eax, %eax
movq 0x10(%rsp), %rdx
je 0x2920d1
movl %r15d, 0x58(%rbx)
movl %eax, 0x5c(%rbx)
movq 0x40(%rsp), %rax
movw %ax, 0x56(%rbx)
movl 0x60(%rbx), %eax
movl %eax, 0x20(%rsp)
movl 0x64(%rbx), %eax
movq %rax, 0x90(%rsp)
jmp 0x2920d1
movl 0x64(%rsp), %r15d
cmpl $0x0, 0x1c(%rsp)
movq 0xd0(%rsp), %rdi
movq 0x30(%rbx), %rax
movq 0xa8(%rsp), %rcx
movq %rdi, (%rax,%rcx,8)
movl $0x0, %eax
movl $0x88, %ecx
cmoveq %rcx, %rax
addq %rax, %rdi
movq 0x98(%rsp), %rcx
leaq (%rcx,%rax), %rsi
movl $0x8000, %edx           # imm = 0x8000
subq %rax, %rdx
callq 0x17660
testb $0x1, %r15b
movq 0xc8(%rsp), %rax
movl 0x1c(%rsp), %esi
je 0x2921fa
incl %esi
addl $0x1000, %eax           # imm = 0x1000
cmpl 0xb0(%rsp), %esi
jbe 0x291fd4
movq 0x50(%rsp), %rdi
callq 0x27c490
xorl %eax, %eax
movl 0x4(%rsp), %r15d
movq 0x90(%rsp), %rdx
movl 0x20(%rsp), %esi
jmp 0x291d07
movl $0x7, %r13d
movl $0x2, %eax
xorl %esi, %esi
movl 0x4(%rsp), %r15d
jmp 0x291b03