// File: /workspace/github_c_makefile_star2_O1/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: walIndexTryHdr
static int walIndexTryHdr(Wal *pWal, int *pChanged){
  u32 aCksum[2];                  /* Checksum on the header content */
  WalIndexHdr h1, h2;             /* Two copies of the header content */
  WalIndexHdr volatile *aHdr;     /* Header in shared memory */

  /* The first page of the wal-index must be mapped at this point. */
  assert( pWal->nWiData>0 && pWal->apWiData[0] );

  /* Read the header. This might happen concurrently with a write to the
  ** same area of shared memory on a different CPU in a SMP,
  ** meaning it is possible that an inconsistent snapshot is read
  ** from the file. If this happens, return non-zero.
  **
  ** There are two copies of the header at the beginning of the wal-index.
  ** When reading, read [0] first then [1].  Writes are in the reverse order.
  ** Memory barriers are used to prevent the compiler or the hardware from
  ** reordering the reads and writes.
  */
  aHdr = walIndexHdr(pWal);
  memcpy(&h1, (void *)&aHdr[0], sizeof(h1));
  walShmBarrier(pWal);
  memcpy(&h2, (void *)&aHdr[1], sizeof(h2));

  if( memcmp(&h1, &h2, sizeof(h1))!=0 ){
    return 1;   /* Dirty read */
  }  
  if( h1.isInit==0 ){
    return 1;   /* Malformed header - probably all zeros */
  }
  walChecksumBytes(1, (u8*)&h1, sizeof(h1)-sizeof(h1.aCksum), 0, aCksum);
  if( aCksum[0]!=h1.aCksum[0] || aCksum[1]!=h1.aCksum[1] ){
    return 1;   /* Checksum does not match */
  }

  if( memcmp(&pWal->hdr, &h1, sizeof(WalIndexHdr)) ){
    *pChanged = 1;
    memcpy(&pWal->hdr, &h1, sizeof(WalIndexHdr));
    pWal->szPage = (pWal->hdr.szPage&0xfe00) + ((pWal->hdr.szPage&0x0001)<<16);
    testcase( pWal->szPage<=32768 );
    testcase( pWal->szPage>=65536 );
  }

  /* The header was successfully read. Return zero. */
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x30(%rdi), %rax
movq (%rax), %r15
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movaps %xmm2, -0x30(%rbp)
movaps %xmm1, -0x40(%rbp)
movaps %xmm0, -0x50(%rbp)
cmpb $0x2, 0x3f(%rdi)
je 0x1c214
movq 0x8(%rbx), %rdi
movq (%rdi), %rax
callq *0x78(%rax)
movups 0x30(%r15), %xmm0
movups 0x40(%r15), %xmm1
movups 0x50(%r15), %xmm2
leaq -0x80(%rbp), %rsi
movaps %xmm2, 0x20(%rsi)
movaps %xmm1, 0x10(%rsi)
movaps %xmm0, (%rsi)
leaq -0x50(%rbp), %rdi
movl $0x30, %edx
callq 0x8410
movl %eax, %ecx
movl $0x1, %eax
testl %ecx, %ecx
jne 0x1c2d2
cmpb $0x0, -0x44(%rbp)
je 0x1c2d2
xorl %ecx, %ecx
movq $-0x8, %rdx
xorl %esi, %esi
addl %ecx, %esi
addl -0x48(%rbp,%rdx), %esi
addl -0x44(%rbp,%rdx), %ecx
addl %esi, %ecx
addq $0x8, %rdx
cmpq $0x20, %rdx
jb 0x1c260
cmpl -0x28(%rbp), %esi
jne 0x1c2d2
cmpl -0x24(%rbp), %ecx
jne 0x1c2d2
leaq 0x48(%rbx), %r15
leaq -0x50(%rbp), %rsi
movl $0x30, %edx
movq %r15, %rdi
callq 0x8410
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
je 0x1c2d2
movl $0x1, (%r14)
movaps -0x50(%rbp), %xmm0
movaps -0x40(%rbp), %xmm1
movaps -0x30(%rbp), %xmm2
movups %xmm2, 0x20(%r15)
movups %xmm1, 0x10(%r15)
movups %xmm0, (%r15)
movzwl 0x56(%rbx), %ecx
movl %ecx, %edx
shll $0x10, %edx
orl %ecx, %edx
andl $0x1fe00, %edx          # imm = 0x1FE00
movl %edx, 0x38(%rbx)
addq $0x68, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq