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

/* Variables and functions */
int UINT32_C(int);
int /*<<< orphan*/ assert(int);
unsigned long blz_hash4_bits(const unsigned char *p, int bits) {
  assert(bits > 0 && bits <= 32);
  uint32_t val = (uint32_t)p[0] | ((uint32_t)p[1] << 8) |
                 ((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24);
  return (val * UINT32_C(2654435761)) >> (32 - bits);
}


x86 assembly (clang, -O0):
<blz_hash4_bits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0x11(%rbp)
jle    1148 <blz_hash4_bits+0x28>
cmpl   $0x20,-0xc(%rbp)
setle  %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
movzbl (%rax),%eax
mov    -0x8(%rbp),%rcx
movzbl 0x1(%rcx),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x2(%rcx),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
mov    -0x8(%rbp),%rcx
movzbl 0x3(%rcx),%ecx
shl    $0x18,%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x9e3779b1,%edi
call   1040 <UINT32_C@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
imul   %ecx,%eax
mov    $0x20,%ecx
sub    -0xc(%rbp),%ecx
sar    %cl,%eax
cltq
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blz_hash4_bits>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
lea    -0x1(%rbx),%eax
xor    %edi,%edi
cmp    $0x20,%eax
setb   %dil
call   1030 <assert@plt>
mov    (%r14),%ebp
mov    $0x9e3779b1,%edi
call   1040 <UINT32_C@plt>
imul   %ebp,%eax
neg    %bl
mov    %ebx,%ecx
sar    %cl,%eax
cltq
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i64 @blz_hash4_bits(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* %4
%10 = icmp sle i32 %9, 32
br label %11
11: ; preds = %8, %2
%12 = phi i1 [ false, %2 ], [ %10, %8 ]
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %3
%16 = getelementptr inbounds i8, i8* %15, i64 0
%17 = load i8, i8* %16
%18 = zext i8 %17 to i32
%19 = load i8*, i8** %3
%20 = getelementptr inbounds i8, i8* %19, i64 1
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = shl i32 %22, 8
%24 = or i32 %18, %23
%25 = load i8*, i8** %3
%26 = getelementptr inbounds i8, i8* %25, i64 2
%27 = load i8, i8* %26
%28 = zext i8 %27 to i32
%29 = shl i32 %28, 16
%30 = or i32 %24, %29
%31 = load i8*, i8** %3
%32 = getelementptr inbounds i8, i8* %31, i64 3
%33 = load i8, i8* %32
%34 = zext i8 %33 to i32
%35 = shl i32 %34, 24
%36 = or i32 %30, %35
store i32 %36, i32* %5
%37 = load i32, i32* %5
%38 = call i32 @UINT32_C(i32 -1640531535)
%39 = mul nsw i32 %37, %38
%40 = load i32, i32* %4
%41 = sub nsw i32 32, %40
%42 = ashr i32 %39, %41
%43 = sext i32 %42 to i64
ret i64 %43
}

LLVM IR (-O2):
define i64 @blz_hash4_bits(i8* nocapture %0, i32 %1) {
%3 = add i32 %1, -1
%4 = icmp ult i32 %3, 32
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = load i8, i8* %0
%8 = zext i8 %7 to i32
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = load i8, i8* %9
%11 = zext i8 %10 to i32
%12 = shl nuw nsw i32 %11, 8
%13 = or i32 %12, %8
%14 = getelementptr inbounds i8, i8* %0, i64 2
%15 = load i8, i8* %14
%16 = zext i8 %15 to i32
%17 = shl nuw nsw i32 %16, 16
%18 = or i32 %13, %17
%19 = getelementptr inbounds i8, i8* %0, i64 3
%20 = load i8, i8* %19
%21 = zext i8 %20 to i32
%22 = shl nuw i32 %21, 24
%23 = or i32 %18, %22
%24 = tail call i32 @UINT32_C(i32 -1640531535)
%25 = mul nsw i32 %23, %24
%26 = sub nsw i32 32, %1
%27 = ashr i32 %25, %26
%28 = sext i32 %27 to i64
ret i64 %28
}