#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 */
typedef int uint32_t;

/* Variables and functions */
uint32_t rkw_crc32(const void *src, uint32_t len) {
  const unsigned char *buf = (const unsigned char *)src;
  static const uint32_t crc32_lookup[16] = {
      0x00000000, 0x04C10DB7, 0x09821B6E, 0x0D4316D9, 0x130436DC, 0x17C53B6B,
      0x1A862DB2, 0x1E472005, 0x26086DB8, 0x22C9600F, 0x2F8A76D6, 0x2B4B7B61,
      0x350C5B64, 0x31CD56D3, 0x3C8E400A, 0x384F4DBD};
  uint32_t crc32 = 0;
  unsigned char byte;
  uint32_t t;
  while (len--) {
    byte = *buf++;
    t = crc32 >> 28;
    t ^= byte >> 4;
    crc32 <<= 4;
    crc32 ^= crc32_lookup[t];
    t = crc32 >> 28;
    t ^= byte & 0x0F;
    crc32 <<= 4;
    crc32 ^= crc32_lookup[t];
  }
  return crc32;
}


x86 assembly (clang, -O0):
<rkw_crc32>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11ad <rkw_crc32+0xad>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%al
mov    %al,-0x1d(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x1c,%eax
mov    %eax,-0x24(%rbp)
movzbl -0x1d(%rbp),%eax
sar    $0x4,%eax
xor    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x24(%rbp),%rcx
lea    0xe94(%rip),%rax
mov    (%rax,%rcx,4),%eax
xor    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sar    $0x1c,%eax
mov    %eax,-0x24(%rbp)
movzbl -0x1d(%rbp),%eax
and    $0xf,%eax
xor    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x4,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x24(%rbp),%rcx
lea    0xe61(%rip),%rax
mov    (%rax,%rcx,4),%eax
xor    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    111a <rkw_crc32+0x1a>
mov    -0x1c(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<rkw_crc32>:
test   %esi,%esi
je     1159 <rkw_crc32+0x59>
mov    %esi,%r8d
xor    %r10d,%r10d
lea    0xeef(%rip),%r9
xor    %eax,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movzbl (%rdi,%r10,1),%edx
mov    %eax,%esi
sar    $0x1c,%esi
mov    %edx,%ecx
shr    $0x4,%ecx
xor    %esi,%ecx
shl    $0x4,%eax
movslq %ecx,%rcx
xor    (%r9,%rcx,4),%eax
mov    %eax,%ecx
sar    $0x1c,%ecx
and    $0xf,%edx
xor    %ecx,%edx
shl    $0x4,%eax
movslq %edx,%rcx
xor    (%r9,%rcx,4),%eax
add    $0x1,%r10
cmp    %r10d,%r8d
jne    1120 <rkw_crc32+0x20>
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@rkw_crc32.crc32_lookup = internal constant [16 x i32] [i32 0, i32 79760823, i32 159521646, i32 222500569, i32 319043292, i32 398801771, i32 445001138, i32 507977733, i32 638086584, i32 583622671, i32 797603542, i32 726367073, i32 890002276, i32 835540691, i32 1015955466, i32 944721341]
define i32 @rkw_crc32(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%9 = load i8*, i8** %3
store i8* %9, i8** %5
store i32 0, i32* %6
br label %10
10: ; preds = %14, %2
%11 = load i32, i32* %4
%12 = add nsw i32 %11, -1
store i32 %12, i32* %4
%13 = icmp ne i32 %11, 0
br i1 %13, label %14, label %48
14: ; preds = %10
%15 = load i8*, i8** %5
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %5
%17 = load i8, i8* %15
store i8 %17, i8* %7
%18 = load i32, i32* %6
%19 = ashr i32 %18, 28
store i32 %19, i32* %8
%20 = load i8, i8* %7
%21 = zext i8 %20 to i32
%22 = ashr i32 %21, 4
%23 = load i32, i32* %8
%24 = xor i32 %23, %22
store i32 %24, i32* %8
%25 = load i32, i32* %6
%26 = shl i32 %25, 4
store i32 %26, i32* %6
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [16 x i32], [16 x i32]* @rkw_crc32.crc32_lookup, i64 0, i64 %28
%30 = load i32, i32* %29
%31 = load i32, i32* %6
%32 = xor i32 %31, %30
store i32 %32, i32* %6
%33 = load i32, i32* %6
%34 = ashr i32 %33, 28
store i32 %34, i32* %8
%35 = load i8, i8* %7
%36 = zext i8 %35 to i32
%37 = and i32 %36, 15
%38 = load i32, i32* %8
%39 = xor i32 %38, %37
store i32 %39, i32* %8
%40 = load i32, i32* %6
%41 = shl i32 %40, 4
store i32 %41, i32* %6
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [16 x i32], [16 x i32]* @rkw_crc32.crc32_lookup, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = load i32, i32* %6
%47 = xor i32 %46, %45
store i32 %47, i32* %6
br label %10
48: ; preds = %10
%49 = load i32, i32* %6
ret i32 %49
}

LLVM IR (-O2):
@rkw_crc32.crc32_lookup = internal unnamed_addr constant [16 x i32] [i32 0, i32 79760823, i32 159521646, i32 222500569, i32 319043292, i32 398801771, i32 445001138, i32 507977733, i32 638086584, i32 583622671, i32 797603542, i32 726367073, i32 890002276, i32 835540691, i32 1015955466, i32 944721341]
define i32 @rkw_crc32(i8* nocapture %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %29, label %4
4: ; preds = %2, %4
%5 = phi i32 [ %8, %4 ], [ %1, %2 ]
%6 = phi i8* [ %9, %4 ], [ %0, %2 ]
%7 = phi i32 [ %27, %4 ], [ 0, %2 ]
%8 = add nsw i32 %5, -1
%9 = getelementptr inbounds i8, i8* %6, i64 1
%10 = load i8, i8* %6
%11 = ashr i32 %7, 28
%12 = zext i8 %10 to i32
%13 = lshr i32 %12, 4
%14 = xor i32 %13, %11
%15 = shl i32 %7, 4
%16 = sext i32 %14 to i64
%17 = getelementptr inbounds [16 x i32], [16 x i32]* @rkw_crc32.crc32_lookup, i64 0, i64 %16
%18 = load i32, i32* %17
%19 = xor i32 %18, %15
%20 = ashr i32 %19, 28
%21 = and i32 %12, 15
%22 = xor i32 %20, %21
%23 = shl i32 %19, 4
%24 = sext i32 %22 to i64
%25 = getelementptr inbounds [16 x i32], [16 x i32]* @rkw_crc32.crc32_lookup, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = xor i32 %23, %26
%28 = icmp eq i32 %8, 0
br i1 %28, label %29, label %4
29: ; preds = %4, %2
%30 = phi i32 [ 0, %2 ], [ %27, %4 ]
ret i32 %30
}