#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_32bit_table(unsigned int *);
int compute_32crc(char *message, int length) {
  unsigned int table[256];
  create_32bit_table(table);
  unsigned int result = 0xffffffff;
  short i = 1;
  while (i <= length) {
    unsigned short position =
        (unsigned char)((result ^ (message[i - 1] << 24)) >> 24);
    result = (unsigned int)((result << 8) ^ (unsigned int)(table[position]));
    i++;
  }
  return (int)result;
}


x86 assembly (clang, -O0):
<compute_32crc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x410(%rbp),%rdi
call   1030 <create_32bit_table@plt>
movl   $0xffffffff,-0x414(%rbp)
ff ff ff
movw   $0x1,-0x416(%rbp)
movswl -0x416(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11b2 <compute_32crc+0xa2>
mov    -0x414(%rbp),%eax
mov    -0x8(%rbp),%rcx
movswl -0x416(%rbp),%edx
sub    $0x1,%edx
movslq %edx,%rdx
movsbl (%rcx,%rdx,1),%ecx
shl    $0x18,%ecx
xor    %ecx,%eax
shr    $0x18,%eax
movzbl %al,%eax
mov    %ax,-0x418(%rbp)
mov    -0x414(%rbp),%eax
shl    $0x8,%eax
movzwl -0x418(%rbp),%ecx
xor    -0x410(%rbp,%rcx,4),%eax
mov    %eax,-0x414(%rbp)
mov    -0x416(%rbp),%ax
add    $0x1,%ax
mov    %ax,-0x416(%rbp)
jmp    1141 <compute_32crc+0x31>
mov    -0x414(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_32crc>:
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
mov    %rsp,%rdi
call   1030 <create_32bit_table@plt>
mov    $0xffffffff,%eax
test   %ebx,%ebx
jle    1161 <compute_32crc+0x51>
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nop
movslq %ecx,%rcx
movzbl -0x1(%rcx,%r14,1),%edx
shl    $0x18,%edx
xor    %eax,%edx
shr    $0x18,%edx
shl    $0x8,%eax
xor    (%rsp,%rdx,4),%eax
add    $0x1,%ecx
movswl %cx,%ecx
cmp    %ebx,%ecx
jle    1140 <compute_32crc+0x30>
add    $0x408,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @compute_32crc(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [256 x i32]
%6 = alloca i32
%7 = alloca i16
%8 = alloca i16
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = getelementptr inbounds [256 x i32], [256 x i32]* %5, i64 0, i64 0
%10 = call i32 @create_32bit_table(i32* %9)
store i32 -1, i32* %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 %40
16: ; preds = %11
%17 = load i32, i32* %6
%18 = load i8*, i8** %3
%19 = load i16, i16* %7
%20 = sext i16 %19 to i32
%21 = sub nsw i32 %20, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %18, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = shl i32 %25, 24
%27 = xor i32 %17, %26
%28 = lshr i32 %27, 24
%29 = trunc i32 %28 to i8
%30 = zext i8 %29 to i16
store i16 %30, i16* %8
%31 = load i32, i32* %6
%32 = shl i32 %31, 8
%33 = load i16, i16* %8
%34 = zext i16 %33 to i64
%35 = getelementptr inbounds [256 x i32], [256 x i32]* %5, i64 0, i64 %34
%36 = load i32, i32* %35
%37 = xor i32 %32, %36
store i32 %37, i32* %6
%38 = load i16, i16* %7
%39 = add i16 %38, 1
store i16 %39, i16* %7
br label %11
40: ; preds = %11
%41 = load i32, i32* %6
ret i32 %41
}

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