#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 EXIT_SUCCESS;
int abs(double);
double boxmuller();
int /*<<< orphan*/ boxmuller_init();
double cnormdist(double, int /*<<< orphan*/, int);
double count(double *, double, int);
int /*<<< orphan*/ doubleAbs(double, double);
int /*<<< orphan*/ printf(char *, ...);
double stddev(double *, double, int);
int main(int argc, char **argv) {
  unsigned int i;
  double x = -3;
  int int_values = abs(x * 2);
  double inc = (double)int_values / (double)400;
  double array[400];
  double sum = 0, mean, sdev;
  boxmuller_init();
  for (i = 0; i < 400; i++)
    sum += (array[i] = boxmuller());
  mean = sum / (double)400;
  sdev = stddev(array, mean, 400);
  printf("#Box-Muller Gaussian Random Number Generator (GRNG)\n");
  printf("#GaussianRN\tNorm of GRN\tstd value\tStandardNorm\tDiff\n");
  double normX, normx;
  for (i = 0; i < 400; i++) {
    normX = count(array, x, 400);
    normx = cnormdist(x, 0, 1);
    printf("%lf\t%lf\t%lf\t%lf\t%lf\n", array[i], normX, x, normx,
           doubleAbs(normX, normx));
    x += inc;
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd00,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  0xe6f(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe5a(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1040 <abs@plt>
mov    %eax,-0x24(%rbp)
cvtsi2sdl -0x24(%rbp),%xmm0
movsd  0xe38(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0xcb8(%rbp)
ff
mov    $0x0,%al
call   1080 <boxmuller_init@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x190,-0x14(%rbp)
jae    1228 <main+0xa8>
mov    $0x0,%al
call   1090 <boxmuller@plt>
mov    -0x14(%rbp),%eax
movsd  %xmm0,-0xcb0(%rbp,%rax,8)
ff ff
addsd  -0xcb8(%rbp),%xmm0
ff
movsd  %xmm0,-0xcb8(%rbp)
ff
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ea <main+0x6a>
movsd  -0xcb8(%rbp),%xmm0
ff
movsd  0xdc8(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0xcc0(%rbp)
ff
lea    -0xcb0(%rbp),%rdi
movsd  -0xcc0(%rbp),%xmm0
ff
mov    $0x190,%esi
call   1050 <stddev@plt>
movsd  %xmm0,-0xcc8(%rbp)
ff
lea    0xdac(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x190,-0x14(%rbp)
jae    136f <main+0x1ef>
lea    -0xcb0(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
mov    $0x190,%esi
call   1030 <count@plt>
movsd  %xmm0,-0xcd0(%rbp)
ff
movsd  -0x20(%rbp),%xmm0
xor    %edi,%edi
mov    $0x1,%esi
call   10a0 <cnormdist@plt>
movsd  %xmm0,-0xcd8(%rbp)
ff
mov    -0x14(%rbp),%eax
movsd  -0xcb0(%rbp,%rax,8),%xmm0
ff ff
movsd  %xmm0,-0xcf8(%rbp)
ff
movsd  -0xcd0(%rbp),%xmm0
ff
movsd  %xmm0,-0xcf0(%rbp)
ff
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0xce8(%rbp)
ff
movsd  -0xcd8(%rbp),%xmm0
ff
movsd  %xmm0,-0xce0(%rbp)
ff
movsd  -0xcd0(%rbp),%xmm0
ff
movsd  -0xcd8(%rbp),%xmm1
ff
call   1060 <doubleAbs@plt>
movsd  -0xcf8(%rbp),%xmm0
ff
movsd  -0xcf0(%rbp),%xmm1
ff
movsd  -0xce8(%rbp),%xmm2
ff
movsd  -0xce0(%rbp),%xmm3
ff
mov    %eax,%esi
lea    0xd37(%rip),%rdi
mov    $0x4,%al
call   1070 <printf@plt>
movsd  -0x30(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1288 <main+0x108>
mov    0x2c6a(%rip),%rax
mov    (%rax),%eax
add    $0xd00,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0xcb0,%rsp
movsd  0xe5c(%rip),%xmm0
call   1050 <abs@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1090 <boxmuller_init@plt>
xorpd  %xmm2,%xmm2
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  %xmm2,0x8(%rsp)
xor    %eax,%eax
call   10a0 <boxmuller@plt>
movsd  0x8(%rsp),%xmm2
movsd  %xmm0,0x30(%rsp,%rbx,8)
addsd  %xmm0,%xmm2
add    $0x1,%rbx
cmp    $0x190,%rbx
jne    11d0 <main+0x40>
movsd  0xe06(%rip),%xmm0
movsd  0x10(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
divsd  %xmm0,%xmm2
lea    0x30(%rsp),%r14
mov    %r14,%rdi
movapd %xmm2,%xmm0
mov    $0x190,%esi
call   1060 <stddev@plt>
lea    0xdfa(%rip),%rdi
call   1040 <puts@plt>
lea    0xe22(%rip),%rdi
call   1040 <puts@plt>
movsd  0xdc4(%rip),%xmm0
xor    %ebx,%ebx
lea    0xdc3(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x190,%esi
call   1030 <count@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
xor    %edi,%edi
mov    $0x1,%esi
call   10b0 <cnormdist@plt>
movaps %xmm0,%xmm1
movsd  %xmm0,0x20(%rsp)
movsd  0x30(%rsp,%rbx,8),%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0x18(%rsp),%xmm0
call   1070 <doubleAbs@plt>
mov    %r15,%rdi
movsd  0x28(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
movsd  0x20(%rsp),%xmm3
mov    %eax,%esi
mov    $0x4,%al
call   1080 <printf@plt>
movsd  0x8(%rsp),%xmm0
addsd  0x10(%rsp),%xmm0
add    $0x1,%rbx
cmp    $0x190,%rbx
jne    1260 <main+0xd0>
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
add    $0xcb0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [53 x i8] c"#Box-Muller Gaussian Random Number Generator (GRNG)\0A\00"
@.str.1 = [53 x i8] c"#GaussianRN\09Norm of GRN\09std value\09StandardNorm\09Diff\0A\00"
@.str.2 = [21 x i8] c"%lf\09%lf\09%lf\09%lf\09%lf\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca [400 x double]
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double -3.000000e+00, double* %7
%16 = load double, double* %7
%17 = fmul double %16, 2.000000e+00
%18 = call i32 @abs(double %17)
store i32 %18, i32* %8
%19 = load i32, i32* %8
%20 = sitofp i32 %19 to double
%21 = fdiv double %20, 4.000000e+02
store double %21, double* %9
store double 0.000000e+00, double* %11
%22 = call i32 (...) @boxmuller_init()
store i32 0, i32* %6
br label %23
23: ; preds = %33, %2
%24 = load i32, i32* %6
%25 = icmp ult i32 %24, 400
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = call double (...) @boxmuller()
%28 = load i32, i32* %6
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds [400 x double], [400 x double]* %10, i64 0, i64 %29
store double %27, double* %30
%31 = load double, double* %11
%32 = fadd double %31, %27
store double %32, double* %11
br label %33
33: ; preds = %26
%34 = load i32, i32* %6
%35 = add i32 %34, 1
store i32 %35, i32* %6
br label %23
36: ; preds = %23
%37 = load double, double* %11
%38 = fdiv double %37, 4.000000e+02
store double %38, double* %12
%39 = getelementptr inbounds [400 x double], [400 x double]* %10, i64 0, i64 0
%40 = load double, double* %12
%41 = call double @stddev(double* %39, double %40, i32 400)
store double %41, double* %13
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %6
br label %44
44: ; preds = %67, %36
%45 = load i32, i32* %6
%46 = icmp ult i32 %45, 400
br i1 %46, label %47, label %70
47: ; preds = %44
%48 = getelementptr inbounds [400 x double], [400 x double]* %10, i64 0, i64 0
%49 = load double, double* %7
%50 = call double @count(double* %48, double %49, i32 400)
store double %50, double* %14
%51 = load double, double* %7
%52 = call double @cnormdist(double %51, i32 0, i32 1)
store double %52, double* %15
%53 = load i32, i32* %6
%54 = zext i32 %53 to i64
%55 = getelementptr inbounds [400 x double], [400 x double]* %10, i64 0, i64 %54
%56 = load double, double* %55
%57 = load double, double* %14
%58 = load double, double* %7
%59 = load double, double* %15
%60 = load double, double* %14
%61 = load double, double* %15
%62 = call i32 @doubleAbs(double %60, double %61)
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), double %56, double %57, double %58, double %59, i32 %62)
%64 = load double, double* %9
%65 = load double, double* %7
%66 = fadd double %65, %64
store double %66, double* %7
br label %67
67: ; preds = %47
%68 = load i32, i32* %6
%69 = add i32 %68, 1
store i32 %69, i32* %6
br label %44
70: ; preds = %44
%71 = load i32, i32* @EXIT_SUCCESS
ret i32 %71
}

LLVM IR (-O2):
@.str.2 = [21 x i8] c"%lf\09%lf\09%lf\09%lf\09%lf\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [52 x i8] c"#Box-Muller Gaussian Random Number Generator (GRNG)\00"
@str.3 = [52 x i8] c"#GaussianRN\09Norm of GRN\09std value\09StandardNorm\09Diff\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [400 x double]
%4 = tail call i32 @abs(double -6.000000e+00)
%5 = sitofp i32 %4 to double
%6 = bitcast [400 x double]* %3 to i8*
%7 = tail call i32 (...) @boxmuller_init()
br label %8
8: ; preds = %2, %8
%9 = phi i64 [ 0, %2 ], [ %14, %8 ]
%10 = phi double [ 0.000000e+00, %2 ], [ %13, %8 ]
%11 = tail call double (...) @boxmuller()
%12 = getelementptr inbounds [400 x double], [400 x double]* %3, i64 0, i64 %9
store double %11, double* %12
%13 = fadd double %10, %11
%14 = add nuw nsw i64 %9, 1
%15 = icmp eq i64 %14, 400
br i1 %15, label %16, label %8
16: ; preds = %8
%17 = fdiv double %5, 4.000000e+02
%18 = fdiv double %13, 4.000000e+02
%19 = getelementptr inbounds [400 x double], [400 x double]* %3, i64 0, i64 0
%20 = call double @stddev(double* %19, double %18, i32 400)
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.3, i64 0, i64 0))
br label %23
23: ; preds = %16, %23
%24 = phi i64 [ 0, %16 ], [ %33, %23 ]
%25 = phi double [ -3.000000e+00, %16 ], [ %32, %23 ]
%26 = call double @count(double* %19, double %25, i32 400)
%27 = call double @cnormdist(double %25, i32 0, i32 1)
%28 = getelementptr inbounds [400 x double], [400 x double]* %3, i64 0, i64 %24
%29 = load double, double* %28
%30 = call i32 @doubleAbs(double %26, double %27)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), double %29, double %26, double %25, double %27, i32 %30)
%32 = fadd double %17, %25
%33 = add nuw nsw i64 %24, 1
%34 = icmp eq i64 %33, 400
br i1 %34, label %35, label %23
35: ; preds = %23
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}