#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*/ crc32_calc_byte(unsigned char const, unsigned int *);
unsigned int crc32_calc(const unsigned char *p, int len) {
  int n = 0;
  unsigned int crc32_val = 0xFFFFFFFF;
  for (; n < len; ++n) {
    crc32_calc_byte(p[n], &crc32_val);
  }
  crc32_val = ~crc32_val;
  return crc32_val;
}


x86 assembly (clang, -O0):
<crc32_calc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    115c <crc32_calc+0x4c>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rsi
movzbl (%rax,%rcx,1),%edi
call   1030 <crc32_calc_byte@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112d <crc32_calc+0x1d>
mov    -0x14(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc32_calc>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
movl   $0xffffffff,0x4(%rsp)
ff
test   %esi,%esi
jle    115e <crc32_calc+0x4e>
mov    %rdi,%r15
mov    %esi,%r12d
xor    %ebx,%ebx
lea    0x4(%rsp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movzbl (%r15,%rbx,1),%edi
mov    %r14,%rsi
call   1030 <crc32_calc_byte@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1140 <crc32_calc+0x30>
mov    0x4(%rsp),%eax
not    %eax
jmp    1160 <crc32_calc+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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