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

/* Variables and functions */
int /*<<< orphan*/ crc32_accumulate_8(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ writel(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
void crc32_csum(uint8_t *buf, const size_t len) {
  uint32_t crc;
  size_t i;
  crc = ~0;
  for (i = 0; i < len; i += 4) {
    crc = crc32_accumulate_8(crc, buf[i + 3]);
    crc = crc32_accumulate_8(crc, buf[i + 2]);
    crc = crc32_accumulate_8(crc, buf[i + 1]);
    crc = crc32_accumulate_8(crc, buf[i]);
  }
  crc = ~crc;
  writel(buf, 16, crc);
}


x86 assembly (clang, -O0):
<crc32_csum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    11b9 <crc32_csum+0x99>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    0xc(%rax,%rcx,4),%esi
call   1040 <crc32_accumulate_8@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    0x8(%rax,%rcx,4),%esi
call   1040 <crc32_accumulate_8@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    0x4(%rax,%rcx,4),%esi
call   1040 <crc32_accumulate_8@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1040 <crc32_accumulate_8@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x20(%rbp)
jmp    113f <crc32_csum+0x1f>
mov    -0x14(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    $0x10,%esi
call   1030 <writel@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc32_csum>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
test   %rsi,%rsi
je     117c <crc32_csum+0x5c>
mov    %rsi,%r14
mov    $0xffffffff,%eax
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    0xc(%r15,%rbx,4),%esi
mov    %eax,%edi
call   1040 <crc32_accumulate_8@plt>
mov    0x8(%r15,%rbx,4),%esi
mov    %eax,%edi
call   1040 <crc32_accumulate_8@plt>
mov    0x4(%r15,%rbx,4),%esi
mov    %eax,%edi
call   1040 <crc32_accumulate_8@plt>
mov    (%r15,%rbx,4),%esi
mov    %eax,%edi
call   1040 <crc32_accumulate_8@plt>
add    $0x4,%rbx
cmp    %r14,%rbx
jb     1140 <crc32_csum+0x20>
not    %eax
jmp    117e <crc32_csum+0x5e>
xor    %eax,%eax
mov    %r15,%rdi
mov    $0x10,%esi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <writel@plt>

LLVM IR (-O0):
define void @crc32_csum(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i64
store i32* %0, i32** %3
store i64 %1, i64* %4
store i32 -1, i32* %5
store i64 0, i64* %6
br label %7
7: ; preds = %39, %2
%8 = load i64, i64* %6
%9 = load i64, i64* %4
%10 = icmp ult i64 %8, %9
br i1 %10, label %11, label %42
11: ; preds = %7
%12 = load i32, i32* %5
%13 = load i32*, i32** %3
%14 = load i64, i64* %6
%15 = add i64 %14, 3
%16 = getelementptr inbounds i32, i32* %13, i64 %15
%17 = load i32, i32* %16
%18 = call i32 @crc32_accumulate_8(i32 %12, i32 %17)
store i32 %18, i32* %5
%19 = load i32, i32* %5
%20 = load i32*, i32** %3
%21 = load i64, i64* %6
%22 = add i64 %21, 2
%23 = getelementptr inbounds i32, i32* %20, i64 %22
%24 = load i32, i32* %23
%25 = call i32 @crc32_accumulate_8(i32 %19, i32 %24)
store i32 %25, i32* %5
%26 = load i32, i32* %5
%27 = load i32*, i32** %3
%28 = load i64, i64* %6
%29 = add i64 %28, 1
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = call i32 @crc32_accumulate_8(i32 %26, i32 %31)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = load i32*, i32** %3
%35 = load i64, i64* %6
%36 = getelementptr inbounds i32, i32* %34, i64 %35
%37 = load i32, i32* %36
%38 = call i32 @crc32_accumulate_8(i32 %33, i32 %37)
store i32 %38, i32* %5
br label %39
39: ; preds = %11
%40 = load i64, i64* %6
%41 = add i64 %40, 4
store i64 %41, i64* %6
br label %7
42: ; preds = %7
%43 = load i32, i32* %5
%44 = xor i32 %43, -1
store i32 %44, i32* %5
%45 = load i32*, i32** %3
%46 = load i32, i32* %5
%47 = call i32 @writel(i32* %45, i32 16, i32 %46)
ret void
}

LLVM IR (-O2):
define void @crc32_csum(i32* %0, i64 %1) {
%3 = icmp eq i64 %1, 0
br i1 %3, label %26, label %4
4: ; preds = %2, %4
%5 = phi i64 [ %22, %4 ], [ 0, %2 ]
%6 = phi i32 [ %21, %4 ], [ -1, %2 ]
%7 = or i64 %5, 3
%8 = getelementptr inbounds i32, i32* %0, i64 %7
%9 = load i32, i32* %8
%10 = tail call i32 @crc32_accumulate_8(i32 %6, i32 %9)
%11 = or i64 %5, 2
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = tail call i32 @crc32_accumulate_8(i32 %10, i32 %13)
%15 = or i64 %5, 1
%16 = getelementptr inbounds i32, i32* %0, i64 %15
%17 = load i32, i32* %16
%18 = tail call i32 @crc32_accumulate_8(i32 %14, i32 %17)
%19 = getelementptr inbounds i32, i32* %0, i64 %5
%20 = load i32, i32* %19
%21 = tail call i32 @crc32_accumulate_8(i32 %18, i32 %20)
%22 = add i64 %5, 4
%23 = icmp ult i64 %22, %1
br i1 %23, label %4, label %24
24: ; preds = %4
%25 = xor i32 %21, -1
br label %26
26: ; preds = %24, %2
%27 = phi i32 [ 0, %2 ], [ %25, %24 ]
%28 = tail call i32 @writel(i32* %0, i32 16, i32 %27)
ret void
}