#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 /*<<< orphan*/ uint8_t;
typedef int uint64_t;
typedef int /*<<< orphan*/ uint32_t;
typedef int /*<<< orphan*/ uint16_t;

/* Variables and functions */
int /*<<< orphan*/ my_asm_crc32_u16(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ my_asm_crc32_u32(int /*<<< orphan*/, int /*<<< orphan*/);
int my_asm_crc32_u64(int, int);
int /*<<< orphan*/ my_asm_crc32_u8(int /*<<< orphan*/,
                                   int /*<<< orphan*/ const);
uint32_t my_crc32c_sse42(const uint8_t *buf, size_t len) {
  const uint8_t *p = buf;
  uint64_t crc64bit = 0xFFFFFFFF;
  for (size_t i = 0; i < len / sizeof(uint64_t); i++) {
    crc64bit = my_asm_crc32_u64(crc64bit, *(uint64_t *)p);
    p += sizeof(uint64_t);
  }
  uint32_t crc32bit = (uint32_t)crc64bit;
  len &= sizeof(uint64_t) - 1;
  switch (len) {
  case 7:
    crc32bit = my_asm_crc32_u8(crc32bit, *p++);
  case 6:
    crc32bit = my_asm_crc32_u16(crc32bit, *(uint16_t *)p);
    p += 2;
  case 4:
    crc32bit = my_asm_crc32_u32(crc32bit, *(uint32_t *)p);
    break;
  case 3:
    crc32bit = my_asm_crc32_u8(crc32bit, *p++);
  case 2:
    crc32bit = my_asm_crc32_u16(crc32bit, *(uint16_t *)p);
    break;
  case 5:
    crc32bit = my_asm_crc32_u32(crc32bit, *(uint32_t *)p);
    p += 4;
  case 1:
    crc32bit = my_asm_crc32_u8(crc32bit, *p);
    break;
  case 0:
    break;
  default:
    break;
  }
  return ~crc32bit;
}


x86 assembly (clang, -O0):
<my_crc32c_sse42>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rcx
shr    $0x2,%rcx
cmp    %rcx,%rax
jae    11aa <my_crc32c_sse42+0x6a>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1050 <my_asm_crc32_u64@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1167 <my_crc32c_sse42+0x27>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
and    $0x3,%eax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
sub    $0x7,%rax
ja     129a <my_crc32c_sse42+0x15a>
mov    -0x38(%rbp),%rax
lea    0xe28(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%esi
call   1040 <my_asm_crc32_u8@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1060 <my_asm_crc32_u16@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1030 <my_asm_crc32_u32@plt>
mov    %eax,-0x2c(%rbp)
jmp    129f <my_crc32c_sse42+0x15f>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x4,%rcx
mov    %rcx,-0x18(%rbp)
mov    (%rax),%esi
call   1040 <my_asm_crc32_u8@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1060 <my_asm_crc32_u16@plt>
mov    %eax,-0x2c(%rbp)
jmp    129f <my_crc32c_sse42+0x15f>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1030 <my_asm_crc32_u32@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x18(%rbp)
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1040 <my_asm_crc32_u8@plt>
mov    %eax,-0x2c(%rbp)
jmp    129f <my_crc32c_sse42+0x15f>
jmp    129f <my_crc32c_sse42+0x15f>
jmp    129f <my_crc32c_sse42+0x15f>
mov    -0x2c(%rbp),%eax
xor    $0xffffffff,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_crc32c_sse42>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0xffffffff,%eax
cmp    $0x4,%rsi
jb     1174 <my_crc32c_sse42+0x44>
mov    %r14,%rbx
shr    $0x2,%rbx
mov    $0xffffffff,%eax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%esi
mov    %eax,%edi
call   1040 <my_asm_crc32_u64@plt>
add    $0x10,%r15
add    $0xffffffffffffffff,%rbx
jne    1160 <my_crc32c_sse42+0x30>
and    $0x3,%r14d
cmp    $0x1,%r14
je     11a4 <my_crc32c_sse42+0x74>
cmp    $0x2,%r14d
je     1198 <my_crc32c_sse42+0x68>
cmp    $0x3,%r14d
jne    11ae <my_crc32c_sse42+0x7e>
mov    (%r15),%esi
add    $0x4,%r15
mov    %eax,%edi
call   1030 <my_asm_crc32_u8@plt>
mov    (%r15),%esi
mov    %eax,%edi
call   1050 <my_asm_crc32_u16@plt>
jmp    11ae <my_crc32c_sse42+0x7e>
mov    (%r15),%esi
mov    %eax,%edi
call   1030 <my_asm_crc32_u8@plt>
not    %eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @my_crc32c_sse42(i32* nocapture %0, i64 %1) {
%3 = icmp ult i64 %1, 4
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = lshr i64 %1, 2
br label %10
6: ; preds = %10, %2
%7 = phi i32* [ %0, %2 ], [ %16, %10 ]
%8 = phi i32 [ -1, %2 ], [ %15, %10 ]
%9 = and i64 %1, 3
switch i64 %9, label %31 [
i64 1, label %28
i64 2, label %23
i64 3, label %19
]
10: ; preds = %4, %10
%11 = phi i64 [ %17, %10 ], [ 0, %4 ]
%12 = phi i32 [ %15, %10 ], [ -1, %4 ]
%13 = phi i32* [ %16, %10 ], [ %0, %4 ]
%14 = load i32, i32* %13
%15 = tail call i32 @my_asm_crc32_u64(i32 %12, i32 %14)
%16 = getelementptr inbounds i32, i32* %13, i64 4
%17 = add nuw nsw i64 %11, 1
%18 = icmp eq i64 %17, %5
br i1 %18, label %6, label %10
19: ; preds = %6
%20 = getelementptr inbounds i32, i32* %7, i64 1
%21 = load i32, i32* %7
%22 = tail call i32 @my_asm_crc32_u8(i32 %8, i32 %21)
br label %23
23: ; preds = %6, %19
%24 = phi i32* [ %7, %6 ], [ %20, %19 ]
%25 = phi i32 [ %8, %6 ], [ %22, %19 ]
%26 = load i32, i32* %24
%27 = tail call i32 @my_asm_crc32_u16(i32 %25, i32 %26)
br label %31
28: ; preds = %6
%29 = load i32, i32* %7
%30 = tail call i32 @my_asm_crc32_u8(i32 %8, i32 %29)
br label %31
31: ; preds = %6, %28, %23
%32 = phi i32 [ %8, %6 ], [ %30, %28 ], [ %27, %23 ]
%33 = xor i32 %32, -1
ret i32 %33
}