#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 scalar_t__ uint8_t;
typedef int uint32_t;
typedef int uint16_t;
typedef int int16_t;

/* Variables and functions */
int CRCEvaluate(scalar_t__ *, int);
int16_t CRCCheck(uint8_t *datablock, uint32_t datalength) {
  uint16_t crc;
  crc = 0;
  if (datalength <= 2)
    return (-1);
  crc = CRCEvaluate((uint8_t *)(datablock + 2), (uint32_t)(datalength - 2));
  if (((uint8_t)((crc & 0xFF00) >> 8) != (uint8_t)datablock[1]) ||
      ((uint8_t)(crc & 0x00FF) != (uint8_t)datablock[0]))
    return (0);
  else
    return (1);
}


x86 assembly (clang, -O0):
<CRCCheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x14(%rbp)
jg     113c <CRCCheck+0x2c>
movl   $0xffffffff,-0x4(%rbp)
jmp    1197 <CRCCheck+0x87>
mov    -0x10(%rbp),%rdi
add    $0x10,%rdi
mov    -0x14(%rbp),%esi
sub    $0x2,%esi
call   1030 <CRCEvaluate@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0xff00,%eax
sar    $0x8,%eax
cltq
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%rax
jne    1184 <CRCCheck+0x74>
mov    -0x18(%rbp),%eax
and    $0xff,%eax
cltq
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
je     1190 <CRCCheck+0x80>
movl   $0x0,-0x4(%rbp)
jmp    1197 <CRCCheck+0x87>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CRCCheck>:
push   %rbx
mov    $0xffffffff,%eax
cmp    $0x3,%esi
jl     1142 <CRCCheck+0x32>
mov    %rdi,%rbx
add    $0x10,%rdi
add    $0xfffffffe,%esi
call   1030 <CRCEvaluate@plt>
mov    %eax,%ecx
movzbl %ch,%edx
xor    %eax,%eax
cmp    %rdx,0x8(%rbx)
jne    1142 <CRCCheck+0x32>
movzbl %cl,%ecx
xor    %eax,%eax
cmp    %rcx,(%rbx)
sete   %al
pop    %rbx
ret

LLVM IR (-O0):
define i32 @CRCCheck(i64* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32
store i64* %0, i64** %4
store i32 %1, i32* %5
store i32 0, i32* %6
%7 = load i32, i32* %5
%8 = icmp sle i32 %7, 2
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %34
10: ; preds = %2
%11 = load i64*, i64** %4
%12 = getelementptr inbounds i64, i64* %11, i64 2
%13 = load i32, i32* %5
%14 = sub nsw i32 %13, 2
%15 = call i32 @CRCEvaluate(i64* %12, i32 %14)
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = and i32 %16, 65280
%18 = ashr i32 %17, 8
%19 = sext i32 %18 to i64
%20 = load i64*, i64** %4
%21 = getelementptr inbounds i64, i64* %20, i64 1
%22 = load i64, i64* %21
%23 = icmp ne i64 %19, %22
br i1 %23, label %32, label %24
24: ; preds = %10
%25 = load i32, i32* %6
%26 = and i32 %25, 255
%27 = sext i32 %26 to i64
%28 = load i64*, i64** %4
%29 = getelementptr inbounds i64, i64* %28, i64 0
%30 = load i64, i64* %29
%31 = icmp ne i64 %27, %30
br i1 %31, label %32, label %33
32: ; preds = %24, %10
store i32 0, i32* %3
br label %34
33: ; preds = %24
store i32 1, i32* %3
br label %34
34: ; preds = %33, %32, %9
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @CRCCheck(i64* %0, i32 %1) {
%3 = icmp slt i32 %1, 3
br i1 %3, label %20, label %4
4: ; preds = %2
%5 = getelementptr inbounds i64, i64* %0, i64 2
%6 = add nsw i32 %1, -2
%7 = tail call i32 @CRCEvaluate(i64* %5, i32 %6)
%8 = lshr i32 %7, 8
%9 = and i32 %8, 255
%10 = zext i32 %9 to i64
%11 = getelementptr inbounds i64, i64* %0, i64 1
%12 = load i64, i64* %11
%13 = icmp eq i64 %12, %10
br i1 %13, label %14, label %20
14: ; preds = %4
%15 = and i32 %7, 255
%16 = zext i32 %15 to i64
%17 = load i64, i64* %0
%18 = icmp eq i64 %17, %16
%19 = zext i1 %18 to i32
br label %20
20: ; preds = %14, %4, %2
%21 = phi i32 [ -1, %2 ], [ 0, %4 ], [ %19, %14 ]
ret i32 %21
}