#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 uint8_t;
typedef int uint16_t;
typedef int int8_t;

/* Variables and functions */
int CRCCCITT(int *, int, int, int);
int8_t check_crc16(uint8_t *buffer) {
  uint16_t crc = CRCCCITT(buffer, 10, 0xffff, 0xffff);
  uint8_t crch = buffer[10];
  uint8_t crcl = buffer[11];
  if (crc >> 8 == crch && (crc & 0xff) == crcl)
    return 0;
  else
    return -1;
}


x86 assembly (clang, -O0):
<check_crc16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
mov    $0xffff,%ecx
mov    %ecx,%edx
call   1030 <CRCCCITT@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2c(%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
sar    $0x8,%eax
cmp    -0x18(%rbp),%eax
jne    1174 <check_crc16+0x64>
mov    -0x14(%rbp),%eax
and    $0xff,%eax
cmp    -0x1c(%rbp),%eax
jne    1174 <check_crc16+0x64>
movl   $0x0,-0x4(%rbp)
jmp    117b <check_crc16+0x6b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_crc16>:
push   %rbx
mov    %rdi,%rbx
mov    $0xa,%esi
mov    $0xffff,%edx
mov    $0xffff,%ecx
call   1030 <CRCCCITT@plt>
mov    %eax,%ecx
sar    $0x8,%ecx
cmp    0x28(%rbx),%ecx
jne    113c <check_crc16+0x2c>
movzbl %al,%ecx
xor    %eax,%eax
cmp    0x2c(%rbx),%ecx
je     1141 <check_crc16+0x31>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
define i32 @check_crc16(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
%7 = load i32*, i32** %3
%8 = call i32 @CRCCCITT(i32* %7, i32 10, i32 65535, i32 65535)
store i32 %8, i32* %4
%9 = load i32*, i32** %3
%10 = getelementptr inbounds i32, i32* %9, i64 10
%11 = load i32, i32* %10
store i32 %11, i32* %5
%12 = load i32*, i32** %3
%13 = getelementptr inbounds i32, i32* %12, i64 11
%14 = load i32, i32* %13
store i32 %14, i32* %6
%15 = load i32, i32* %4
%16 = ashr i32 %15, 8
%17 = load i32, i32* %5
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %25
19: ; preds = %1
%20 = load i32, i32* %4
%21 = and i32 %20, 255
%22 = load i32, i32* %6
%23 = icmp eq i32 %21, %22
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %2
br label %26
25: ; preds = %19, %1
store i32 -1, i32* %2
br label %26
26: ; preds = %25, %24
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
define i32 @check_crc16(i32* %0) {
%2 = tail call i32 @CRCCCITT(i32* %0, i32 10, i32 65535, i32 65535)
%3 = getelementptr inbounds i32, i32* %0, i64 10
%4 = load i32, i32* %3
%5 = ashr i32 %2, 8
%6 = icmp eq i32 %5, %4
br i1 %6, label %7, label %12
7: ; preds = %1
%8 = getelementptr inbounds i32, i32* %0, i64 11
%9 = load i32, i32* %8
%10 = and i32 %2, 255
%11 = icmp eq i32 %10, %9
br i1 %11, label %13, label %12
12: ; preds = %7, %1
br label %13
13: ; preds = %7, %12
%14 = phi i32 [ -1, %12 ], [ 0, %7 ]
ret i32 %14
}