#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 _hz_update_crc7_12(unsigned char, unsigned char const);
unsigned char hz_calc_crc7_12(const unsigned char *pSrc, unsigned int len,
                              unsigned char crc7) {
  unsigned int i = 0;
  unsigned char crc = crc7;
  for (i = 0; i < len; i++) {
    crc = _hz_update_crc7_12(crc, pSrc[i]);
  }
  return crc;
}


x86 assembly (clang, -O0):
<hz_calc_crc7_12>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %al,-0xd(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xd(%rbp),%al
mov    %al,-0x15(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    116b <hz_calc_crc7_12+0x5b>
mov    -0x15(%rbp),%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movzbl %dl,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <_hz_update_crc7_12@plt>
mov    %al,-0x15(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1138 <hz_calc_crc7_12+0x28>
movzbl -0x15(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hz_calc_crc7_12>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%eax
test   %esi,%esi
je     1146 <hz_calc_crc7_12+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 <_hz_update_crc7_12@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1130 <hz_calc_crc7_12+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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