#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 */
int /*<<< orphan*/ create_16bit_table(unsigned short *);
int compute_16crc(char *message, int length) {
  unsigned short table[256];
  create_16bit_table(table);
  unsigned short result = 0xffff;
  short i = 1;
  while (i <= length) {
    unsigned char position = (unsigned char)((result >> 8) ^ message[i - 1]);
    result =
        (unsigned short)((result << 8) ^ (unsigned short)(table[position]));
    i++;
  }
  return (int)result;
}


x86 assembly (clang, -O0):
<compute_16crc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x210(%rbp),%rdi
call   1030 <create_16bit_table@plt>
movw   $0xffff,-0x212(%rbp)
ff ff
movw   $0x1,-0x214(%rbp)
movswl -0x214(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11b0 <compute_16crc+0xa0>
movzwl -0x212(%rbp),%eax
sar    $0x8,%eax
mov    -0x8(%rbp),%rcx
movswl -0x214(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
xor    %ecx,%eax
mov    %al,-0x215(%rbp)
movzwl -0x212(%rbp),%eax
shl    $0x8,%eax
movzbl -0x215(%rbp),%ecx
movzwl -0x210(%rbp,%rcx,2),%ecx
ff
xor    %ecx,%eax
mov    %ax,-0x212(%rbp)
mov    -0x214(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x214(%rbp)
jmp    1140 <compute_16crc+0x30>
movzwl -0x212(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_16crc>:
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rsp,%rdi
call   1030 <create_16bit_table@plt>
mov    $0xffff,%eax
test   %ebx,%ebx
jle    1166 <compute_16crc+0x56>
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,%edx
shr    $0x8,%edx
movslq %ecx,%rcx
xor    -0x1(%rcx,%r14,1),%dl
shl    $0x8,%eax
movzbl %dl,%edx
movzwl (%rsp,%rdx,2),%edx
movzwl %ax,%eax
xor    %edx,%eax
add    $0x1,%ecx
movswl %cx,%ecx
cmp    %ebx,%ecx
jle    1140 <compute_16crc+0x30>
add    $0x208,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @compute_16crc(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [256 x i16]
%6 = alloca i16
%7 = alloca i16
%8 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = getelementptr inbounds [256 x i16], [256 x i16]* %5, i64 0, i64 0
%10 = call i32 @create_16bit_table(i16* %9)
store i16 -1, i16* %6
store i16 1, i16* %7
br label %11
11: ; preds = %16, %2
%12 = load i16, i16* %7
%13 = sext i16 %12 to i32
%14 = load i32, i32* %4
%15 = icmp sle i32 %13, %14
br i1 %15, label %16, label %42
16: ; preds = %11
%17 = load i16, i16* %6
%18 = zext i16 %17 to i32
%19 = ashr i32 %18, 8
%20 = load i8*, i8** %3
%21 = load i16, i16* %7
%22 = sext i16 %21 to i32
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %20, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = xor i32 %19, %27
%29 = trunc i32 %28 to i8
store i8 %29, i8* %8
%30 = load i16, i16* %6
%31 = zext i16 %30 to i32
%32 = shl i32 %31, 8
%33 = load i8, i8* %8
%34 = zext i8 %33 to i64
%35 = getelementptr inbounds [256 x i16], [256 x i16]* %5, i64 0, i64 %34
%36 = load i16, i16* %35
%37 = zext i16 %36 to i32
%38 = xor i32 %32, %37
%39 = trunc i32 %38 to i16
store i16 %39, i16* %6
%40 = load i16, i16* %7
%41 = add i16 %40, 1
store i16 %41, i16* %7
br label %11
42: ; preds = %11
%43 = load i16, i16* %6
%44 = zext i16 %43 to i32
ret i32 %44
}

LLVM IR (-O2):
define i32 @compute_16crc(i8* nocapture %0, i32 %1) {
%3 = alloca [256 x i16]
%4 = bitcast [256 x i16]* %3 to i8*
%5 = getelementptr inbounds [256 x i16], [256 x i16]* %3, i64 0, i64 0
%6 = call i32 @create_16bit_table(i16* %5)
%7 = icmp slt i32 %1, 1
br i1 %7, label %29, label %8
8: ; preds = %2, %8
%9 = phi i32 [ %27, %8 ], [ 1, %2 ]
%10 = phi i32 [ %24, %8 ], [ 65535, %2 ]
%11 = lshr i32 %10, 8
%12 = add nsw i32 %9, -1
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = trunc i32 %11 to i8
%17 = xor i8 %15, %16
%18 = shl nsw i32 %10, 8
%19 = zext i8 %17 to i64
%20 = getelementptr inbounds [256 x i16], [256 x i16]* %3, i64 0, i64 %19
%21 = load i16, i16* %20
%22 = zext i16 %21 to i32
%23 = and i32 %18, 65280
%24 = xor i32 %23, %22
%25 = shl nsw i32 %9, 16
%26 = add i32 %25, 65536
%27 = ashr exact i32 %26, 16
%28 = icmp sgt i32 %27, %1
br i1 %28, label %29, label %8
29: ; preds = %8, %2
%30 = phi i32 [ 65535, %2 ], [ %24, %8 ]
ret i32 %30
}