// File: /workspace/github_c_makefile_star2_O0/barabo[P]advanced-shell-history/src/sqlite3.c
// Function: walDecodeFrame
static int walDecodeFrame(
  Wal *pWal,                      /* The write-ahead log */
  u32 *piPage,                    /* OUT: Database page number for frame */
  u32 *pnTruncate,                /* OUT: New db size (or 0 if not commit) */
  u8 *aData,                      /* Pointer to page data (for checksum) */
  u8 *aFrame                      /* Frame data */
){
  int nativeCksum;                /* True for native byte-order checksums */
  u32 *aCksum = pWal->hdr.aFrameCksum;
  u32 pgno;                       /* Page number of the frame */
  assert( WAL_FRAME_HDRSIZE==24 );

  /* A frame is only valid if the salt values in the frame-header
  ** match the salt values in the wal-header. 
  */
  if( memcmp(&pWal->hdr.aSalt, &aFrame[8], 8)!=0 ){
    return 0;
  }

  /* A frame is only valid if the page number is creater than zero.
  */
  pgno = sqlite3Get4byte(&aFrame[0]);
  if( pgno==0 ){
    return 0;
  }

  /* A frame is only valid if a checksum of the WAL header,
  ** all prior frams, the first 16 bytes of this frame-header, 
  ** and the frame-data matches the checksum in the last 8 
  ** bytes of this frame-header.
  */
  nativeCksum = (pWal->hdr.bigEndCksum==SQLITE_BIGENDIAN);
  walChecksumBytes(nativeCksum, aFrame, 8, aCksum, aCksum);
  walChecksumBytes(nativeCksum, aData, pWal->szPage, aCksum, aCksum);
  if( aCksum[0]!=sqlite3Get4byte(&aFrame[16]) 
   || aCksum[1]!=sqlite3Get4byte(&aFrame[20]) 
  ){
    /* Checksum failed. */
    return 0;
  }

  /* If we reach this point, the frame is valid.  Return the page number
  ** and the new database size.
  */
  *piPage = pgno;
  *pnTruncate = sqlite3Get4byte(&aFrame[4]);
  return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq -0x10(%rbp), %rax
addq $0x48, %rax
addq $0x18, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
addq $0x48, %rax
addq $0x20, %rax
movq -0x30(%rbp), %rcx
addq $0x8, %rcx
movq (%rcx), %rcx
movq (%rax), %rax
subq %rcx, %rax
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x23ed0
movl $0x0, -0x4(%rbp)
jmp 0x23fa5
movq -0x30(%rbp), %rdi
callq 0x20a50
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x23eee
movl $0x0, -0x4(%rbp)
jmp 0x23fa5
movq -0x10(%rbp), %rax
movzbl 0x55(%rax), %eax
cmpl $0x0, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %edi
movq -0x30(%rbp), %rsi
movq -0x40(%rbp), %rcx
movq -0x40(%rbp), %r8
movl $0x8, %edx
callq 0x22b70
movl -0x34(%rbp), %edi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x38(%rax), %edx
movq -0x40(%rbp), %rcx
movq -0x40(%rbp), %r8
callq 0x22b70
movq -0x40(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x48(%rbp)
movq -0x30(%rbp), %rdi
addq $0x10, %rdi
callq 0x20a50
movl %eax, %ecx
movl -0x48(%rbp), %eax
cmpl %ecx, %eax
jne 0x23f77
movq -0x40(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x30(%rbp), %rdi
addq $0x14, %rdi
callq 0x20a50
movl %eax, %ecx
movl -0x4c(%rbp), %eax
cmpl %ecx, %eax
je 0x23f80
movl $0x0, -0x4(%rbp)
jmp 0x23fa5
movl -0x44(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rdi
addq $0x4, %rdi
callq 0x20a50
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nop