#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*/ printf(char *);
unsigned long int crc32(unsigned long long int value, int num_bits,
                        unsigned long int crc_in) {
  if ((1 > num_bits) || (num_bits > 64)) {
    printf("ERROR: Max 64 bits of CRC can be computed. Ignored\n");
    return crc_in;
  }
  static const unsigned long int CRC32_POLY = 0x04c11db7;
  int i;
  for (i = num_bits - 1; i >= 0; i--) {
    unsigned long int d;
    unsigned long int t;
    d = (1 == ((value >> i) & 1)) ? 0xfffffff : 0x0000000;
    t = (1 == ((crc_in >> 31) & 1)) ? 0xfffffff : 0x0000000;
    crc_in <<= 1;
    crc_in ^= (d ^ t) & CRC32_POLY;
  }
  return crc_in;
}


x86 assembly (clang, -O0):
<crc32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    $0x1,%eax
cmp    -0x14(%rbp),%eax
jg     113b <crc32+0x2b>
cmpl   $0x40,-0x14(%rbp)
jle    1154 <crc32+0x44>
lea    0xebe(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11eb <crc32+0xdb>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     11e3 <crc32+0xd3>
mov    -0x10(%rbp),%rsi
mov    -0x24(%rbp),%eax
mov    %eax,%ecx
shr    %cl,%rsi
and    $0x1,%rsi
mov    $0x1,%edx
xor    %eax,%eax
mov    $0xfffffff,%ecx
cmp    %rsi,%rdx
cmove  %ecx,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rsi
shr    $0x1f,%rsi
and    $0x1,%rsi
mov    $0x1,%edx
xor    %eax,%eax
mov    $0xfffffff,%ecx
cmp    %rsi,%rdx
cmove  %ecx,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
xor    -0x38(%rbp),%rax
and    $0x4c11db7,%rax
xor    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    115d <crc32+0x4d>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc32>:
push   %rbx
mov    %rdx,%rbx
lea    -0x41(%rsi),%eax
cmp    $0xffffffc0,%eax
jae    112a <crc32+0x1a>
lea    0xedd(%rip),%rdi
call   1030 <puts@plt>
jmp    1173 <crc32+0x63>
mov    %esi,%eax
add    $0x1,%rax
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x2(%rax),%edx
movzbl %dl,%edx
bt     %rdx,%rdi
mov    $0x4c11db7,%edx
cmovae %rcx,%rdx
movslq %ebx,%rsi
shr    $0x1f,%rsi
and    $0x4c11db7,%esi
add    %rbx,%rbx
xor    %rsi,%rbx
xor    %rdx,%rbx
add    $0xffffffffffffffff,%rax
cmp    $0x1,%rax
ja     1140 <crc32+0x30>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [52 x i8] c"ERROR: Max 64 bits of CRC can be computed. Ignored\0A\00"
@crc32.CRC32_POLY = internal constant i64 79764919
define i64 @crc32(i64 %0, i32 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
store i64 %0, i64* %5
store i32 %1, i32* %6
store i64 %2, i64* %7
%11 = load i32, i32* %6
%12 = icmp sgt i32 1, %11
br i1 %12, label %16, label %13
13: ; preds = %3
%14 = load i32, i32* %6
%15 = icmp sgt i32 %14, 64
br i1 %15, label %16, label %19
16: ; preds = %13, %3
%17 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str, i64 0, i64 0))
%18 = load i64, i64* %7
store i64 %18, i64* %4
br label %55
19: ; preds = %13
%20 = load i32, i32* %6
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %8
br label %22
22: ; preds = %50, %19
%23 = load i32, i32* %8
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %53
25: ; preds = %22
%26 = load i64, i64* %5
%27 = load i32, i32* %8
%28 = zext i32 %27 to i64
%29 = lshr i64 %26, %28
%30 = and i64 %29, 1
%31 = icmp eq i64 1, %30
%32 = zext i1 %31 to i64
%33 = select i1 %31, i32 268435455, i32 0
%34 = sext i32 %33 to i64
store i64 %34, i64* %9
%35 = load i64, i64* %7
%36 = lshr i64 %35, 31
%37 = and i64 %36, 1
%38 = icmp eq i64 1, %37
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 268435455, i32 0
%41 = sext i32 %40 to i64
store i64 %41, i64* %10
%42 = load i64, i64* %7
%43 = shl i64 %42, 1
store i64 %43, i64* %7
%44 = load i64, i64* %9
%45 = load i64, i64* %10
%46 = xor i64 %44, %45
%47 = and i64 %46, 79764919
%48 = load i64, i64* %7
%49 = xor i64 %48, %47
store i64 %49, i64* %7
br label %50
50: ; preds = %25
%51 = load i32, i32* %8
%52 = add nsw i32 %51, -1
store i32 %52, i32* %8
br label %22
53: ; preds = %22
%54 = load i64, i64* %7
store i64 %54, i64* %4
br label %55
55: ; preds = %53, %16
%56 = load i64, i64* %4
ret i64 %56
}

LLVM IR (-O2):
@str = [51 x i8] c"ERROR: Max 64 bits of CRC can be computed. Ignored\00"
define i64 @crc32(i64 %0, i32 %1, i64 %2) {
%4 = add i32 %1, -65
%5 = icmp ult i32 %4, -64
br i1 %5, label %8, label %6
6: ; preds = %3
%7 = zext i32 %1 to i64
br label %10
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @str, i64 0, i64 0))
br label %26
10: ; preds = %6, %10
%11 = phi i64 [ %7, %6 ], [ %13, %10 ]
%12 = phi i64 [ %2, %6 ], [ %24, %10 ]
%13 = add nsw i64 %11, -1
%14 = and i64 %13, 4294967295
%15 = shl nuw i64 1, %14
%16 = and i64 %15, %0
%17 = icmp eq i64 %16, 0
%18 = select i1 %17, i64 0, i64 79764919
%19 = and i64 %12, 2147483648
%20 = icmp eq i64 %19, 0
%21 = select i1 %20, i64 0, i64 79764919
%22 = shl i64 %12, 1
%23 = xor i64 %21, %22
%24 = xor i64 %23, %18
%25 = icmp ugt i64 %11, 1
br i1 %25, label %10, label %26
26: ; preds = %10, %8
%27 = phi i64 [ %2, %8 ], [ %24, %10 ]
ret i64 %27
}