#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 int crc32(int /*<<< orphan*/, unsigned char const *, int);
int /*<<< orphan*/ memcpy(char *, unsigned int *, int);
void compute_crc(const void *data_buffer, void *crc_buffer, size_t len) {
  size_t i;
  unsigned int crc;
  for (i = 0; i < len; i += 512) {
    crc = crc32(0, (const unsigned char *)data_buffer + i, 512);
    memcpy((char *)crc_buffer + i / 512 * 4, &crc, 4);
  }
}


x86 assembly (clang, -O0):
<compute_crc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1195 <compute_crc+0x75>
mov    -0x8(%rbp),%rsi
add    -0x20(%rbp),%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1030 <crc32@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
shr    $0x9,%rax
shl    $0x2,%rax
add    %rax,%rdi
lea    -0x24(%rbp),%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rax
add    $0x200,%rax
mov    %rax,-0x20(%rbp)
jmp    113c <compute_crc+0x1c>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compute_crc>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %rdx,%rdx
je     1187 <compute_crc+0x67>
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r15
xor    %ebx,%ebx
lea    0xc(%rsp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    (%r15,%rbx,1),%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1030 <crc32@plt>
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
shr    $0x7,%rdi
add    %r14,%rdi
mov    %r12,%rsi
mov    $0x4,%edx
call   1040 <memcpy@plt>
add    $0x200,%rbx
cmp    %r13,%rbx
jb     1150 <compute_crc+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @compute_crc(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
store i64 0, i64* %7
br label %9
9: ; preds = %24, %3
%10 = load i64, i64* %7
%11 = load i64, i64* %6
%12 = icmp ult i64 %10, %11
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load i8*, i8** %4
%15 = load i64, i64* %7
%16 = getelementptr inbounds i8, i8* %14, i64 %15
%17 = call i32 @crc32(i32 0, i8* %16, i32 512)
store i32 %17, i32* %8
%18 = load i8*, i8** %5
%19 = load i64, i64* %7
%20 = udiv i64 %19, 512
%21 = mul i64 %20, 4
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = call i32 @memcpy(i8* %22, i32* %8, i32 4)
br label %24
24: ; preds = %13
%25 = load i64, i64* %7
%26 = add i64 %25, 512
store i64 %26, i64* %7
br label %9
27: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @compute_crc(i8* %0, i8* %1, i64 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp eq i64 %2, 0
br i1 %6, label %16, label %7
7: ; preds = %3, %7
%8 = phi i64 [ %14, %7 ], [ 0, %3 ]
%9 = getelementptr inbounds i8, i8* %0, i64 %8
%10 = call i32 @crc32(i32 0, i8* %9, i32 512)
store i32 %10, i32* %4
%11 = lshr exact i64 %8, 7
%12 = getelementptr inbounds i8, i8* %1, i64 %11
%13 = call i32 @memcpy(i8* %12, i32* %4, i32 4)
%14 = add i64 %8, 512
%15 = icmp ult i64 %14, %2
br i1 %15, label %7, label %16
16: ; preds = %7, %3
ret void
}