#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 */
int /*<<< orphan*/ bias_hash(int, int, int);
scalar_t__ count_collisions(int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ free(int *);
int *malloc(int);
int rand();
int test_pval(int pval, int num_runs, int len) {
  int *data = malloc(sizeof(*data) * num_runs);
  int i, a, b, collisions = 0;
  for (i = 0; i < num_runs; i++) {
    a = rand() % (2 * len) - len;
    b = rand() % (2 * len) - len;
    collisions += count_collisions(bias_hash(a, b, pval), data, i);
  }
  free(data);
  return collisions;
}


x86 assembly (clang, -O0):
<test_pval>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11f1 <test_pval+0xa1>
mov    $0x0,%al
call   1070 <rand@plt>
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cltd
idiv   %ecx
sub    -0xc(%rbp),%edx
mov    %edx,-0x20(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cltd
idiv   %ecx
sub    -0xc(%rbp),%edx
mov    %edx,-0x24(%rbp)
mov    -0x20(%rbp),%edi
mov    -0x24(%rbp),%esi
mov    -0x4(%rbp),%edx
call   1040 <bias_hash@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1060 <count_collisions@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1182 <test_pval+0x32>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_pval>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,0x10(%rsp)
mov    %esi,%r14d
mov    %edi,%r15d
lea    0x0(,%r14,4),%edi
call   1050 <malloc@plt>
mov    %rax,%r12
test   %r14d,%r14d
jle    11fc <test_pval+0xac>
mov    0x10(%rsp),%rax
add    %eax,%eax
mov    %eax,0xc(%rsp)
xor    %ebp,%ebp
xor    %ebx,%ebx
mov    %r12,0x20(%rsp)
mov    %r14,0x18(%rsp)
mov    0xc(%rsp),%r13d
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <rand@plt>
cltd
idiv   %r13d
mov    %edx,%r12d
mov    0x10(%rsp),%rax
mov    %r15d,%r14d
mov    %rax,%r15
sub    %r15d,%r12d
xor    %eax,%eax
call   1070 <rand@plt>
cltd
idiv   %r13d
sub    %r15d,%edx
mov    %r14d,%r15d
mov    %r12d,%edi
mov    0x20(%rsp),%r12
mov    0x18(%rsp),%r14
mov    %edx,%esi
mov    %r15d,%edx
call   1040 <bias_hash@plt>
mov    %eax,%edi
mov    %r12,%rsi
mov    %ebx,%edx
call   1060 <count_collisions@plt>
add    %eax,%ebp
add    $0x1,%ebx
cmp    %ebx,%r14d
jne    11a0 <test_pval+0x50>
jmp    11fe <test_pval+0xae>
xor    %ebp,%ebp
mov    %r12,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @test_pval(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = mul i64 4, %13
%15 = trunc i64 %14 to i32
%16 = call i32* @malloc(i32 %15)
store i32* %16, i32** %7
store i32 0, i32* %11
store i32 0, i32* %8
br label %17
17: ; preds = %45, %3
%18 = load i32, i32* %8
%19 = load i32, i32* %5
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %48
21: ; preds = %17
%22 = call i32 (...) @rand()
%23 = load i32, i32* %6
%24 = mul nsw i32 2, %23
%25 = srem i32 %22, %24
%26 = load i32, i32* %6
%27 = sub nsw i32 %25, %26
store i32 %27, i32* %9
%28 = call i32 (...) @rand()
%29 = load i32, i32* %6
%30 = mul nsw i32 2, %29
%31 = srem i32 %28, %30
%32 = load i32, i32* %6
%33 = sub nsw i32 %31, %32
store i32 %33, i32* %10
%34 = load i32, i32* %9
%35 = load i32, i32* %10
%36 = load i32, i32* %4
%37 = call i32 @bias_hash(i32 %34, i32 %35, i32 %36)
%38 = load i32*, i32** %7
%39 = load i32, i32* %8
%40 = call i64 @count_collisions(i32 %37, i32* %38, i32 %39)
%41 = load i32, i32* %11
%42 = sext i32 %41 to i64
%43 = add nsw i64 %42, %40
%44 = trunc i64 %43 to i32
store i32 %44, i32* %11
br label %45
45: ; preds = %21
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %17
48: ; preds = %17
%49 = load i32*, i32** %7
%50 = call i32 @free(i32* %49)
%51 = load i32, i32* %11
ret i32 %51
}

LLVM IR (-O2):
define i32 @test_pval(i32 %0, i32 %1, i32 %2) {
%4 = shl i32 %1, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = icmp sgt i32 %1, 0
br i1 %6, label %7, label %24
7: ; preds = %3
%8 = shl nsw i32 %2, 1
br label %9
9: ; preds = %7, %9
%10 = phi i32 [ 0, %7 ], [ %21, %9 ]
%11 = phi i32 [ 0, %7 ], [ %22, %9 ]
%12 = tail call i32 (...) @rand()
%13 = srem i32 %12, %8
%14 = sub nsw i32 %13, %2
%15 = tail call i32 (...) @rand()
%16 = srem i32 %15, %8
%17 = sub nsw i32 %16, %2
%18 = tail call i32 @bias_hash(i32 %14, i32 %17, i32 %0)
%19 = tail call i64 @count_collisions(i32 %18, i32* %5, i32 %11)
%20 = trunc i64 %19 to i32
%21 = add i32 %10, %20
%22 = add nuw nsw i32 %11, 1
%23 = icmp eq i32 %22, %1
br i1 %23, label %24, label %9
24: ; preds = %9, %3
%25 = phi i32 [ 0, %3 ], [ %21, %9 ]
%26 = tail call i32 @free(i32* %5)
ret i32 %25
}