#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 */
unsigned long csc_crc32_byte(unsigned long, int /*<<< orphan*/);
unsigned long csc_crc32(unsigned long crc, void *buf, size_t len) {
  unsigned char *p = buf;
  crc ^= 0xffffffff;
  while (len--) {
    crc = csc_crc32_byte(crc, *p++);
  }
  return crc ^ 0xffffffff;
}


x86 assembly (clang, -O0):
<csc_crc32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movabs $0xffffffff,%rax
xor    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
cmp    $0x0,%rax
je     117b <csc_crc32+0x6b>
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x20(%rbp)
movzbl (%rax),%esi
call   1030 <csc_crc32_byte@plt>
mov    %rax,-0x8(%rbp)
jmp    113e <csc_crc32+0x2e>
movabs $0xffffffff,%rax
xor    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<csc_crc32>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rax
mov    $0xffffffff,%r15d
xor    %r15,%rax
test   %rdx,%rdx
je     1156 <csc_crc32+0x46>
mov    %rdx,%r12
mov    %rsi,%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r14,%rbx,1),%esi
mov    %rax,%rdi
call   1030 <csc_crc32_byte@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <csc_crc32+0x30>
xor    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @csc_crc32(i64 %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
store i64 %0, i64* %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i8*, i8** %5
store i8* %8, i8** %7
%9 = load i64, i64* %4
%10 = xor i64 %9, 4294967295
store i64 %10, i64* %4
br label %11
11: ; preds = %15, %3
%12 = load i64, i64* %6
%13 = add i64 %12, -1
store i64 %13, i64* %6
%14 = icmp ne i64 %12, 0
br i1 %14, label %15, label %22
15: ; preds = %11
%16 = load i64, i64* %4
%17 = load i8*, i8** %7
%18 = getelementptr inbounds i8, i8* %17, i32 1
store i8* %18, i8** %7
%19 = load i8, i8* %17
%20 = zext i8 %19 to i32
%21 = call i64 @csc_crc32_byte(i64 %16, i32 %20)
store i64 %21, i64* %4
br label %11
22: ; preds = %11
%23 = load i64, i64* %4
%24 = xor i64 %23, 4294967295
ret i64 %24
}

LLVM IR (-O2):
define i64 @csc_crc32(i64 %0, i8* nocapture %1, i64 %2) {
%4 = xor i64 %0, 4294967295
%5 = icmp eq i64 %2, 0
br i1 %5, label %16, label %6
6: ; preds = %3, %6
%7 = phi i8* [ %11, %6 ], [ %1, %3 ]
%8 = phi i64 [ %10, %6 ], [ %2, %3 ]
%9 = phi i64 [ %14, %6 ], [ %4, %3 ]
%10 = add i64 %8, -1
%11 = getelementptr inbounds i8, i8* %7, i64 1
%12 = load i8, i8* %7
%13 = zext i8 %12 to i32
%14 = tail call i64 @csc_crc32_byte(i64 %9, i32 %13)
%15 = icmp eq i64 %10, 0
br i1 %15, label %16, label %6
16: ; preds = %6, %3
%17 = phi i64 [ %4, %3 ], [ %14, %6 ]
%18 = xor i64 %17, 4294967295
ret i64 %18
}