#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 calc_deviation(double, double, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, ...);
int /*<<< orphan*/ linsched_destroy_rand(int *);
int *linsched_init_rand(unsigned int);
double linsched_rand(int *);
int simple_strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int test_linsched_rand(int argc, char **argv) {
  unsigned int seed = (unsigned int)simple_strtoul(argv[2], NULL, 0);
  int n = simple_strtoul(argv[3], NULL, 0);
  int *state = linsched_init_rand(seed);
  int i;
  double sum = 0, sum_sq = 0;
  double val, avg;
  for (i = 0; i < n; i++) {
    val = linsched_rand(state);
    sum += val;
    sum_sq += (val * val);
    fprintf(stdout, "val = %f\n", val);
  }
  avg = sum / (double)n;
  fprintf(stdout, "\n AVG(mu) : %f, DEVIATION(sd) = %f\n", avg,
          calc_deviation(avg, sum_sq, n));
  linsched_destroy_rand(state);
  return 0;
}


x86 assembly (clang, -O0):
<test_linsched_rand>:
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   1070 <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   1070 <simple_strtoul@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <linsched_init_rand@plt>
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    122d <test_linsched_rand+0xcd>
mov    -0x20(%rbp),%rdi
call   1060 <linsched_rand@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
movsd  -0x40(%rbp),%xmm0
lea    0xde8(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11be <test_linsched_rand+0x5e>
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x18(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mov    -0x18(%rbp),%edi
call   1080 <calc_deviation@plt>
mov    -0x54(%rbp),%edi
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
lea    0xd90(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <linsched_destroy_rand@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_linsched_rand>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %eax,%ebp
mov    0x18(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %eax,%r14d
mov    %ebp,%edi
call   1030 <linsched_init_rand@plt>
mov    %rax,%rbx
xorpd  %xmm0,%xmm0
test   %r14d,%r14d
jle    1212 <test_linsched_rand+0xb2>
movsd  %xmm0,(%rsp)
mov    0x2e33(%rip),%r15
lea    0xe4c(%rip),%r12
mov    %r14d,%ebp
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <linsched_rand@plt>
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  0x8(%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
mov    (%r15),%edi
mov    %r12,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0xffffffff,%ebp
jne    11d0 <test_linsched_rand+0x70>
jmp    1221 <test_linsched_rand+0xc1>
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sd %r14d,%xmm1
movsd  (%rsp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
mov    0x2da2(%rip),%rax
mov    (%rax),%ebp
movsd  0x8(%rsp),%xmm1
mov    %r14d,%edi
call   1080 <calc_deviation@plt>
movapd %xmm0,%xmm1
lea    0xdb1(%rip),%rsi
mov    %ebp,%edi
movsd  (%rsp),%xmm0
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <linsched_destroy_rand@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [10 x i8] c"val = %f\0A\00"
@.str.1 = [36 x i8] c"\0A AVG(mu) : %f, DEVIATION(sd) = %f\0A\00"
define i32 @test_linsched_rand(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
%12 = alloca double
store i32 %0, i32* %3
store i8** %1, i8*** %4
%13 = load i8**, i8*** %4
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @simple_strtoul(i8* %15, i32* null, i32 0)
store i32 %16, i32* %5
%17 = load i8**, i8*** %4
%18 = getelementptr inbounds i8*, i8** %17, i64 3
%19 = load i8*, i8** %18
%20 = call i32 @simple_strtoul(i8* %19, i32* null, i32 0)
store i32 %20, i32* %6
%21 = load i32, i32* %5
%22 = call i32* @linsched_init_rand(i32 %21)
store i32* %22, i32** %7
store double 0.000000e+00, double* %9
store double 0.000000e+00, double* %10
store i32 0, i32* %8
br label %23
23: ; preds = %40, %2
%24 = load i32, i32* %8
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %43
27: ; preds = %23
%28 = load i32*, i32** %7
%29 = call double @linsched_rand(i32* %28)
store double %29, double* %11
%30 = load double, double* %11
%31 = load double, double* %9
%32 = fadd double %31, %30
store double %32, double* %9
%33 = load double, double* %11
%34 = load double, double* %11
%35 = load double, double* %10
%36 = call double @llvm.fmuladd.f64(double %33, double %34, double %35)
store double %36, double* %10
%37 = load i32, i32* @stdout
%38 = load double, double* %11
%39 = call i32 (i32, i8*, double, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %38)
br label %40
40: ; preds = %27
%41 = load i32, i32* %8
%42 = add nsw i32 %41, 1
store i32 %42, i32* %8
br label %23
43: ; preds = %23
%44 = load double, double* %9
%45 = load i32, i32* %6
%46 = sitofp i32 %45 to double
%47 = fdiv double %44, %46
store double %47, double* %12
%48 = load i32, i32* @stdout
%49 = load double, double* %12
%50 = load double, double* %12
%51 = load double, double* %10
%52 = load i32, i32* %6
%53 = call double @calc_deviation(double %50, double %51, i32 %52)
%54 = call i32 (i32, i8*, double, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), double %49, double %53)
%55 = load i32*, i32** %7
%56 = call i32 @linsched_destroy_rand(i32* %55)
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [10 x i8] c"val = %f\0A\00"
@.str.1 = [36 x i8] c"\0A AVG(mu) : %f, DEVIATION(sd) = %f\0A\00"
define i32 @test_linsched_rand(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 = tail call i32* @linsched_init_rand(i32 %5)
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %22
11: ; preds = %2, %11
%12 = phi i32 [ %20, %11 ], [ 0, %2 ]
%13 = phi double [ %16, %11 ], [ 0.000000e+00, %2 ]
%14 = phi double [ %17, %11 ], [ 0.000000e+00, %2 ]
%15 = tail call double @linsched_rand(i32* %9)
%16 = fadd double %13, %15
%17 = tail call double @llvm.fmuladd.f64(double %15, double %15, double %14)
%18 = load i32, i32* @stdout
%19 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %15)
%20 = add nuw nsw i32 %12, 1
%21 = icmp eq i32 %20, %8
br i1 %21, label %22, label %11
22: ; preds = %11, %2
%23 = phi double [ 0.000000e+00, %2 ], [ %17, %11 ]
%24 = phi double [ 0.000000e+00, %2 ], [ %16, %11 ]
%25 = sitofp i32 %8 to double
%26 = fdiv double %24, %25
%27 = load i32, i32* @stdout
%28 = tail call double @calc_deviation(double %26, double %23, i32 %8)
%29 = tail call i32 (i32, i8*, double, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), double %26, double %28)
%30 = tail call i32 @linsched_destroy_rand(i32* %9)
ret i32 0
}