#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 aciCrcUpdate(unsigned short, unsigned char);
unsigned short aciUpdateCrc16(unsigned short crc, void *data,
                              unsigned short cnt) {
  unsigned short crcNew = crc;
  unsigned char *chrData = (unsigned char *)data;
  int i;
  for (i = 0; i < cnt; i++)
    crcNew = aciCrcUpdate(crcNew, chrData[i]);
  return crcNew;
}


x86 assembly (clang, -O0):
<aciUpdateCrc16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dx,%ax
mov    %di,%cx
mov    %cx,-0x2(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    -0x2(%rbp),%ax
mov    %ax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
movzwl -0x12(%rbp),%ecx
cmp    %ecx,%eax
jge    117a <aciUpdateCrc16+0x6a>
mov    -0x14(%rbp),%dx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movzwl %dx,%edi
movzbl (%rax,%rcx,1),%esi
call   1030 <aciCrcUpdate@plt>
mov    %ax,-0x14(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1141 <aciUpdateCrc16+0x31>
movzwl -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
define zeroext i16 @aciUpdateCrc16(i16 zeroext %0, i8* nocapture %1, i16 zeroext %2) {
%4 = icmp eq i16 %2, 0
br i1 %4, label %15, label %5
5: ; preds = %3
%6 = zext i16 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %13, %7 ]
%9 = phi i16 [ %0, %5 ], [ %12, %7 ]
%10 = getelementptr inbounds i8, i8* %1, i64 %8
%11 = load i8, i8* %10
%12 = tail call zeroext i16 @aciCrcUpdate(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 [ %0, %3 ], [ %12, %7 ]
ret i16 %16
}