#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 short _hz_update_crc16_sick(unsigned short, unsigned char const, char);
unsigned short hz_calc_crc16_sick(const unsigned char *pSrc, unsigned int len,
                                  unsigned short crc16) {
  unsigned int i = 0;
  char prev_byte = 0x00;
  unsigned short crc = crc16;
  for (i = 0; i < len; i++) {
    crc = _hz_update_crc16_sick(crc, pSrc[i], prev_byte);
    prev_byte = pSrc[i];
  }
  return crc;
}


x86 assembly (clang, -O0):
<hz_calc_crc16_sick>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %ax,-0xe(%rbp)
movl   $0x0,-0x14(%rbp)
movb   $0x0,-0x15(%rbp)
mov    -0xe(%rbp),%ax
mov    %ax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1188 <hz_calc_crc16_sick+0x78>
mov    -0x18(%rbp),%cx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%edx
mov    (%rax,%rdx,1),%al
movzwl %cx,%edi
movzbl %al,%esi
movsbl -0x15(%rbp),%edx
call   1030 <_hz_update_crc16_sick@plt>
mov    %ax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1140 <hz_calc_crc16_sick+0x30>
movzwl -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hz_calc_crc16_sick>:
push   %r15
push   %r14
push   %rbx
mov    %edx,%eax
test   %esi,%esi
je     114e <hz_calc_crc16_sick+0x3e>
mov    %rdi,%r15
mov    %esi,%r14d
xor    %ebx,%ebx
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r15,%rbx,1),%esi
movzwl %ax,%edi
movsbl %cl,%edx
call   1030 <_hz_update_crc16_sick@plt>
movzbl (%r15,%rbx,1),%ecx
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <hz_calc_crc16_sick+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

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

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