#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 crc16_add(unsigned char const, unsigned short);
unsigned short crc16_data(const void *data_v, int len, unsigned short acc) {
  int i;
  const unsigned char *data = data_v;
  for (i = 0; i < len; ++i) {
    acc = crc16_add(*data, acc);
    ++data;
  }
  return acc;
}


x86 assembly (clang, -O0):
<crc16_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %ax,-0xe(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1171 <crc16_data+0x61>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
movzbl %al,%edi
movzwl -0xe(%rbp),%esi
call   1030 <crc16_add@plt>
mov    %ax,-0xe(%rbp)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1135 <crc16_data+0x25>
movzwl -0xe(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
define zeroext i16 @crc16_data(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 i8*, i8** %4
store i8* %9, i8** %8
store i32 0, i32* %7
br label %10
10: ; preds = %21, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %5
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i8*, i8** %8
%16 = load i8, i8* %15
%17 = load i16, i16* %6
%18 = call zeroext i16 @crc16_add(i8 zeroext %16, i16 zeroext %17)
store i16 %18, i16* %6
%19 = load i8*, i8** %8
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %8
br label %21
21: ; preds = %14
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
store i32 %23, i32* %7
br label %10
24: ; preds = %10
%25 = load i16, i16* %6
ret i16 %25
}

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