#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 char *uint32_t;

/* Variables and functions */
char *crc32c_intel_le_hw_byte(char *, unsigned char *, unsigned int);
uint32_t crc32c_intel(unsigned char const *data, unsigned long length) {
  unsigned int iquotient = length / 4;
  unsigned int iremainder = length % 4;
  uint32_t *ptmp = (uint32_t *)data;
  uint32_t crc = ~0;
  while (iquotient--) {
    __asm__ __volatile__(".byte 0xf2, "
                         "0xf, 0x38, 0xf1, 0xf1;"
                         : "=S"(crc)
                         : "0"(crc), "c"(*ptmp));
    ptmp++;
  }
  if (iremainder)
    crc = crc32c_intel_le_hw_byte(crc, (unsigned char *)ptmp, iremainder);
  return crc;
}


x86 assembly (clang, -O0):
<crc32c_intel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x2,%rax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
and    $0x3,%rax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     1182 <crc32c_intel+0x72>
mov    -0x28(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rcx
crc32  %ecx,%esi
mov    %rsi,-0x28(%rbp)
mov    -0x20(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x20(%rbp)
jmp    1149 <crc32c_intel+0x39>
cmpl   $0x0,-0x18(%rbp)
je     11a0 <crc32c_intel+0x90>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <crc32c_intel_le_hw_byte@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc32c_intel>:
mov    %rsi,%rdx
mov    %rdi,%rax
mov    %rsi,%rdi
shr    $0x2,%rdi
and    $0x3,%edx
mov    $0xffffffffffffffff,%rsi
test   %edi,%edi
je     1141 <crc32c_intel+0x31>
nopl   0x0(%rax,%rax,1)
mov    (%rax),%rcx
crc32  %ecx,%esi
add    $0x8,%rax
add    $0xffffffff,%edi
jne    1130 <crc32c_intel+0x20>
test   %edx,%edx
je     1150 <crc32c_intel+0x40>
mov    %rsi,%rdi
mov    %rax,%rsi
jmp    1030 <crc32c_intel_le_hw_byte@plt>
mov    %rsi,%rax
ret

LLVM IR (-O0):
define i8* @crc32c_intel(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8**
%8 = alloca i8*
store i8* %0, i8** %3
store i64 %1, i64* %4
%9 = load i64, i64* %4
%10 = udiv i64 %9, 4
%11 = trunc i64 %10 to i32
store i32 %11, i32* %5
%12 = load i64, i64* %4
%13 = urem i64 %12, 4
%14 = trunc i64 %13 to i32
store i32 %14, i32* %6
%15 = load i8*, i8** %3
%16 = bitcast i8* %15 to i8**
store i8** %16, i8*** %7
store i8* inttoptr (i64 -1 to i8*), i8** %8
br label %17
17: ; preds = %21, %2
%18 = load i32, i32* %5
%19 = add i32 %18, -1
store i32 %19, i32* %5
%20 = icmp ne i32 %18, 0
br i1 %20, label %21, label %28
21: ; preds = %17
%22 = load i8*, i8** %8
%23 = load i8**, i8*** %7
%24 = load i8*, i8** %23
%25 = call i8* asm sideeffect ".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;", "={si},0,{cx},~{dirflag},~{fpsr},~{flags}"(i8* %22, i8* %24)
store i8* %25, i8** %8
%26 = load i8**, i8*** %7
%27 = getelementptr inbounds i8*, i8** %26, i32 1
store i8** %27, i8*** %7
br label %17
28: ; preds = %17
%29 = load i32, i32* %6
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = load i8*, i8** %8
%33 = load i8**, i8*** %7
%34 = bitcast i8** %33 to i8*
%35 = load i32, i32* %6
%36 = call i8* @crc32c_intel_le_hw_byte(i8* %32, i8* %34, i32 %35)
store i8* %36, i8** %8
br label %37
37: ; preds = %31, %28
%38 = load i8*, i8** %8
ret i8* %38
}

LLVM IR (-O2):
define i8* @crc32c_intel(i8* %0, i64 %1) {
%3 = lshr i64 %1, 2
%4 = trunc i64 %3 to i32
%5 = trunc i64 %1 to i32
%6 = and i32 %5, 3
%7 = bitcast i8* %0 to i8**
%8 = icmp eq i32 %4, 0
br i1 %8, label %18, label %9
9: ; preds = %2, %9
%10 = phi i8* [ %15, %9 ], [ inttoptr (i64 -1 to i8*), %2 ]
%11 = phi i8** [ %16, %9 ], [ %7, %2 ]
%12 = phi i32 [ %13, %9 ], [ %4, %2 ]
%13 = add i32 %12, -1
%14 = load i8*, i8** %11
%15 = tail call i8* asm sideeffect ".byte 0xf2, 0xf, 0x38, 0xf1, 0xf1;", "={si},0,{cx},~{dirflag},~{fpsr},~{flags}"(i8* %10, i8* %14)
%16 = getelementptr inbounds i8*, i8** %11, i64 1
%17 = icmp eq i32 %13, 0
br i1 %17, label %18, label %9
18: ; preds = %9, %2
%19 = phi i8** [ %7, %2 ], [ %16, %9 ]
%20 = phi i8* [ inttoptr (i64 -1 to i8*), %2 ], [ %15, %9 ]
%21 = icmp eq i32 %6, 0
br i1 %21, label %25, label %22
22: ; preds = %18
%23 = bitcast i8** %19 to i8*
%24 = tail call i8* @crc32c_intel_le_hw_byte(i8* %20, i8* %23, i32 %6)
br label %25
25: ; preds = %22, %18
%26 = phi i8* [ %24, %22 ], [ %20, %18 ]
ret i8* %26
}