#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 */

/* Variables and functions */
unsigned long drmRandom(void *);
void *drmRandomCreate(int);
unsigned long HashHash(unsigned long key) {
  unsigned long hash = 0;
  unsigned long tmp = key;
  static int init = 0;
  static unsigned long scatter[256];
  int i;
  if (!init) {
    void *state;
    state = drmRandomCreate(37);
    for (i = 0; i < 256; i++)
      scatter[i] = drmRandom(state);
    ++init;
  }
  while (tmp) {
    hash = (hash << 1) + scatter[tmp & 0xff];
    tmp >>= 8;
  }
  hash %= 512;
  return hash;
}


x86 assembly (clang, -O0):
<HashHash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,0x2efd(%rip)
jne    11a3 <HashHash+0x83>
mov    $0x25,%edi
call   1030 <drmRandomCreate@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    1194 <HashHash+0x74>
mov    -0x28(%rbp),%rdi
call   1040 <drmRandom@plt>
mov    %rax,%rdx
movslq -0x1c(%rbp),%rcx
lea    0x2ece(%rip),%rax
mov    %rdx,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115e <HashHash+0x3e>
mov    0x2ea6(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e9d(%rip)
jmp    11a8 <HashHash+0x88>
cmpq   $0x0,-0x18(%rbp)
je     11e6 <HashHash+0xc6>
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    -0x18(%rbp),%rdx
and    $0xff,%rdx
lea    0x2e83(%rip),%rcx
add    (%rcx,%rdx,8),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    11a8 <HashHash+0x88>
mov    -0x10(%rbp),%rax
and    $0x1ff,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HashHash>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
cmpl   $0x0,0x2f0e(%rip)
jne    1170 <HashHash+0x50>
mov    $0x25,%edi
call   1030 <drmRandomCreate@plt>
mov    %rax,%r14
xor    %ebx,%ebx
lea    0x2f06(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <drmRandom@plt>
mov    %rax,(%rbx,%r12,1)
add    $0x8,%rbx
cmp    $0x800,%rbx
jne    1150 <HashHash+0x30>
addl   $0x1,0x2ed0(%rip)
xor    %eax,%eax
test   %r15,%r15
je     11b0 <HashHash+0x90>
lea    0x2ed2(%rip),%rcx
mov    %r15,%rdx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    %rax,%rax
movzbl %r15b,%esi
add    (%rcx,%rsi,8),%rax
shr    $0x8,%rdx
cmp    $0xff,%r15
mov    %rdx,%r15
ja     1190 <HashHash+0x70>
and    $0x1ff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@HashHash.init = internal global i32 0
@HashHash.scatter = internal global [256 x i64] zeroinitializer
define i64 @HashHash(i64 %0) {
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8*
store i64 %0, i64* %2
store i64 0, i64* %3
%7 = load i64, i64* %2
store i64 %7, i64* %4
%8 = load i32, i32* @HashHash.init
%9 = icmp ne i32 %8, 0
br i1 %9, label %27, label %10
10: ; preds = %1
%11 = call i8* @drmRandomCreate(i32 37)
store i8* %11, i8** %6
store i32 0, i32* %5
br label %12
12: ; preds = %21, %10
%13 = load i32, i32* %5
%14 = icmp slt i32 %13, 256
br i1 %14, label %15, label %24
15: ; preds = %12
%16 = load i8*, i8** %6
%17 = call i64 @drmRandom(i8* %16)
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [256 x i64], [256 x i64]* @HashHash.scatter, i64 0, i64 %19
store i64 %17, i64* %20
br label %21
21: ; preds = %15
%22 = load i32, i32* %5
%23 = add nsw i32 %22, 1
store i32 %23, i32* %5
br label %12
24: ; preds = %12
%25 = load i32, i32* @HashHash.init
%26 = add nsw i32 %25, 1
store i32 %26, i32* @HashHash.init
br label %27
27: ; preds = %24, %1
br label %28
28: ; preds = %31, %27
%29 = load i64, i64* %4
%30 = icmp ne i64 %29, 0
br i1 %30, label %31, label %41
31: ; preds = %28
%32 = load i64, i64* %3
%33 = shl i64 %32, 1
%34 = load i64, i64* %4
%35 = and i64 %34, 255
%36 = getelementptr inbounds [256 x i64], [256 x i64]* @HashHash.scatter, i64 0, i64 %35
%37 = load i64, i64* %36
%38 = add i64 %33, %37
store i64 %38, i64* %3
%39 = load i64, i64* %4
%40 = lshr i64 %39, 8
store i64 %40, i64* %4
br label %28
41: ; preds = %28
%42 = load i64, i64* %3
%43 = urem i64 %42, 512
store i64 %43, i64* %3
%44 = load i64, i64* %3
ret i64 %44
}

LLVM IR (-O2):
@HashHash.init = internal unnamed_addr global i32 0
@HashHash.scatter = internal unnamed_addr global [256 x i64] zeroinitializer
define i64 @HashHash(i64 %0) {
%2 = load i32, i32* @HashHash.init
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = tail call i8* @drmRandomCreate(i32 37)
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %10, %6 ]
%8 = tail call i64 @drmRandom(i8* %5)
%9 = getelementptr inbounds [256 x i64], [256 x i64]* @HashHash.scatter, i64 0, i64 %7
store i64 %8, i64* %9
%10 = add nuw nsw i64 %7, 1
%11 = icmp eq i64 %10, 256
br i1 %11, label %12, label %6
12: ; preds = %6
%13 = load i32, i32* @HashHash.init
%14 = add nsw i32 %13, 1
store i32 %14, i32* @HashHash.init
br label %15
15: ; preds = %12, %1
%16 = icmp eq i64 %0, 0
br i1 %16, label %29, label %17
17: ; preds = %15, %17
%18 = phi i64 [ %24, %17 ], [ 0, %15 ]
%19 = phi i64 [ %25, %17 ], [ %0, %15 ]
%20 = shl i64 %18, 1
%21 = and i64 %19, 255
%22 = getelementptr inbounds [256 x i64], [256 x i64]* @HashHash.scatter, i64 0, i64 %21
%23 = load i64, i64* %22
%24 = add i64 %23, %20
%25 = lshr i64 %19, 8
%26 = icmp ult i64 %19, 256
br i1 %26, label %27, label %17
27: ; preds = %17
%28 = and i64 %24, 511
br label %29
29: ; preds = %27, %15
%30 = phi i64 [ 0, %15 ], [ %28, %27 ]
ret i64 %30
}