#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 augment_message_for_crc(unsigned short);
unsigned short update_crc(unsigned char, unsigned short);
unsigned short getCRC(unsigned char *buffer, int length) {
  unsigned short crcValue = 0xffff;
  int i = 0;
  for (i = 0; i < length; i++) {
    crcValue = update_crc(buffer[i], crcValue);
  }
  crcValue = augment_message_for_crc(crcValue);
  return crcValue;
}


x86 assembly (clang, -O0):
<getCRC>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movw   $0xffff,-0xe(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1178 <getCRC+0x58>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,1),%al
movzbl %al,%edi
movzwl -0xe(%rbp),%esi
call   1040 <update_crc@plt>
mov    %ax,-0xe(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <getCRC+0x23>
movzwl -0xe(%rbp),%edi
call   1030 <augment_message_for_crc@plt>
mov    %ax,-0xe(%rbp)
movzwl -0xe(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCRC>:
push   %r15
push   %r14
push   %rbx
test   %esi,%esi
jle    1158 <getCRC+0x38>
mov    %rdi,%r14
mov    %esi,%r15d
mov    $0xffff,%ax
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl (%r14,%rbx,1),%edi
movzwl %ax,%esi
call   1040 <update_crc@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1140 <getCRC+0x20>
jmp    115c <getCRC+0x3c>
mov    $0xffff,%ax
movzwl %ax,%edi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <augment_message_for_crc@plt>

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

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