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


x86 assembly (clang, -O0):
<hz_calc_crc16_1021>:
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)
mov    -0xe(%rbp),%ax
mov    %ax,-0x16(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    1171 <hz_calc_crc16_1021+0x61>
mov    -0x16(%rbp),%dx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
movzwl %dx,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <_hz_update_crc16_1021@plt>
mov    %ax,-0x16(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    113c <hz_calc_crc16_1021+0x2c>
movzwl -0x16(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define zeroext i16 @hz_calc_crc16_1021(i8* %0, i32 %1, i16 zeroext %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i16
%7 = alloca i32
%8 = alloca i16
store i8* %0, i8** %4
store i32 %1, i32* %5
store i16 %2, i16* %6
store i32 0, i32* %7
%9 = load i16, i16* %6
store i16 %9, i16* %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 i16, i16* %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 i16 @_hz_update_crc16_1021(i16 zeroext %15, i8 zeroext %20)
store i16 %21, i16* %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 i16, i16* %8
ret i16 %26
}

LLVM IR (-O2):
define zeroext i16 @hz_calc_crc16_1021(i8* nocapture %0, i32 %1, i16 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 i16 [ %2, %5 ], [ %12, %7 ]
%10 = getelementptr inbounds i8, i8* %0, i64 %8
%11 = load i8, i8* %10
%12 = tail call zeroext i16 @_hz_update_crc16_1021(i16 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 i16 [ %2, %3 ], [ %12, %7 ]
ret i16 %16
}