// File: /workspace/github_c_makefile_star2_O0/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
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 0x3df0f0
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x3debea
cmpl $0x508, -0x1c(%rbp)     # imm = 0x508
jne 0x3debdd
movq -0x10(%rbp), %rax
movb $0x1, 0x46(%rax)
movq -0x10(%rbp), %rax
movb $0x2, 0x3f(%rax)
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x3debe8
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ded6c
jmp 0x3debec
jmp 0x3debec
cmpq $0x0, -0x28(%rbp)
je 0x3dec05
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3df160
movl %eax, -0x30(%rbp)
jmp 0x3dec0f
movl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3dec0f
movl -0x30(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x3ded09
movq -0x10(%rbp), %rax
movzbl 0x46(%rax), %eax
cmpl $0x0, %eax
jne 0x3dec69
movq -0x10(%rbp), %rax
movzbl 0x42(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x3dec69
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x3ded80
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x3dec64
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x3de740
movl $0x108, -0x1c(%rbp)     # imm = 0x108
jmp 0x3ded07
movq -0x10(%rbp), %rax
movzbl 0x40(%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x3dec95
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x3de5e0
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x3ded05
movq -0x10(%rbp), %rax
movb $0x1, 0x40(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
leaq -0x28(%rbp), %rdx
callq 0x3df0f0
movl %eax, %ecx
movl %ecx, -0x1c(%rbp)
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x3dece5
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3df160
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x3dece3
movq -0x10(%rbp), %rdi
callq 0x3df2a0
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
jmp 0x3dece5
cmpl $0x0, -0x2c(%rbp)
jne 0x3ded03
movq -0x10(%rbp), %rax
movb $0x0, 0x40(%rax)
movq -0x10(%rbp), %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0x3de700
jmp 0x3ded05
jmp 0x3ded07
jmp 0x3ded09
cmpl $0x0, -0x20(%rbp)
jne 0x3ded29
movq -0x10(%rbp), %rax
cmpl $0x2de218, 0x48(%rax)   # imm = 0x2DE218
je 0x3ded29
movl $0xf149, %edi           # imm = 0xF149
callq 0x3d80e0
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, 0x46(%rax)
je 0x3ded66
cmpl $0x0, -0x1c(%rbp)
je 0x3ded5e
movq -0x10(%rbp), %rdi
xorl %esi, %esi
callq 0x3df940
movq -0x10(%rbp), %rax
movb $0x0, 0x46(%rax)
cmpl $0x20a, -0x1c(%rbp)     # imm = 0x20A
jne 0x3ded5c
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
jmp 0x3ded5e
movq -0x10(%rbp), %rax
movb $0x0, 0x3f(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)