// File: /workspace/github_c_makefile_star2_O0/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
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x23680
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rsi
leaq -0x50(%rbp), %rdi
movl $0x30, %edx
callq 0x82f0
movq -0x10(%rbp), %rdi
callq 0x23650
movq -0x88(%rbp), %rsi
addq $0x30, %rsi
leaq -0x80(%rbp), %rdi
movl $0x30, %edx
callq 0x82f0
leaq -0x50(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0x30, %edx
callq 0x81c0
cmpl $0x0, %eax
je 0x238ad
movl $0x1, -0x4(%rbp)
jmp 0x2395d
movzbl -0x44(%rbp), %eax
cmpl $0x0, %eax
jne 0x238c2
movl $0x1, -0x4(%rbp)
jmp 0x2395d
leaq -0x20(%rbp), %r8
movl $0x1, %edi
leaq -0x50(%rbp), %rsi
movl $0x28, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x22b70
movl -0x20(%rbp), %eax
cmpl -0x28(%rbp), %eax
jne 0x238ed
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
je 0x238f6
movl $0x1, -0x4(%rbp)
jmp 0x2395d
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
leaq -0x50(%rbp), %rsi
movl $0x30, %edx
callq 0x81c0
cmpl $0x0, %eax
je 0x23956
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
leaq -0x50(%rbp), %rsi
movl $0x30, %edx
callq 0x82f0
movq -0x10(%rbp), %rax
movzwl 0x56(%rax), %ecx
andl $0xfe00, %ecx           # imm = 0xFE00
movq -0x10(%rbp), %rax
movzwl 0x56(%rax), %eax
andl $0x1, %eax
shll $0x10, %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x38(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)