#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 ceph_crc32c_le_intel(uint32_t crc, unsigned char const *data,
                              unsigned length) {
  unsigned int iquotient = length / 4;
  unsigned int iremainder = length % 4;
  uint32_t *ptmp = (uint32_t *)data;
  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):
<ceph_crc32c_le_intel>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shr    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0x3,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
je     1176 <ceph_crc32c_le_intel+0x66>
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
crc32  %ecx,%esi
mov    %rsi,-0x8(%rbp)
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    113d <ceph_crc32c_le_intel+0x2d>
cmpl   $0x0,-0x1c(%rbp)
je     1194 <ceph_crc32c_le_intel+0x84>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1030 <crc32c_intel_le_hw_byte@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

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

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

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