#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 */
size_t rand5();
int test_rand5() {
  int counter[5] = {0};
  for (int i = 0; i < 5000000; i++) {
    counter[rand5()]++;
  }
  for (int i = 0; i < 5; i++) {
    double error = (counter[i] - 1000000) / 1000000.0;
    if (error > 0.01)
      return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<test_rand5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1040 <memset@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4c4b40,-0x24(%rbp)
jge    116c <test_rand5+0x4c>
mov    $0x0,%al
call   1030 <rand5@plt>
mov    -0x20(%rbp,%rax,4),%ecx
add    $0x1,%ecx
mov    %ecx,-0x20(%rbp,%rax,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    113f <test_rand5+0x1f>
movl   $0x0,-0x28(%rbp)
cmpl   $0x5,-0x28(%rbp)
jge    11d5 <test_rand5+0xb5>
movslq -0x28(%rbp),%rax
mov    -0x20(%rbp,%rax,4),%eax
sub    $0xf4240,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe72(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xe54(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c2 <test_rand5+0xa2>
movl   $0x0,-0x4(%rbp)
jmp    11dc <test_rand5+0xbc>
jmp    11c7 <test_rand5+0xa7>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1173 <test_rand5+0x53>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_rand5>:
push   %rbx
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
mov    $0x4c4b40,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <rand5@plt>
addl   $0x1,(%rsp,%rax,4)
add    $0xffffffff,%ebx
jne    1130 <test_rand5+0x20>
mov    $0xfff0bdc0,%ecx
mov    (%rsp),%eax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xea7(%rip),%xmm0
xor    %eax,%eax
ucomisd 0xea5(%rip),%xmm0
ja     11ee <test_rand5+0xde>
add    0x4(%rsp),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
divsd  0xe84(%rip),%xmm0
ucomisd 0xe84(%rip),%xmm0
ja     11ee <test_rand5+0xde>
mov    $0xfff0bdc0,%ecx
mov    0x8(%rsp),%edx
add    %ecx,%edx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
divsd  0xe60(%rip),%xmm0
ucomisd 0xe60(%rip),%xmm0
ja     11ee <test_rand5+0xde>
add    0xc(%rsp),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
divsd  0xe43(%rip),%xmm0
ucomisd 0xe43(%rip),%xmm0
ja     11ee <test_rand5+0xde>
mov    $0xfff0bdc0,%ecx
add    0x10(%rsp),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
divsd  0xe21(%rip),%xmm0
ucomisd 0xe21(%rip),%xmm0
ja     11ee <test_rand5+0xde>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @test_rand5() {
%1 = alloca i32
%2 = alloca [5 x i32]
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = bitcast [5 x i32]* %2 to i8*
store i32 0, i32* %3
br label %7
7: ; preds = %15, %0
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 5000000
br i1 %9, label %10, label %18
10: ; preds = %7
%11 = call i64 (...) @rand5()
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 %11
%13 = load i32, i32* %12
%14 = add nsw i32 %13, 1
store i32 %14, i32* %12
br label %15
15: ; preds = %10
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %7
18: ; preds = %7
store i32 0, i32* %4
br label %19
19: ; preds = %34, %18
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 5
br i1 %21, label %22, label %37
22: ; preds = %19
%23 = load i32, i32* %4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [5 x i32], [5 x i32]* %2, i64 0, i64 %24
%26 = load i32, i32* %25
%27 = sub nsw i32 %26, 1000000
%28 = sitofp i32 %27 to double
%29 = fdiv double %28, 1.000000e+06
store double %29, double* %5
%30 = load double, double* %5
%31 = fcmp ogt double %30, 1.000000e-02
br i1 %31, label %32, label %33
32: ; preds = %22
store i32 0, i32* %1
br label %38
33: ; preds = %22
br label %34
34: ; preds = %33
%35 = load i32, i32* %4
%36 = add nsw i32 %35, 1
store i32 %36, i32* %4
br label %19
37: ; preds = %19
store i32 1, i32* %1
br label %38
38: ; preds = %37, %32
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
define i32 @test_rand5() {
%1 = alloca [5 x i32]
%2 = bitcast [5 x i32]* %1 to i8*
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 0, %0 ], [ %9, %3 ]
%5 = tail call i64 (...) @rand5()
%6 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 %5
%7 = load i32, i32* %6
%8 = add nsw i32 %7, 1
store i32 %8, i32* %6
%9 = add nuw nsw i32 %4, 1
%10 = icmp eq i32 %9, 5000000
br i1 %10, label %11, label %3
11: ; preds = %3
%12 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 0
%13 = load i32, i32* %12
%14 = add nsw i32 %13, -1000000
%15 = sitofp i32 %14 to double
%16 = fdiv double %15, 1.000000e+06
%17 = fcmp ogt double %16, 1.000000e-02
br i1 %17, label %47, label %18
18: ; preds = %11
%19 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 1
%20 = load i32, i32* %19
%21 = add nsw i32 %20, -1000000
%22 = sitofp i32 %21 to double
%23 = fdiv double %22, 1.000000e+06
%24 = fcmp ogt double %23, 1.000000e-02
br i1 %24, label %47, label %25
25: ; preds = %18
%26 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 2
%27 = load i32, i32* %26
%28 = add nsw i32 %27, -1000000
%29 = sitofp i32 %28 to double
%30 = fdiv double %29, 1.000000e+06
%31 = fcmp ogt double %30, 1.000000e-02
br i1 %31, label %47, label %32
32: ; preds = %25
%33 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 3
%34 = load i32, i32* %33
%35 = add nsw i32 %34, -1000000
%36 = sitofp i32 %35 to double
%37 = fdiv double %36, 1.000000e+06
%38 = fcmp ogt double %37, 1.000000e-02
br i1 %38, label %47, label %39
39: ; preds = %32
%40 = getelementptr inbounds [5 x i32], [5 x i32]* %1, i64 0, i64 4
%41 = load i32, i32* %40
%42 = add nsw i32 %41, -1000000
%43 = sitofp i32 %42 to double
%44 = fdiv double %43, 1.000000e+06
%45 = fcmp ogt double %44, 1.000000e-02
br i1 %45, label %47, label %46
46: ; preds = %39
br label %47
47: ; preds = %46, %39, %32, %25, %18, %11
%48 = phi i32 [ 0, %11 ], [ 0, %18 ], [ 0, %25 ], [ 0, %32 ], [ 0, %39 ], [ 1, %46 ]
ret i32 %48
}