#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 char crc8(unsigned char, unsigned char);
unsigned char data_crc8(unsigned char *dataframe) {
  unsigned char i, crc = 0;
  unsigned char *len = dataframe;
  for (i = 0; i < *len; i++) {
    crc = crc8(crc, dataframe[i + 1]);
  }
  return crc ^ 0xff;
}


x86 assembly (clang, -O0):
<data_crc8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0xa(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movb   $0x0,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
mov    -0x18(%rbp),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jge    116c <data_crc8+0x5c>
mov    -0xa(%rbp),%dl
mov    -0x8(%rbp),%rax
movzbl -0x9(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movzbl %dl,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <crc8@plt>
mov    %al,-0xa(%rbp)
mov    -0x9(%rbp),%al
add    $0x1,%al
mov    %al,-0x9(%rbp)
jmp    112c <data_crc8+0x1c>
movzbl -0xa(%rbp),%eax
xor    $0xff,%eax
movzbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<data_crc8>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     113f <data_crc8+0x2f>
mov    %rdi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
movzbl 0x1(%r14,%rbx,1),%esi
add    $0x1,%rbx
movzbl %al,%edi
call   1030 <crc8@plt>
movzbl (%r14),%ecx
cmp    %rcx,%rbx
jb     1120 <data_crc8+0x10>
not    %al
jmp    1141 <data_crc8+0x31>
mov    $0xff,%al
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define zeroext i8 @data_crc8(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8*
store i8* %0, i8** %2
store i8 0, i8* %4
%6 = load i8*, i8** %2
store i8* %6, i8** %5
store i8 0, i8* %3
br label %7
7: ; preds = %24, %1
%8 = load i8, i8* %3
%9 = zext i8 %8 to i32
%10 = load i8*, i8** %5
%11 = load i8, i8* %10
%12 = zext i8 %11 to i32
%13 = icmp slt i32 %9, %12
br i1 %13, label %14, label %27
14: ; preds = %7
%15 = load i8, i8* %4
%16 = load i8*, i8** %2
%17 = load i8, i8* %3
%18 = zext i8 %17 to i32
%19 = add nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %16, i64 %20
%22 = load i8, i8* %21
%23 = call zeroext i8 @crc8(i8 zeroext %15, i8 zeroext %22)
store i8 %23, i8* %4
br label %24
24: ; preds = %14
%25 = load i8, i8* %3
%26 = add i8 %25, 1
store i8 %26, i8* %3
br label %7
27: ; preds = %7
%28 = load i8, i8* %4
%29 = zext i8 %28 to i32
%30 = xor i32 %29, 255
%31 = trunc i32 %30 to i8
ret i8 %31
}

LLVM IR (-O2):
define zeroext i8 @data_crc8(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %16, label %4
4: ; preds = %1, %4
%5 = phi i64 [ %7, %4 ], [ 0, %1 ]
%6 = phi i8 [ %10, %4 ], [ 0, %1 ]
%7 = add nuw nsw i64 %5, 1
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = tail call zeroext i8 @crc8(i8 zeroext %6, i8 zeroext %9)
%11 = load i8, i8* %0
%12 = zext i8 %11 to i64
%13 = icmp ult i64 %7, %12
br i1 %13, label %4, label %14
14: ; preds = %4
%15 = xor i8 %10, -1
br label %16
16: ; preds = %14, %1
%17 = phi i8 [ -1, %1 ], [ %15, %14 ]
ret i8 %17
}