#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 /*<<< orphan*/ input;

/* Variables and functions */
unsigned int _mm_crc32_u32(unsigned int, unsigned int);
unsigned int _mm_crc32_u8(unsigned int, unsigned char);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ printf(char *, unsigned int);
int /*<<< orphan*/ puts(char *);
int main() {
  unsigned int crc1 = 0xffffffffu;
  unsigned char input[] = {'a', 'b', 'c', 'd'};
  int n = sizeof(input) / sizeof(input[0]);
  for (int i = 0; i < n; i++) {
    crc1 = _mm_crc32_u8(crc1, input[i]);
  }
  crc1 ^= 0xffffffffu;
  printf("CRC: 0x%08x\n", crc1);
  assert(crc1 == 0x92c80a31);
  unsigned int crc2 = 0xffffffffu;
  assert(n % 4 == 0);
  for (int i = 0; i < n; i += 4) {
    unsigned int *ptr = (unsigned int *)&input[i];
    crc2 = _mm_crc32_u32(crc2, *ptr);
  }
  crc2 ^= 0xffffffffu;
  printf("CRC: %08x\n", crc2);
  assert(crc2 == 0x92c80a31);
  puts("pass");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
mov    0xe94(%rip),%eax
mov    %eax,-0xc(%rbp)
movl   $0x4,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    11ab <main+0x5b>
mov    -0x8(%rbp),%edi
movslq -0x14(%rbp),%rax
movzbl -0xc(%rbp,%rax,1),%esi
call   1070 <_mm_crc32_u8@plt>
mov    %eax,-0x8(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <main+0x2d>
mov    -0x8(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe46(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x92c80a31,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0xffffffff,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    $0x4,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    123a <main+0xea>
movslq -0x1c(%rbp),%rcx
lea    -0xc(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1040 <_mm_crc32_u32@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x1c(%rbp)
jmp    1200 <main+0xb0>
mov    -0x18(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    0xdc4(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0x92c80a31,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
lea    0xdaf(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0xffffffff,%edi
mov    $0x61,%esi
call   1070 <_mm_crc32_u8@plt>
mov    %eax,%edi
mov    $0x62,%esi
call   1070 <_mm_crc32_u8@plt>
mov    %eax,%edi
mov    $0x63,%esi
call   1070 <_mm_crc32_u8@plt>
mov    %eax,%edi
mov    $0x64,%esi
call   1070 <_mm_crc32_u8@plt>
mov    %eax,%ebx
mov    %eax,%esi
not    %esi
lea    0xe6f(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
cmp    $0x6d37f5ce,%ebx
sete   %dil
call   1060 <assert@plt>
mov    $0x1,%edi
call   1060 <assert@plt>
mov    $0xffffffff,%edi
mov    $0x64636261,%esi
call   1040 <_mm_crc32_u32@plt>
mov    %eax,%ebx
mov    %eax,%esi
not    %esi
lea    0xe40(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
cmp    $0x6d37f5ce,%ebx
sete   %dil
call   1060 <assert@plt>
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.input = [4 x i8] c"abcd"
@.str = [13 x i8] c"CRC: 0x%08x\0A\00"
@.str.1 = [11 x i8] c"CRC: %08x\0A\00"
@.str.2 = [5 x i8] c"pass\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [4 x i8]
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %1
store i32 -1, i32* %2
%9 = bitcast [4 x i8]* %3 to i8*
store i32 4, i32* %4
store i32 0, i32* %5
br label %10
10: ; preds = %21, %0
%11 = load i32, i32* %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %24
14: ; preds = %10
%15 = load i32, i32* %2
%16 = load i32, i32* %5
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @_mm_crc32_u8(i32 %15, i8 zeroext %19)
store i32 %20, i32* %2
br label %21
21: ; preds = %14
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %10
24: ; preds = %10
%25 = load i32, i32* %2
%26 = xor i32 %25, -1
store i32 %26, i32* %2
%27 = load i32, i32* %2
%28 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i32, i32* %2
%30 = icmp eq i32 %29, -1832383951
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
store i32 -1, i32* %6
%33 = load i32, i32* %4
%34 = srem i32 %33, 4
%35 = icmp eq i32 %34, 0
%36 = zext i1 %35 to i32
%37 = call i32 @assert(i32 %36)
store i32 0, i32* %7
br label %38
38: ; preds = %51, %24
%39 = load i32, i32* %7
%40 = load i32, i32* %4
%41 = icmp slt i32 %39, %40
br i1 %41, label %42, label %54
42: ; preds = %38
%43 = load i32, i32* %7
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [4 x i8], [4 x i8]* %3, i64 0, i64 %44
%46 = bitcast i8* %45 to i32*
store i32* %46, i32** %8
%47 = load i32, i32* %6
%48 = load i32*, i32** %8
%49 = load i32, i32* %48
%50 = call i32 @_mm_crc32_u32(i32 %47, i32 %49)
store i32 %50, i32* %6
br label %51
51: ; preds = %42
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 4
store i32 %53, i32* %7
br label %38
54: ; preds = %38
%55 = load i32, i32* %6
%56 = xor i32 %55, -1
store i32 %56, i32* %6
%57 = load i32, i32* %6
%58 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %6
%60 = icmp eq i32 %59, -1832383951
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
%63 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"CRC: 0x%08x\0A\00"
@.str.1 = [11 x i8] c"CRC: %08x\0A\00"
@.str.2 = [5 x i8] c"pass\00"
define i32 @main() {
%1 = tail call i32 @_mm_crc32_u8(i32 -1, i8 zeroext 97)
%2 = tail call i32 @_mm_crc32_u8(i32 %1, i8 zeroext 98)
%3 = tail call i32 @_mm_crc32_u8(i32 %2, i8 zeroext 99)
%4 = tail call i32 @_mm_crc32_u8(i32 %3, i8 zeroext 100)
%5 = xor i32 %4, -1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %4, 1832383950
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @assert(i32 1)
%11 = tail call i32 @_mm_crc32_u32(i32 -1, i32 1684234849)
%12 = xor i32 %11, -1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %11, 1832383950
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}