#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 */
double fabs(double);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
double xt_core_random_01();
double xt_core_random_gaussian(int, double);
scalar_t__ xt_core_random_poisson(int);
int /*<<< orphan*/ xt_core_trace_exit(char *, double, ...);
int main(int argc, char *argv[]) {
  unsigned long ii = 0;
  double value = 0.0;
  double total = 0.0;
  double average = 0.0;
  srand(time(0));
  value = 0.0;
  total = 0.0;
  average = 0.0;
  for (ii = 0; ii < 30000; ii++) {
    value = xt_core_random_01();
    total += value;
  }
  average = (total / 30000);
  value = fabs(average - .5);
  if (value > 0.01) {
    xt_core_trace_exit("FAILED: Uniform random average: %f", average);
  }
  value = 0.0;
  total = 0.0;
  average = 0.0;
  for (ii = 0; ii < 30000; ii++) {
    value = (double)xt_core_random_poisson(3);
    total += value;
  }
  average = (total / 30000);
  value = fabs(average - 3);
  if (value > 0.05) {
    xt_core_trace_exit("FAILED: Poisson random average: %f vs %f", average,
                       (double)3);
  }
  value = 0.0;
  total = 0.0;
  average = 0.0;
  for (ii = 0; ii < 30000; ii++) {
    value = xt_core_random_gaussian(5, 2.0);
    total += value;
  }
  average = (total / 30000);
  value = fabs(average - 5);
  if (value > 0.05) {
    xt_core_trace_exit("FAILED: Gaussian random average: %f vs %f", average,
                       (double)5);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x7530,-0x18(%rbp)
jae    11fe <main+0x9e>
mov    $0x0,%al
call   1030 <xt_core_random_01@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    11c4 <main+0x64>
movsd  -0x28(%rbp),%xmm0
movsd  0xe05(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xde7(%rip),%xmm1
subsd  %xmm1,%xmm0
movaps 0xe14(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xdbe(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    125f <main+0xff>
movsd  -0x30(%rbp),%xmm0
lea    0xdf8(%rip),%rdi
mov    $0x1,%al
call   1060 <xt_core_trace_exit@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x7530,-0x18(%rbp)
jae    12c1 <main+0x161>
mov    $0x3,%edi
call   1080 <xt_core_random_poisson@plt>
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    127f <main+0x11f>
movsd  -0x28(%rbp),%xmm0
movsd  0xd42(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xd3c(%rip),%xmm1
subsd  %xmm1,%xmm0
movaps 0xd51(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xd13(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    132a <main+0x1ca>
movsd  -0x30(%rbp),%xmm0
lea    0xd58(%rip),%rdi
movsd  0xcfd(%rip),%xmm1
mov    $0x2,%al
call   1060 <xt_core_trace_exit@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x7530,-0x18(%rbp)
jae    138f <main+0x22f>
mov    $0x5,%edi
movsd  0xccb(%rip),%xmm0
call   1050 <xt_core_random_gaussian@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    134a <main+0x1ea>
movsd  -0x28(%rbp),%xmm0
movsd  0xc74(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xc76(%rip),%xmm1
subsd  %xmm1,%xmm0
movaps 0xc83(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xc45(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    13f8 <main+0x298>
movsd  -0x30(%rbp),%xmm0
lea    0xcb3(%rip),%rdi
movsd  0xc37(%rip),%xmm1
mov    $0x2,%al
call   1060 <xt_core_trace_exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
xorpd  %xmm1,%xmm1
mov    $0x7530,%ebx
nopl   0x0(%rax)
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <xt_core_random_01@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
add    $0xffffffffffffffff,%rbx
jne    1180 <main+0x20>
divsd  0xe5b(%rip),%xmm1
movsd  0xe5b(%rip),%xmm0
addsd  %xmm1,%xmm0
andpd  0xe97(%rip),%xmm0
ucomisd 0xe4f(%rip),%xmm0
jbe    11d5 <main+0x75>
lea    0xe96(%rip),%rdi
movapd %xmm1,%xmm0
mov    $0x1,%al
call   1060 <xt_core_trace_exit@plt>
xorpd  %xmm0,%xmm0
mov    $0x7530,%ebx
xchg   %ax,%ax
movsd  %xmm0,0x8(%rsp)
mov    $0x3,%edi
call   1080 <xt_core_random_poisson@plt>
movsd  0x8(%rsp),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
add    $0xffffffffffffffff,%rbx
jne    11e0 <main+0x80>
divsd  0xdf0(%rip),%xmm0
movsd  0xe00(%rip),%xmm1
addsd  %xmm0,%xmm1
andpd  0xe2c(%rip),%xmm1
ucomisd 0xdf4(%rip),%xmm1
jbe    1244 <main+0xe4>
lea    0xe4e(%rip),%rdi
movsd  0xdeb(%rip),%xmm1
mov    $0x2,%al
call   1060 <xt_core_trace_exit@plt>
xorpd  %xmm2,%xmm2
mov    $0x7530,%ebx
nopl   (%rax)
movsd  %xmm2,0x8(%rsp)
mov    $0x5,%edi
movsd  0xdcd(%rip),%xmm0
call   1050 <xt_core_random_gaussian@plt>
movsd  0x8(%rsp),%xmm2
addsd  %xmm0,%xmm2
add    $0xffffffffffffffff,%rbx
jne    1250 <main+0xf0>
divsd  0xd80(%rip),%xmm2
movsd  0xdb0(%rip),%xmm0
addsd  %xmm2,%xmm0
andpd  0xdbc(%rip),%xmm0
ucomisd 0xd84(%rip),%xmm0
jbe    12b8 <main+0x158>
lea    0xe07(%rip),%rdi
movsd  0xd93(%rip),%xmm1
movapd %xmm2,%xmm0
mov    $0x2,%al
call   1060 <xt_core_trace_exit@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"FAILED: Uniform random average: %f\00"
@.str.1 = [41 x i8] c"FAILED: Poisson random average: %f vs %f\00"
@.str.2 = [42 x i8] c"FAILED: Gaussian random average: %f vs %f\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca double
%8 = alloca double
%9 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 0, i64* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
%10 = call i32 @time(i32 0)
%11 = call i32 @srand(i32 %10)
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
store i64 0, i64* %6
br label %12
12: ; preds = %20, %2
%13 = load i64, i64* %6
%14 = icmp ult i64 %13, 30000
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = call double (...) @xt_core_random_01()
store double %16, double* %7
%17 = load double, double* %7
%18 = load double, double* %8
%19 = fadd double %18, %17
store double %19, double* %8
br label %20
20: ; preds = %15
%21 = load i64, i64* %6
%22 = add i64 %21, 1
store i64 %22, i64* %6
br label %12
23: ; preds = %12
%24 = load double, double* %8
%25 = fdiv double %24, 3.000000e+04
store double %25, double* %9
%26 = load double, double* %9
%27 = fsub double %26, 5.000000e-01
%28 = call double @llvm.fabs.f64(double %27)
store double %28, double* %7
%29 = load double, double* %7
%30 = fcmp ogt double %29, 1.000000e-02
br i1 %30, label %31, label %34
31: ; preds = %23
%32 = load double, double* %9
%33 = call i32 (i8*, double, ...) @xt_core_trace_exit(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), double %32)
br label %34
34: ; preds = %31, %23
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
store i64 0, i64* %6
br label %35
35: ; preds = %44, %34
%36 = load i64, i64* %6
%37 = icmp ult i64 %36, 30000
br i1 %37, label %38, label %47
38: ; preds = %35
%39 = call i64 @xt_core_random_poisson(i32 3)
%40 = sitofp i64 %39 to double
store double %40, double* %7
%41 = load double, double* %7
%42 = load double, double* %8
%43 = fadd double %42, %41
store double %43, double* %8
br label %44
44: ; preds = %38
%45 = load i64, i64* %6
%46 = add i64 %45, 1
store i64 %46, i64* %6
br label %35
47: ; preds = %35
%48 = load double, double* %8
%49 = fdiv double %48, 3.000000e+04
store double %49, double* %9
%50 = load double, double* %9
%51 = fsub double %50, 3.000000e+00
%52 = call double @llvm.fabs.f64(double %51)
store double %52, double* %7
%53 = load double, double* %7
%54 = fcmp ogt double %53, 5.000000e-02
br i1 %54, label %55, label %58
55: ; preds = %47
%56 = load double, double* %9
%57 = call i32 (i8*, double, ...) @xt_core_trace_exit(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), double %56, double 3.000000e+00)
br label %58
58: ; preds = %55, %47
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
store i64 0, i64* %6
br label %59
59: ; preds = %67, %58
%60 = load i64, i64* %6
%61 = icmp ult i64 %60, 30000
br i1 %61, label %62, label %70
62: ; preds = %59
%63 = call double @xt_core_random_gaussian(i32 5, double 2.000000e+00)
store double %63, double* %7
%64 = load double, double* %7
%65 = load double, double* %8
%66 = fadd double %65, %64
store double %66, double* %8
br label %67
67: ; preds = %62
%68 = load i64, i64* %6
%69 = add i64 %68, 1
store i64 %69, i64* %6
br label %59
70: ; preds = %59
%71 = load double, double* %8
%72 = fdiv double %71, 3.000000e+04
store double %72, double* %9
%73 = load double, double* %9
%74 = fsub double %73, 5.000000e+00
%75 = call double @llvm.fabs.f64(double %74)
store double %75, double* %7
%76 = load double, double* %7
%77 = fcmp ogt double %76, 5.000000e-02
br i1 %77, label %78, label %81
78: ; preds = %70
%79 = load double, double* %9
%80 = call i32 (i8*, double, ...) @xt_core_trace_exit(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), double %79, double 5.000000e+00)
br label %81
81: ; preds = %78, %70
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"FAILED: Uniform random average: %f\00"
@.str.1 = [41 x i8] c"FAILED: Poisson random average: %f vs %f\00"
@.str.2 = [42 x i8] c"FAILED: Gaussian random average: %f vs %f\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 @time(i32 0)
%4 = tail call i32 @srand(i32 %3)
br label %5
5: ; preds = %2, %5
%6 = phi double [ 0.000000e+00, %2 ], [ %9, %5 ]
%7 = phi i64 [ 0, %2 ], [ %10, %5 ]
%8 = tail call double (...) @xt_core_random_01()
%9 = fadd double %6, %8
%10 = add nuw nsw i64 %7, 1
%11 = icmp eq i64 %10, 30000
br i1 %11, label %12, label %5
12: ; preds = %5
%13 = fdiv double %9, 3.000000e+04
%14 = fadd double %13, -5.000000e-01
%15 = tail call double @llvm.fabs.f64(double %14)
%16 = fcmp ogt double %15, 1.000000e-02
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = tail call i32 (i8*, double, ...) @xt_core_trace_exit(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), double %13)
br label %19
19: ; preds = %17, %12
br label %20
20: ; preds = %19, %20
%21 = phi double [ %25, %20 ], [ 0.000000e+00, %19 ]
%22 = phi i64 [ %26, %20 ], [ 0, %19 ]
%23 = tail call i64 @xt_core_random_poisson(i32 3)
%24 = sitofp i64 %23 to double
%25 = fadd double %21, %24
%26 = add nuw nsw i64 %22, 1
%27 = icmp eq i64 %26, 30000
br i1 %27, label %28, label %20
28: ; preds = %20
%29 = fdiv double %25, 3.000000e+04
%30 = fadd double %29, -3.000000e+00
%31 = tail call double @llvm.fabs.f64(double %30)
%32 = fcmp ogt double %31, 5.000000e-02
br i1 %32, label %33, label %35
33: ; preds = %28
%34 = tail call i32 (i8*, double, ...) @xt_core_trace_exit(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), double %29, double 3.000000e+00)
br label %35
35: ; preds = %33, %28
br label %36
36: ; preds = %35, %36
%37 = phi double [ %40, %36 ], [ 0.000000e+00, %35 ]
%38 = phi i64 [ %41, %36 ], [ 0, %35 ]
%39 = tail call double @xt_core_random_gaussian(i32 5, double 2.000000e+00)
%40 = fadd double %37, %39
%41 = add nuw nsw i64 %38, 1
%42 = icmp eq i64 %41, 30000
br i1 %42, label %43, label %36
43: ; preds = %36
%44 = fdiv double %40, 3.000000e+04
%45 = fadd double %44, -5.000000e+00
%46 = tail call double @llvm.fabs.f64(double %45)
%47 = fcmp ogt double %46, 5.000000e-02
br i1 %47, label %48, label %50
48: ; preds = %43
%49 = tail call i32 (i8*, double, ...) @xt_core_trace_exit(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), double %44, double 5.000000e+00)
br label %50
50: ; preds = %48, %43
ret i32 0
}