#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);
int /*<<< orphan*/ drmRandomDestroy(void *);
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);
    drmRandomDestroy(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    11bc <HashHash+0x8c>
mov    $0x25,%edi
call   1040 <drmRandomCreate@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x100,-0x1c(%rbp)
jge    11a4 <HashHash+0x74>
mov    -0x28(%rbp),%rdi
call   1050 <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    116e <HashHash+0x3e>
mov    -0x28(%rbp),%rdi
call   1030 <drmRandomDestroy@plt>
mov    0x2e9d(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e94(%rip)
jmp    11c1 <HashHash+0x91>
cmpq   $0x0,-0x18(%rbp)
je     11ff <HashHash+0xcf>
mov    -0x10(%rbp),%rax
shl    $0x1,%rax
mov    -0x18(%rbp),%rdx
and    $0xff,%rdx
lea    0x2e7a(%rip),%rcx
add    (%rcx,%rdx,8),%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
shr    $0x8,%rax
mov    %rax,-0x18(%rbp)
jmp    11c1 <HashHash+0x91>
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    1188 <HashHash+0x58>
mov    $0x25,%edi
call   1040 <drmRandomCreate@plt>
mov    %rax,%r14
xor    %ebx,%ebx
lea    0x2f06(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1050 <drmRandom@plt>
mov    %rax,(%rbx,%r12,1)
add    $0x8,%rbx
cmp    $0x800,%rbx
jne    1160 <HashHash+0x30>
mov    %r14,%rdi
call   1030 <drmRandomDestroy@plt>
addl   $0x1,0x2ec8(%rip)
xor    %eax,%eax
test   %r15,%r15
je     11c0 <HashHash+0x90>
lea    0x2eca(%rip),%rcx
mov    %r15,%rdx
nopl   0x0(%rax)
add    %rax,%rax
movzbl %r15b,%esi
add    (%rcx,%rsi,8),%rax
shr    $0x8,%rdx
cmp    $0xff,%r15
mov    %rdx,%r15
ja     11a0 <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 %29, 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 i8*, i8** %6
%26 = call i32 @drmRandomDestroy(i8* %25)
%27 = load i32, i32* @HashHash.init
%28 = add nsw i32 %27, 1
store i32 %28, i32* @HashHash.init
br label %29
29: ; preds = %24, %1
br label %30
30: ; preds = %33, %29
%31 = load i64, i64* %4
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %43
33: ; preds = %30
%34 = load i64, i64* %3
%35 = shl i64 %34, 1
%36 = load i64, i64* %4
%37 = and i64 %36, 255
%38 = getelementptr inbounds [256 x i64], [256 x i64]* @HashHash.scatter, i64 0, i64 %37
%39 = load i64, i64* %38
%40 = add i64 %35, %39
store i64 %40, i64* %3
%41 = load i64, i64* %4
%42 = lshr i64 %41, 8
store i64 %42, i64* %4
br label %30
43: ; preds = %30
%44 = load i64, i64* %3
%45 = urem i64 %44, 512
store i64 %45, i64* %3
%46 = load i64, i64* %3
ret i64 %46
}

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 %16
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 = tail call i32 @drmRandomDestroy(i8* %5)
%14 = load i32, i32* @HashHash.init
%15 = add nsw i32 %14, 1
store i32 %15, i32* @HashHash.init
br label %16
16: ; preds = %12, %1
%17 = icmp eq i64 %0, 0
br i1 %17, label %30, label %18
18: ; preds = %16, %18
%19 = phi i64 [ %25, %18 ], [ 0, %16 ]
%20 = phi i64 [ %26, %18 ], [ %0, %16 ]
%21 = shl i64 %19, 1
%22 = and i64 %20, 255
%23 = getelementptr inbounds [256 x i64], [256 x i64]* @HashHash.scatter, i64 0, i64 %22
%24 = load i64, i64* %23
%25 = add i64 %24, %21
%26 = lshr i64 %20, 8
%27 = icmp ult i64 %20, 256
br i1 %27, label %28, label %18
28: ; preds = %18
%29 = and i64 %25, 511
br label %30
30: ; preds = %28, %16
%31 = phi i64 [ 0, %16 ], [ %29, %28 ]
ret i64 %31
}