#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 int8_t;

/* Variables and functions */
int /*<<< orphan*/ apb_crc16(scalar_t__ *, scalar_t__ *, int);
int8_t apb_checkCrc(uint8_t *message, int length) {
  uint8_t crc[2] = {0, 0};
  apb_crc16(message, crc, length);
  if ((message[length - 2] == crc[0]) && (message[length - 1] == crc[1]))
    return -1;
  else
    return 0;
}


x86 assembly (clang, -O0):
<apb_checkCrc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <apb_crc16@plt>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x30(%rbp),%rax
jne    1191 <apb_checkCrc+0x71>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
cmp    -0x28(%rbp),%rax
jne    1191 <apb_checkCrc+0x71>
movl   $0xffffffff,-0x4(%rbp)
jmp    1198 <apb_checkCrc+0x78>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<apb_checkCrc>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edx
call   1030 <apb_crc16@plt>
movslq %ebp,%rax
mov    -0x10(%rbx,%rax,8),%rcx
cmp    (%rsp),%rcx
jne    114b <apb_checkCrc+0x3b>
mov    -0x8(%rbx,%rax,8),%rcx
mov    $0xffffffff,%eax
cmp    0x8(%rsp),%rcx
je     114d <apb_checkCrc+0x3d>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @apb_checkCrc(i64* %0, i32 %1) {
%3 = alloca [2 x i64]
%4 = bitcast [2 x i64]* %3 to i8*
%5 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 0
%6 = call i32 @apb_crc16(i64* %0, i64* %5, i32 %1)
%7 = add nsw i32 %1, -2
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds i64, i64* %0, i64 %8
%10 = load i64, i64* %9
%11 = load i64, i64* %5
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = add nsw i32 %1, -1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i64, i64* %0, i64 %15
%17 = load i64, i64* %16
%18 = getelementptr inbounds [2 x i64], [2 x i64]* %3, i64 0, i64 1
%19 = load i64, i64* %18
%20 = icmp eq i64 %17, %19
br i1 %20, label %22, label %21
21: ; preds = %13, %2
br label %22
22: ; preds = %13, %21
%23 = phi i32 [ 0, %21 ], [ -1, %13 ]
ret i32 %23
}