#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(char *, int);
int /*<<< orphan*/ memcpy(char *, char *, int);
unsigned int yac_crc32(char *data, unsigned int size) {
  if (size < 128) {
    return crc32(data, size);
  } else {
    int i = 0;
    char crc_contents[128];
    int head = 128 >> 2;
    int tail = 128 >> 4;
    int body = 128 - head - tail;
    char *p = data + head;
    char *q = crc_contents + head;
    int step = (size - tail - head) / body;
    memcpy(crc_contents, data, head);
    for (; i < body; i++, q++, p += step) {
      *q = *p;
    }
    memcpy(q, p, tail);
    return crc32(crc_contents, 128);
  }
}


x86 assembly (clang, -O0):
<yac_crc32>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x80,-0x14(%rbp)
jae    1153 <yac_crc32+0x33>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <crc32@plt>
mov    %eax,-0x4(%rbp)
jmp    126d <yac_crc32+0x14d>
movl   $0x0,-0x18(%rbp)
movl   $0x20,-0xa4(%rbp)
movl   $0x8,-0xa8(%rbp)
mov    $0x80,%eax
sub    -0xa4(%rbp),%eax
sub    -0xa8(%rbp),%eax
mov    %eax,-0xac(%rbp)
mov    -0x10(%rbp),%rax
movslq -0xa4(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0xb8(%rbp)
lea    -0xa0(%rbp),%rax
movslq -0xa4(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0xc0(%rbp)
mov    -0x14(%rbp),%eax
sub    -0xa8(%rbp),%eax
sub    -0xa4(%rbp),%eax
xor    %edx,%edx
divl   -0xac(%rbp)
mov    %eax,-0xc4(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0xa4(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x18(%rbp),%eax
cmp    -0xac(%rbp),%eax
jge    1240 <yac_crc32+0x120>
mov    -0xb8(%rbp),%rax
mov    (%rax),%cl
mov    -0xc0(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc0(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xc0(%rbp)
mov    -0xc4(%rbp),%ecx
mov    -0xb8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0xb8(%rbp)
jmp    11e5 <yac_crc32+0xc5>
mov    -0xc0(%rbp),%rdi
mov    -0xb8(%rbp),%rsi
mov    -0xa8(%rbp),%edx
call   1040 <memcpy@plt>
lea    -0xa0(%rbp),%rdi
mov    $0x80,%esi
call   1030 <crc32@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yac_crc32>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rdi,%r14
cmp    $0x7f,%esi
ja     114c <yac_crc32+0x2c>
mov    %r14,%rdi
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <crc32@plt>
lea    0x20(%rsp),%rbx
add    $0xffffffd8,%esi
mov    $0xba2e8ba3,%r15d
imul   %rsi,%r15
shr    $0x26,%r15
mov    %rsp,%rdi
mov    %r14,%rsi
mov    $0x20,%edx
call   1040 <memcpy@plt>
lea    0x77(%rsp),%r8
lea    (%r15,%r15,4),%r10
lea    (%r15,%r10,2),%r9
lea    (%r15,%r15,1),%rcx
lea    (%rcx,%rcx,4),%r11
lea    (%r15,%r15,8),%r12
lea    0x0(,%r15,8),%rax
sub    %r15,%rax
lea    (%rcx,%rcx,2),%rsi
lea    (%r15,%r15,2),%rcx
xchg   %ax,%ax
movzbl 0x20(%r14),%edx
mov    %dl,(%rbx)
movzbl 0x20(%r14,%r15,1),%edx
mov    %dl,0x1(%rbx)
movzbl 0x20(%r14,%r15,2),%edx
mov    %dl,0x2(%rbx)
movzbl 0x20(%r14,%rcx,1),%edx
mov    %dl,0x3(%rbx)
movzbl 0x20(%r14,%r15,4),%edx
mov    %dl,0x4(%rbx)
movzbl 0x20(%r14,%r10,1),%edx
mov    %dl,0x5(%rbx)
movzbl 0x20(%r14,%rsi,1),%edx
mov    %dl,0x6(%rbx)
movzbl 0x20(%r14,%rax,1),%edx
mov    %dl,0x7(%rbx)
movzbl 0x20(%r14,%r15,8),%edx
mov    %dl,0x8(%rbx)
movzbl 0x20(%r14,%r12,1),%edx
mov    %dl,0x9(%rbx)
movzbl 0x20(%r14,%r11,1),%edx
lea    0xa(%rbx),%rdi
mov    %dl,0xa(%rbx)
add    $0xb,%rbx
add    %r9,%r14
cmp    %r8,%rdi
jne    11a0 <yac_crc32+0x80>
add    $0x20,%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
mov    %rsp,%rdi
mov    $0x80,%esi
call   1030 <crc32@plt>
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @yac_crc32(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [128 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%14 = load i32, i32* %5
%15 = icmp ult i32 %14, 128
br i1 %15, label %16, label %20
16: ; preds = %2
%17 = load i8*, i8** %4
%18 = load i32, i32* %5
%19 = call i32 @crc32(i8* %17, i32 %18)
store i32 %19, i32* %3
br label %68
20: ; preds = %2
store i32 0, i32* %6
store i32 32, i32* %8
store i32 8, i32* %9
%21 = load i32, i32* %8
%22 = sub nsw i32 128, %21
%23 = load i32, i32* %9
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %10
%25 = load i8*, i8** %4
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8* %28, i8** %11
%29 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8* %32, i8** %12
%33 = load i32, i32* %5
%34 = load i32, i32* %9
%35 = sub i32 %33, %34
%36 = load i32, i32* %8
%37 = sub i32 %35, %36
%38 = load i32, i32* %10
%39 = udiv i32 %37, %38
store i32 %39, i32* %13
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%41 = load i8*, i8** %4
%42 = load i32, i32* %8
%43 = call i32 @memcpy(i8* %40, i8* %41, i32 %42)
br label %44
44: ; preds = %52, %20
%45 = load i32, i32* %6
%46 = load i32, i32* %10
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %61
48: ; preds = %44
%49 = load i8*, i8** %11
%50 = load i8, i8* %49
%51 = load i8*, i8** %12
store i8 %50, i8* %51
br label %52
52: ; preds = %48
%53 = load i32, i32* %6
%54 = add nsw i32 %53, 1
store i32 %54, i32* %6
%55 = load i8*, i8** %12
%56 = getelementptr inbounds i8, i8* %55, i32 1
store i8* %56, i8** %12
%57 = load i32, i32* %13
%58 = load i8*, i8** %11
%59 = sext i32 %57 to i64
%60 = getelementptr inbounds i8, i8* %58, i64 %59
store i8* %60, i8** %11
br label %44
61: ; preds = %44
%62 = load i8*, i8** %12
%63 = load i8*, i8** %11
%64 = load i32, i32* %9
%65 = call i32 @memcpy(i8* %62, i8* %63, i32 %64)
%66 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%67 = call i32 @crc32(i8* %66, i32 128)
store i32 %67, i32* %3
br label %68
68: ; preds = %61, %16
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
define i32 @yac_crc32(i8* %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = icmp ult i32 %1, 128
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @crc32(i8* %0, i32 %1)
br label %56
7: ; preds = %2
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds i8, i8* %0, i64 32
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 32
%11 = add i32 %1, -40
%12 = udiv i32 %11, 88
%13 = call i32 @memcpy(i8* %8, i8* %0, i32 32)
%14 = zext i32 %12 to i64
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 119
br label %16
16: ; preds = %16, %7
%17 = phi i8* [ %10, %7 ], [ %50, %16 ]
%18 = phi i8* [ %9, %7 ], [ %51, %16 ]
%19 = load i8, i8* %18
store i8 %19, i8* %17
%20 = getelementptr inbounds i8, i8* %17, i64 1
%21 = getelementptr inbounds i8, i8* %18, i64 %14
%22 = load i8, i8* %21
store i8 %22, i8* %20
%23 = getelementptr inbounds i8, i8* %17, i64 2
%24 = getelementptr inbounds i8, i8* %21, i64 %14
%25 = load i8, i8* %24
store i8 %25, i8* %23
%26 = getelementptr inbounds i8, i8* %17, i64 3
%27 = getelementptr inbounds i8, i8* %24, i64 %14
%28 = load i8, i8* %27
store i8 %28, i8* %26
%29 = getelementptr inbounds i8, i8* %17, i64 4
%30 = getelementptr inbounds i8, i8* %27, i64 %14
%31 = load i8, i8* %30
store i8 %31, i8* %29
%32 = getelementptr inbounds i8, i8* %17, i64 5
%33 = getelementptr inbounds i8, i8* %30, i64 %14
%34 = load i8, i8* %33
store i8 %34, i8* %32
%35 = getelementptr inbounds i8, i8* %17, i64 6
%36 = getelementptr inbounds i8, i8* %33, i64 %14
%37 = load i8, i8* %36
store i8 %37, i8* %35
%38 = getelementptr inbounds i8, i8* %17, i64 7
%39 = getelementptr inbounds i8, i8* %36, i64 %14
%40 = load i8, i8* %39
store i8 %40, i8* %38
%41 = getelementptr inbounds i8, i8* %17, i64 8
%42 = getelementptr inbounds i8, i8* %39, i64 %14
%43 = load i8, i8* %42
store i8 %43, i8* %41
%44 = getelementptr inbounds i8, i8* %17, i64 9
%45 = getelementptr inbounds i8, i8* %42, i64 %14
%46 = load i8, i8* %45
store i8 %46, i8* %44
%47 = getelementptr inbounds i8, i8* %17, i64 10
%48 = getelementptr inbounds i8, i8* %45, i64 %14
%49 = load i8, i8* %48
store i8 %49, i8* %47
%50 = getelementptr inbounds i8, i8* %17, i64 11
%51 = getelementptr inbounds i8, i8* %48, i64 %14
%52 = icmp eq i8* %47, %15
br i1 %52, label %53, label %16
53: ; preds = %16
%54 = call i32 @memcpy(i8* %50, i8* %51, i32 8)
%55 = call i32 @crc32(i8* %8, i32 128)
br label %56
56: ; preds = %53, %5
%57 = phi i32 [ %6, %5 ], [ %55, %53 ]
ret i32 %57
}