#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_iter(unsigned char, unsigned short);
unsigned char full_crc8(unsigned char *data, int size, unsigned short seed) {
  int i;
  unsigned char curcrc = seed;
  for (i = 0; i < size; ++i) {
    curcrc = crc8_iter(curcrc, (unsigned short)data[i]);
  }
  return curcrc;
}


x86 assembly (clang, -O0):
<full_crc8>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %ax,-0xe(%rbp)
mov    -0xe(%rbp),%ax
mov    %al,-0x15(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116b <full_crc8+0x5b>
mov    -0x15(%rbp),%cl
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rdx
movzbl (%rax,%rdx,1),%eax
movzbl %cl,%edi
movzwl %ax,%esi
call   1030 <crc8_iter@plt>
mov    %al,-0x15(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1134 <full_crc8+0x24>
movzbl -0x15(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<full_crc8>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%eax
test   %esi,%esi
jle    1146 <full_crc8+0x36>
mov    %rdi,%r14
mov    %esi,%r15d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%r14,%rbx,1),%esi
movzbl %al,%edi
call   1030 <crc8_iter@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <full_crc8+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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