#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ uint64_t;
typedef int uint16_t;

/* Variables and functions */
scalar_t__ memcmp(int /*<<< orphan*/ *, unsigned char *, int);
int /*<<< orphan*/ rl_crc64(int /*<<< orphan*/, unsigned char *, long);
int verify(unsigned char *data, long datalen) {
  unsigned char *footer;
  uint16_t rdbver;
  uint64_t crc;
  if (datalen < 10)
    return 5;
  footer = data + (datalen - 10);
  rdbver = (footer[1] << 8) | footer[0];
  if (rdbver != 6)
    return 5;
  crc = rl_crc64(0, data, datalen - 8);
  ;
  return (memcmp(&crc, footer + 2, 8) == 0) ? 0 : 5;
}


x86 assembly (clang, -O0):
<verify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0xa,-0x18(%rbp)
jge    1147 <verify+0x27>
movl   $0x5,-0x4(%rbp)
jmp    11c7 <verify+0xa7>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0xa,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movzbl 0x1(%rax),%eax
shl    $0x8,%eax
mov    -0x20(%rbp),%rcx
movzbl (%rcx),%ecx
or     %ecx,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x6,-0x24(%rbp)
je     1187 <verify+0x67>
movl   $0x5,-0x4(%rbp)
jmp    11c7 <verify+0xa7>
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
sub    $0x8,%rdx
xor    %edi,%edi
call   1040 <rl_crc64@plt>
mov    %eax,-0x28(%rbp)
mov    -0x20(%rbp),%rsi
add    $0x2,%rsi
lea    -0x28(%rbp),%rdi
mov    $0x8,%edx
call   1030 <memcmp@plt>
mov    %rax,%rdx
mov    $0x5,%eax
xor    %ecx,%ecx
cmp    $0x0,%rdx
cmove  %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<verify>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rdx
mov    $0x5,%eax
cmp    $0xa,%rsi
jl     1176 <verify+0x56>
mov    %rdi,%rsi
cmpw   $0x6,-0xa(%rdx,%rdi,1)
jne    1176 <verify+0x56>
lea    (%rdx,%rsi,1),%rbx
add    $0xfffffffffffffff6,%rbx
add    $0xfffffffffffffff8,%rdx
xor    %edi,%edi
call   1040 <rl_crc64@plt>
mov    %eax,0xc(%rsp)
add    $0x2,%rbx
lea    0xc(%rsp),%rdi
mov    %rbx,%rsi
mov    $0x8,%edx
call   1030 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,4),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @verify(i8* %0, i64 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i64 %1, i64* %5
%9 = load i64, i64* %5
%10 = icmp slt i64 %9, 10
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 5, i32* %3
br label %41
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = load i64, i64* %5
%15 = sub nsw i64 %14, 10
%16 = getelementptr inbounds i8, i8* %13, i64 %15
store i8* %16, i8** %6
%17 = load i8*, i8** %6
%18 = getelementptr inbounds i8, i8* %17, i64 1
%19 = load i8, i8* %18
%20 = zext i8 %19 to i32
%21 = shl i32 %20, 8
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = zext i8 %24 to i32
%26 = or i32 %21, %25
store i32 %26, i32* %7
%27 = load i32, i32* %7
%28 = icmp ne i32 %27, 6
br i1 %28, label %29, label %30
29: ; preds = %12
store i32 5, i32* %3
br label %41
30: ; preds = %12
%31 = load i8*, i8** %4
%32 = load i64, i64* %5
%33 = sub nsw i64 %32, 8
%34 = call i32 @rl_crc64(i32 0, i8* %31, i64 %33)
store i32 %34, i32* %8
%35 = load i8*, i8** %6
%36 = getelementptr inbounds i8, i8* %35, i64 2
%37 = call i64 @memcmp(i32* %8, i8* %36, i32 8)
%38 = icmp eq i64 %37, 0
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 0, i32 5
store i32 %40, i32* %3
br label %41
41: ; preds = %30, %29, %11
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
define i32 @verify(i8* %0, i64 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i64 %1, 10
br i1 %5, label %24, label %6
6: ; preds = %2
%7 = add nsw i64 %1, -10
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = shl nuw nsw i32 %11, 8
%13 = load i8, i8* %8
%14 = zext i8 %13 to i32
%15 = or i32 %12, %14
%16 = icmp eq i32 %15, 6
br i1 %16, label %17, label %24
17: ; preds = %6
%18 = add nsw i64 %1, -8
%19 = tail call i32 @rl_crc64(i32 0, i8* %0, i64 %18)
store i32 %19, i32* %3
%20 = getelementptr inbounds i8, i8* %8, i64 2
%21 = call i64 @memcmp(i32* %3, i8* %20, i32 8)
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, i32 0, i32 5
br label %24
24: ; preds = %6, %2, %17
%25 = phi i32 [ %23, %17 ], [ 5, %2 ], [ 5, %6 ]
ret i32 %25
}