#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 */
struct rand_dist {
  int dummy;
};

/* Variables and functions */
double calc_deviation(double, long, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, double);
int /*<<< orphan*/ linsched_destroy_gaussian(struct rand_dist *);
int linsched_gen_gaussian_dist(struct rand_dist *);
struct rand_dist *linsched_init_gaussian(int, int, unsigned int);
int simple_strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int test_linsched_gaussian(int argc, char **argv) {
  unsigned int seed = (unsigned int)simple_strtoul(argv[2], NULL, 0);
  int mu = simple_strtoul(argv[3], NULL, 0);
  int sd = simple_strtoul(argv[4], NULL, 0);
  int n = simple_strtoul(argv[5], NULL, 0);
  int i, val;
  struct rand_dist *rdist = linsched_init_gaussian(mu, sd, seed);
  long sum = 0, sum_sq = 0;
  double avg;
  for (i = 0; i < n; i++) {
    val = linsched_gen_gaussian_dist(rdist);
    sum += val;
    sum_sq += (val * val);
  }
  avg = sum / (double)n;
  fprintf(stdout, "\n AVG(mu) : %f, DEVIATION(sd) = %f\n", avg,
          calc_deviation(avg, sum_sq, n));
  linsched_destroy_gaussian(rdist);
  return 0;
}


