#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 int uint8_t;
typedef int uint32_t;

/* Variables and functions */
int crc32c_intel(int, int);
void crc_handler(int n) {
  uint8_t *p = (char *)*(uint32_t *)(&n + 15);
  if (*(uint32_t *)p == 0xf0380ff2) {
    uint8_t modrm, reg, rm;
    modrm = p[4];
    if ((modrm & 0xc0) != 0 || (modrm & 0xfe) == 4)
      return;
    reg = (modrm >> 3) & 7;
    rm = modrm & 7;
    (*(uint32_t *)(&n + 12 - reg)) =
        crc32c_intel((*(uint32_t *)(&n + 12 - reg)),
                     *(uint8_t *)(*(uint32_t *)(&n + 12 - rm)));
    *(uint32_t *)(&n + 15) += 5;
  }
}


x86 assembly (clang, -O0):
<crc_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq 0x38(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0xf0380ff2,(%rax)
jne    11b3 <crc_handler+0xa3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
and    $0xc0,%eax
cmp    $0x0,%eax
jne    115f <crc_handler+0x4f>
mov    -0x14(%rbp),%eax
and    $0xfe,%eax
cmp    $0x4,%eax
jne    1164 <crc_handler+0x54>
jmp    11b3 <crc_handler+0xa3>
mov    -0x14(%rbp),%eax
sar    $0x3,%eax
and    $0x7,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0x1c(%rbp)
movslq -0x18(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
mov    0x2c(%rbp,%rax,4),%edi
movslq -0x1c(%rbp),%rcx
xor    %eax,%eax
sub    %rcx,%rax
movslq 0x2c(%rbp,%rax,4),%rax
mov    (%rax),%esi
call   1030 <crc32c_intel@plt>
mov    %eax,%ecx
movslq -0x18(%rbp),%rdx
xor    %eax,%eax
sub    %rdx,%rax
mov    %ecx,0x2c(%rbp,%rax,4)
mov    0x38(%rbp),%eax
add    $0x5,%eax
mov    %eax,0x38(%rbp)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crc_handler>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,0xc(%rsp)
mov    0x10,%ebx
test   $0xc0,%bl
jne    1165 <crc_handler+0x55>
mov    %ebx,%eax
and    $0xfe,%eax
cmp    $0x4,%eax
je     1165 <crc_handler+0x55>
mov    %ebx,%eax
and    $0x7,%eax
lea    0x3c(%rsp),%rcx
shr    %rbx
and    $0x1c,%ebx
sub    %rbx,%rcx
neg    %rbx
mov    (%rcx),%edi
shl    $0x2,%rax
neg    %rax
movslq 0x3c(%rsp,%rax,1),%rax
mov    (%rax),%esi
call   1030 <crc32c_intel@plt>
mov    %eax,0x3c(%rsp,%rbx,1)
addl   $0x5,0x48(%rsp)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define void @crc_handler(i32 %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %2
%7 = getelementptr inbounds i32, i32* %2, i64 15
%8 = load i32, i32* %7
%9 = sext i32 %8 to i64
%10 = inttoptr i64 %9 to i8*
%11 = bitcast i8* %10 to i32*
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = load i32, i32* %12
%14 = icmp eq i32 %13, -264761358
br i1 %14, label %15, label %57
15: ; preds = %1
%16 = load i32*, i32** %3
%17 = getelementptr inbounds i32, i32* %16, i64 4
%18 = load i32, i32* %17
store i32 %18, i32* %4
%19 = load i32, i32* %4
%20 = and i32 %19, 192
%21 = icmp ne i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %15
%23 = load i32, i32* %4
%24 = and i32 %23, 254
%25 = icmp eq i32 %24, 4
br i1 %25, label %26, label %27
26: ; preds = %22, %15
br label %57
27: ; preds = %22
%28 = load i32, i32* %4
%29 = ashr i32 %28, 3
%30 = and i32 %29, 7
store i32 %30, i32* %5
%31 = load i32, i32* %4
%32 = and i32 %31, 7
store i32 %32, i32* %6
%33 = getelementptr inbounds i32, i32* %2, i64 12
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = sub i64 0, %35
%37 = getelementptr inbounds i32, i32* %33, i64 %36
%38 = load i32, i32* %37
%39 = getelementptr inbounds i32, i32* %2, i64 12
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = sub i64 0, %41
%43 = getelementptr inbounds i32, i32* %39, i64 %42
%44 = load i32, i32* %43
%45 = sext i32 %44 to i64
%46 = inttoptr i64 %45 to i32*
%47 = load i32, i32* %46
%48 = call i32 @crc32c_intel(i32 %38, i32 %47)
%49 = getelementptr inbounds i32, i32* %2, i64 12
%50 = load i32, i32* %5
%51 = sext i32 %50 to i64
%52 = sub i64 0, %51
%53 = getelementptr inbounds i32, i32* %49, i64 %52
store i32 %48, i32* %53
%54 = getelementptr inbounds i32, i32* %2, i64 15
%55 = load i32, i32* %54
%56 = add nsw i32 %55, 5
store i32 %56, i32* %54
br label %57
57: ; preds = %26, %27, %1
ret void
}

LLVM IR (-O2):
define void @crc_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = getelementptr inbounds i32, i32* %2, i64 15
%4 = load i32, i32* inttoptr (i64 16 to i32*)
%5 = and i32 %4, 192
%6 = icmp ne i32 %5, 0
%7 = and i32 %4, 254
%8 = icmp eq i32 %7, 4
%9 = or i1 %6, %8
br i1 %9, label %29, label %10
10: ; preds = %1
%11 = lshr i32 %4, 3
%12 = and i32 %11, 7
%13 = and i32 %4, 7
%14 = getelementptr inbounds i32, i32* %2, i64 12
%15 = zext i32 %12 to i64
%16 = sub nsw i64 0, %15
%17 = getelementptr inbounds i32, i32* %14, i64 %16
%18 = load i32, i32* %17
%19 = zext i32 %13 to i64
%20 = sub nsw i64 0, %19
%21 = getelementptr inbounds i32, i32* %14, i64 %20
%22 = load i32, i32* %21
%23 = sext i32 %22 to i64
%24 = inttoptr i64 %23 to i32*
%25 = load i32, i32* %24
%26 = tail call i32 @crc32c_intel(i32 %18, i32 %25)
store i32 %26, i32* %17
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 5
store i32 %28, i32* %3
br label %29
29: ; preds = %10, %1
ret void
}