#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 */

/* Variables and functions */
unsigned short crcsum(unsigned char const *, unsigned long, int);
int crcverify(const unsigned char *message, unsigned long length) {
  unsigned short expected;
  expected = crcsum(message, length - 2, 0xFFFF);
  return (expected & 0xff) == message[length - 2] &&
         ((expected >> 8) & 0xff) == message[length - 1];
}


x86 assembly (clang, -O0):
<crcverify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
sub    $0x2,%rsi
mov    $0xffff,%edx
call   1030 <crcsum@plt>
mov    %ax,-0x12(%rbp)
movzwl -0x12(%rbp),%ecx
and    $0xff,%ecx
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdx
sub    $0x2,%rdx
movzbl (%rax,%rdx,1),%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x13(%rbp)
jne    1185 <crcverify+0x75>
movzwl -0x12(%rbp),%eax
sar    $0x8,%eax
and    $0xff,%eax
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
movzbl (%rcx,%rdx,1),%ecx
cmp    %ecx,%eax
sete   %al
mov    %al,-0x13(%rbp)
mov    -0x13(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crcverify>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0xfffffffffffffffe,%rsi
mov    $0xffff,%edx
call   1030 <crcsum@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    %cl,-0x2(%rbx,%r14,1)
jne    1147 <crcverify+0x37>
movzwl %cx,%ecx
shr    $0x8,%ecx
movzbl -0x1(%r14,%rbx,1),%edx
xor    %eax,%eax
cmp    %dx,%cx
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @crcverify(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i16
store i8* %0, i8** %3
store i64 %1, i64* %4
%6 = load i8*, i8** %3
%7 = load i64, i64* %4
%8 = sub i64 %7, 2
%9 = call zeroext i16 @crcsum(i8* %6, i64 %8, i32 65535)
store i16 %9, i16* %5
%10 = load i16, i16* %5
%11 = zext i16 %10 to i32
%12 = and i32 %11, 255
%13 = load i8*, i8** %3
%14 = load i64, i64* %4
%15 = sub i64 %14, 2
%16 = getelementptr inbounds i8, i8* %13, i64 %15
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = icmp eq i32 %12, %18
br i1 %19, label %20, label %32
20: ; preds = %2
%21 = load i16, i16* %5
%22 = zext i16 %21 to i32
%23 = ashr i32 %22, 8
%24 = and i32 %23, 255
%25 = load i8*, i8** %3
%26 = load i64, i64* %4
%27 = sub i64 %26, 1
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = zext i8 %29 to i32
%31 = icmp eq i32 %24, %30
br label %32
32: ; preds = %20, %2
%33 = phi i1 [ false, %2 ], [ %31, %20 ]
%34 = zext i1 %33 to i32
ret i32 %34
}

LLVM IR (-O2):
define i32 @crcverify(i8* %0, i64 %1) {
%3 = add i64 %1, -2
%4 = tail call zeroext i16 @crcsum(i8* %0, i64 %3, i32 65535)
%5 = getelementptr inbounds i8, i8* %0, i64 %3
%6 = load i8, i8* %5
%7 = trunc i16 %4 to i8
%8 = icmp eq i8 %6, %7
br i1 %8, label %9, label %17
9: ; preds = %2
%10 = lshr i16 %4, 8
%11 = add i64 %1, -1
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = zext i8 %13 to i16
%15 = icmp eq i16 %10, %14
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %9, %2
%18 = phi i32 [ 0, %2 ], [ %16, %9 ]
ret i32 %18
}