x86 assembly (clang, -O0):
<test_linsched_gaussian>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <simple_strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <simple_strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <simple_strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <simple_strtoul@plt>
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1070 <linsched_init_gaussian@plt>
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1233 <test_linsched_gaussian+0xd3>
mov    -0x30(%rbp),%rdi
call   1050 <linsched_gen_gaussian_dist@plt>
mov    %eax,-0x28(%rbp)
movslq -0x28(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%eax
imul   -0x28(%rbp),%eax
cltq
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11f0 <test_linsched_gaussian+0x90>
cvtsi2sdq -0x38(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1080 <calc_deviation@plt>
mov    -0x54(%rbp),%edi
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
lea    0xd80(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1030 <linsched_destroy_gaussian@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_linsched_gaussian>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    0x10(%rsi),%rdi
xor    %r15d,%r15d
xor    %esi,%esi
xor    %edx,%edx
call   1060 <simple_strtoul@plt>
mov    %eax,%r14d
mov    0x18(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <simple_strtoul@plt>
mov    %eax,%ebx
mov    0x20(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <simple_strtoul@plt>
mov    %eax,%r12d
mov    0x28(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <simple_strtoul@plt>
mov    %eax,%r13d
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r14d,%edx
call   1070 <linsched_init_gaussian@plt>
mov    %rax,%r14
test   %r13d,%r13d
jle    11ef <test_linsched_gaussian+0x8f>
xor    %r15d,%r15d
mov    %r13d,%ebp
xor    %ebx,%ebx
nopl   (%rax)
mov    %r14,%rdi
call   1050 <linsched_gen_gaussian_dist@plt>
cltq
add    %rax,%rbx
imul   %eax,%eax
add    %rax,%r15
add    $0xffffffff,%ebp
jne    11d0 <test_linsched_gaussian+0x70>
cvtsi2sd %rbx,%xmm0
jmp    11f3 <test_linsched_gaussian+0x93>
xorpd  %xmm0,%xmm0
cvtsi2sd %r13d,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%ebp
mov    %r15,%rdi
mov    %r13d,%esi
call   1080 <calc_deviation@plt>
movapd %xmm0,%xmm1
lea    0xde0(%rip),%rsi
mov    %ebp,%edi
movsd  (%rsp),%xmm0
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1030 <linsched_destroy_gaussian@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.rand_dist = type { i32 }
@stdout = global i32 0
@.str = [36 x i8] c"\0A AVG(mu) : %f, DEVIATION(sd) = %f\0A\00"
define i32 @test_linsched_gaussian(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.rand_dist*
%12 = alloca i64
%13 = alloca i64
%14 = alloca double
store i32 %0, i32* %3
store i8** %1, i8*** %4
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32 @simple_strtoul(i8* %17, i32* null, i32 0)
store i32 %18, i32* %5
%19 = load i8**, i8*** %4
%20 = getelementptr inbounds i8*, i8** %19, i64 3
%21 = load i8*, i8** %20
%22 = call i32 @simple_strtoul(i8* %21, i32* null, i32 0)
store i32 %22, i32* %6
%23 = load i8**, i8*** %4
%24 = getelementptr inbounds i8*, i8** %23, i64 4
%25 = load i8*, i8** %24
%26 = call i32 @simple_strtoul(i8* %25, i32* null, i32 0)
store i32 %26, i32* %7
%27 = load i8**, i8*** %4
%28 = getelementptr inbounds i8*, i8** %27, i64 5
%29 = load i8*, i8** %28
%30 = call i32 @simple_strtoul(i8* %29, i32* null, i32 0)
store i32 %30, i32* %8
%31 = load i32, i32* %6
%32 = load i32, i32* %7
%33 = load i32, i32* %5
%34 = call %struct.rand_dist* @linsched_init_gaussian(i32 %31, i32 %32, i32 %33)
store %struct.rand_dist* %34, %struct.rand_dist** %11
store i64 0, i64* %12
store i64 0, i64* %13
store i32 0, i32* %9
br label %35
35: ; preds = %52, %2
%36 = load i32, i32* %9
%37 = load i32, i32* %8
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %55
39: ; preds = %35
%40 = load %struct.rand_dist*, %struct.rand_dist** %11
%41 = call i32 @linsched_gen_gaussian_dist(%struct.rand_dist* %40)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = sext i32 %42 to i64
%44 = load i64, i64* %12
%45 = add nsw i64 %44, %43
store i64 %45, i64* %12
%46 = load i32, i32* %10
%47 = load i32, i32* %10
%48 = mul nsw i32 %46, %47
%49 = sext i32 %48 to i64
%50 = load i64, i64* %13
%51 = add nsw i64 %50, %49
store i64 %51, i64* %13
br label %52
52: ; preds = %39
%53 = load i32, i32* %9
%54 = add nsw i32 %53, 1
store i32 %54, i32* %9
br label %35
55: ; preds = %35
%56 = load i64, i64* %12
%57 = sitofp i64 %56 to double
%58 = load i32, i32* %8
%59 = sitofp i32 %58 to double
%60 = fdiv double %57, %59
store double %60, double* %14
%61 = load i32, i32* @stdout
%62 = load double, double* %14
%63 = load double, double* %14
%64 = load i64, i64* %13
%65 = load i32, i32* %8
%66 = call double @calc_deviation(double %63, i64 %64, i32 %65)
%67 = call i32 @fprintf(i32 %61, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %62, double %66)
%68 = load %struct.rand_dist*, %struct.rand_dist** %11
%69 = call i32 @linsched_destroy_gaussian(%struct.rand_dist* %68)
ret i32 0
}

LLVM IR (-O2):
%struct.rand_dist = type { i32 }
@stdout = global i32 0
@.str = [36 x i8] c"\0A AVG(mu) : %f, DEVIATION(sd) = %f\0A\00"
define i32 @test_linsched_gaussian(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 2
%4 = load i8*, i8** %3
%5 = tail call i32 @simple_strtoul(i8* %4, i32* null, i32 0)
%6 = getelementptr inbounds i8*, i8** %1, i64 3
%7 = load i8*, i8** %6
%8 = tail call i32 @simple_strtoul(i8* %7, i32* null, i32 0)
%9 = getelementptr inbounds i8*, i8** %1, i64 4
%10 = load i8*, i8** %9
%11 = tail call i32 @simple_strtoul(i8* %10, i32* null, i32 0)
%12 = getelementptr inbounds i8*, i8** %1, i64 5
%13 = load i8*, i8** %12
%14 = tail call i32 @simple_strtoul(i8* %13, i32* null, i32 0)
%15 = tail call %struct.rand_dist* @linsched_init_gaussian(i32 %8, i32 %11, i32 %5)
%16 = icmp sgt i32 %14, 0
br i1 %16, label %17, label %31
17: ; preds = %2, %17
%18 = phi i32 [ %27, %17 ], [ 0, %2 ]
%19 = phi i64 [ %26, %17 ], [ 0, %2 ]
%20 = phi i64 [ %23, %17 ], [ 0, %2 ]
%21 = tail call i32 @linsched_gen_gaussian_dist(%struct.rand_dist* %15)
%22 = sext i32 %21 to i64
%23 = add nsw i64 %20, %22
%24 = mul nsw i32 %21, %21
%25 = zext i32 %24 to i64
%26 = add nuw nsw i64 %19, %25
%27 = add nuw nsw i32 %18, 1
%28 = icmp eq i32 %27, %14
br i1 %28, label %29, label %17
29: ; preds = %17
%30 = sitofp i64 %23 to double
br label %31
31: ; preds = %29, %2
%32 = phi double [ 0.000000e+00, %2 ], [ %30, %29 ]
%33 = phi i64 [ 0, %2 ], [ %26, %29 ]
%34 = sitofp i32 %14 to double
%35 = fdiv double %32, %34
%36 = load i32, i32* @stdout
%37 = tail call double @calc_deviation(double %35, i64 %33, i32 %14)
%38 = tail call i32 @fprintf(i32 %36, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %35, double %37)
%39 = tail call i32 @linsched_destroy_gaussian(%struct.rand_dist* %15)
ret i32 0
}