#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 */
float distributions_uniform(double, double);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
float sqrt(float);
void distributions_rantest() {
  int i;
  float x, sum, sum2, fmin, fmax;
  sum = sum2 = 0.0;
  fmin = 1.0e35;
  fmax = -1.0e35;
  printf("distributions_rantest- Calculating...\n");
  for (i = 0; i < 10000; i++) {
    x = distributions_uniform(-1.0, 1.0);
    if (x > fmax) {
      fmax = x;
    }
    if (x < fmin) {
      fmin = x;
    }
    sum += x;
    sum2 += (x * x);
  }
  sum /= 10000.0;
  sum2 = sqrt(sum2 / 10000.0 - sum * sum);
  printf("distributions_rantest- n: 10000 max: %f min: %f ave: %f sigma: %f\n",
         fmax, fmin, sum, sum2);
  if (fmax < 0.99 || fmax > 1.0 || fmin < -1.0 || fmin > -0.99) {
    printf("                     - ERROR in random number generator, check "
           "RAND_MAX.\n");
    printf("distributions_rantest- Good bye!\n");
    exit(0);
  }
  printf("distributions_rantest- RAND_MAX ok!\n");
}


x86 assembly (clang, -O0):
<distributions_rantest>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movss  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  0xea4(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  0xe93(%rip),%xmm0
movss  %xmm0,-0x18(%rbp)
lea    0xeb7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
cmpl   $0x2710,-0x4(%rbp)
jge    121d <distributions_rantest+0xdd>
movsd  0xe84(%rip),%xmm0
movsd  0xe74(%rip),%xmm1
call   1040 <distributions_uniform@plt>
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
ucomiss -0x18(%rbp),%xmm0
jbe    11c7 <distributions_rantest+0x87>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x8(%rbp),%xmm1
movss  -0x14(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jbe    11e4 <distributions_rantest+0xa4>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x8(%rbp),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
movss  -0x8(%rbp),%xmm2
movss  -0x10(%rbp),%xmm1
mulss  %xmm2,%xmm0
addss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    1187 <distributions_rantest+0x47>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xde2(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x10(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdc4(%rip),%xmm1
divsd  %xmm1,%xmm0
movss  -0xc(%rbp),%xmm1
mulss  -0xc(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1050 <sqrt@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movss  -0x14(%rbp),%xmm1
cvtss2sd %xmm1,%xmm1
movss  -0xc(%rbp),%xmm2
cvtss2sd %xmm2,%xmm2
movss  -0x10(%rbp),%xmm3
cvtss2sd %xmm3,%xmm3
lea    0xdbc(%rip),%rdi
mov    $0x4,%al
call   1030 <printf@plt>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd55(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     130e <distributions_rantest+0x1ce>
movss  -0x18(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd4a(%rip),%xmm1
ucomisd %xmm1,%xmm0
ja     130e <distributions_rantest+0x1ce>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xd37(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     130e <distributions_rantest+0x1ce>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xd24(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1331 <distributions_rantest+0x1f1>
lea    0xd85(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0xdce(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<distributions_rantest>:
push   %rbx
sub    $0x20,%rsp
lea    0xf27(%rip),%rdi
call   1030 <puts@plt>
xorps  %xmm0,%xmm0
movss  0xe94(%rip),%xmm2
movss  0xe90(%rip),%xmm3
mov    $0x2710,%ebx
xorps  %xmm4,%xmm4
nopl   0x0(%rax)
movss  %xmm0,0x18(%rsp)
movss  %xmm4,0x10(%rsp)
movss  %xmm2,0xc(%rsp)
movss  %xmm3,0x8(%rsp)
movsd  0xe78(%rip),%xmm0
movsd  0xe78(%rip),%xmm1
call   1050 <distributions_uniform@plt>
movss  0x10(%rsp),%xmm4
movaps %xmm0,%xmm3
maxss  0x8(%rsp),%xmm3
movaps %xmm0,%xmm2
minss  0xc(%rsp),%xmm2
addss  %xmm0,%xmm4
mulss  %xmm0,%xmm0
movss  0x18(%rsp),%xmm1
addss  %xmm0,%xmm1
movss  %xmm1,0x18(%rsp)
movss  0x18(%rsp),%xmm0
add    $0xffffffff,%ebx
jne    1180 <distributions_rantest+0x30>
divss  0xe18(%rip),%xmm4
cvtss2sd %xmm0,%xmm0
divsd  0xe2c(%rip),%xmm0
movaps %xmm4,%xmm1
mulss  %xmm4,%xmm1
cvtss2sd %xmm1,%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
movss  %xmm2,0xc(%rsp)
movss  %xmm3,0x8(%rsp)
jb     1229 <distributions_rantest+0xd9>
sqrtss %xmm0,%xmm0
jmp    1246 <distributions_rantest+0xf6>
movss  %xmm4,0x10(%rsp)
call   1060 <sqrt@plt>
movss  0x10(%rsp),%xmm4
movss  0x8(%rsp),%xmm3
movss  0xc(%rsp),%xmm2
cvtss2sd %xmm3,%xmm5
xorps  %xmm1,%xmm1
cvtss2sd %xmm2,%xmm1
movsd  %xmm1,0x18(%rsp)
xorps  %xmm2,%xmm2
cvtss2sd %xmm4,%xmm2
xorps  %xmm3,%xmm3
cvtss2sd %xmm0,%xmm3
lea    0xdd4(%rip),%rdi
movsd  %xmm5,0x10(%rsp)
movaps %xmm5,%xmm0
mov    $0x4,%al
call   1040 <printf@plt>
movsd  0x18(%rsp),%xmm0
ucomisd 0xda6(%rip),%xmm0
ja     12cb <distributions_rantest+0x17b>
movss  0x8(%rsp),%xmm0
ucomiss 0xd73(%rip),%xmm0
ja     12cb <distributions_rantest+0x17b>
movsd  0xd95(%rip),%xmm0
ucomisd 0x10(%rsp),%xmm0
ja     12cb <distributions_rantest+0x17b>
movss  0xd5d(%rip),%xmm0
ucomiss 0xc(%rsp),%xmm0
ja     12cb <distributions_rantest+0x17b>
lea    0xde8(%rip),%rdi
add    $0x20,%rsp
pop    %rbx
jmp    1030 <puts@plt>
lea    0xdfb(%rip),%rdi
call   1030 <puts@plt>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [39 x i8] c"distributions_rantest- Calculating...\0A\00"
@.str.1 = [67 x i8] c"distributions_rantest- n: 10000 max: %f min: %f ave: %f sigma: %f\0A\00"
@.str.2 = [74 x i8] c" - ERROR in random number generator, check RAND_MAX.\0A\00"
@.str.3 = [34 x i8] c"distributions_rantest- Good bye!\0A\00"
@.str.4 = [37 x i8] c"distributions_rantest- RAND_MAX ok!\0A\00"
define void @distributions_rantest() {
%1 = alloca i32
%2 = alloca float
%3 = alloca float
%4 = alloca float
%5 = alloca float
%6 = alloca float
store float 0.000000e+00, float* %4
store float 0.000000e+00, float* %3
store float 0x4733426180000000, float* %5
store float 0xC733426180000000, float* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %1
br label %8
8: ; preds = %32, %0
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 10000
br i1 %10, label %11, label %35
11: ; preds = %8
%12 = call float @distributions_uniform(double -1.000000e+00, double 1.000000e+00)
store float %12, float* %2
%13 = load float, float* %2
%14 = load float, float* %6
%15 = fcmp ogt float %13, %14
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load float, float* %2
store float %17, float* %6
br label %18
18: ; preds = %16, %11
%19 = load float, float* %2
%20 = load float, float* %5
%21 = fcmp olt float %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = load float, float* %2
store float %23, float* %5
br label %24
24: ; preds = %22, %18
%25 = load float, float* %2
%26 = load float, float* %3
%27 = fadd float %26, %25
store float %27, float* %3
%28 = load float, float* %2
%29 = load float, float* %2
%30 = load float, float* %4
%31 = call float @llvm.fmuladd.f32(float %28, float %29, float %30)
store float %31, float* %4
br label %32
32: ; preds = %24
%33 = load i32, i32* %1
%34 = add nsw i32 %33, 1
store i32 %34, i32* %1
br label %8
35: ; preds = %8
%36 = load float, float* %3
%37 = fpext float %36 to double
%38 = fdiv double %37, 1.000000e+04
%39 = fptrunc double %38 to float
store float %39, float* %3
%40 = load float, float* %4
%41 = fpext float %40 to double
%42 = fdiv double %41, 1.000000e+04
%43 = load float, float* %3
%44 = load float, float* %3
%45 = fmul float %43, %44
%46 = fpext float %45 to double
%47 = fsub double %42, %46
%48 = fptrunc double %47 to float
%49 = call float @sqrt(float %48)
store float %49, float* %4
%50 = load float, float* %6
%51 = fpext float %50 to double
%52 = load float, float* %5
%53 = fpext float %52 to double
%54 = load float, float* %3
%55 = fpext float %54 to double
%56 = load float, float* %4
%57 = fpext float %56 to double
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), double %51, double %53, double %55, double %57)
%59 = load float, float* %6
%60 = fpext float %59 to double
%61 = fcmp olt double %60, 0x3FEFAE147AE147AE
br i1 %61, label %74, label %62
62: ; preds = %35
%63 = load float, float* %6
%64 = fpext float %63 to double
%65 = fcmp ogt double %64, 1.000000e+00
br i1 %65, label %74, label %66
66: ; preds = %62
%67 = load float, float* %5
%68 = fpext float %67 to double
%69 = fcmp olt double %68, -1.000000e+00
br i1 %69, label %74, label %70
70: ; preds = %66
%71 = load float, float* %5
%72 = fpext float %71 to double
%73 = fcmp ogt double %72, 0xBFEFAE147AE147AE
br i1 %73, label %74, label %78
74: ; preds = %70, %66, %62, %35
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str.2, i64 0, i64 0))
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0))
%77 = call i32 @exit(i32 0)
unreachable
78: ; preds = %70
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [67 x i8] c"distributions_rantest- n: 10000 max: %f min: %f ave: %f sigma: %f\0A\00"
@str = [38 x i8] c"distributions_rantest- Calculating...\00"
@str.5 = [36 x i8] c"distributions_rantest- RAND_MAX ok!\00"
@str.6 = [73 x i8] c" - ERROR in random number generator, check RAND_MAX.\00"
@str.7 = [33 x i8] c"distributions_rantest- Good bye!\00"
define void @distributions_rantest() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
br label %2
2: ; preds = %0, %2
%3 = phi float [ 0xC733426180000000, %0 ], [ %10, %2 ]
%4 = phi float [ 0x4733426180000000, %0 ], [ %12, %2 ]
%5 = phi float [ 0.000000e+00, %0 ], [ %14, %2 ]
%6 = phi float [ 0.000000e+00, %0 ], [ %13, %2 ]
%7 = phi i32 [ 0, %0 ], [ %15, %2 ]
%8 = tail call float @distributions_uniform(double -1.000000e+00, double 1.000000e+00)
%9 = fcmp ogt float %8, %3
%10 = select i1 %9, float %8, float %3
%11 = fcmp olt float %8, %4
%12 = select i1 %11, float %8, float %4
%13 = fadd float %6, %8
%14 = tail call float @llvm.fmuladd.f32(float %8, float %8, float %5)
%15 = add nuw nsw i32 %7, 1
%16 = icmp eq i32 %15, 10000
br i1 %16, label %17, label %2
17: ; preds = %2
%18 = fdiv float %13, 1.000000e+04
%19 = fpext float %14 to double
%20 = fdiv double %19, 1.000000e+04
%21 = fmul float %18, %18
%22 = fpext float %21 to double
%23 = fsub double %20, %22
%24 = fptrunc double %23 to float
%25 = tail call float @sqrt(float %24)
%26 = fpext float %10 to double
%27 = fpext float %12 to double
%28 = fpext float %18 to double
%29 = fpext float %25 to double
%30 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), double %26, double %27, double %28, double %29)
%31 = fcmp olt double %26, 0x3FEFAE147AE147AE
%32 = fcmp ogt float %10, 1.000000e+00
%33 = or i1 %32, %31
%34 = fcmp olt float %12, -1.000000e+00
%35 = select i1 %33, i1 true, i1 %34
%36 = fcmp ogt double %27, 0xBFEFAE147AE147AE
%37 = or i1 %36, %35
br i1 %37, label %38, label %42
38: ; preds = %17
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([73 x i8], [73 x i8]* @str.6, i64 0, i64 0))
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str.7, i64 0, i64 0))
%41 = tail call i32 @exit(i32 0)
unreachable
42: ; preds = %17
%43 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.5, i64 0, i64 0))
ret void
}