#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_iter(unsigned short, unsigned short);
unsigned short full_crc16(unsigned char *data, int size, unsigned short seed) {
  int i;
  unsigned short curcrc = seed;
  for (i = 0; i < size; ++i) {
    curcrc = crc16_iter(curcrc, (unsigned short)data[i]);
  }
  return curcrc;
}


x86 assembly (clang, -O0):
<full_crc16>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dx,%ax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %ax,-0xe(%rbp)
mov    -0xe(%rbp),%ax
mov    %ax,-0x16(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116e <full_crc16+0x5e>
mov    -0x16(%rbp),%cx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rdx
movzbl (%rax,%rdx,1),%eax
movzwl %cx,%edi
movzwl %ax,%esi
call   1030 <crc16_iter@plt>
mov    %ax,-0x16(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1135 <full_crc16+0x25>
movzwl -0x16(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

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

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

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