#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_exponential(struct rand_dist *);
double linsched_gen_exp_dist(struct rand_dist *);
struct rand_dist *linsched_init_exponential(int, unsigned int);
int simple_strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int test_linsched_exponential(int argc, char **argv) {
  unsigned int seed = (unsigned int)simple_strtoul(argv[2], NULL, 0);
  int mu = simple_strtoul(argv[3], NULL, 0);
  int n = simple_strtoul(argv[4], NULL, 0);
  struct rand_dist *rdist = linsched_init_exponential(mu, seed);
  long sum = 0, sum_sq = 0;
  int i;
  double avg, val;
  for (i = 0; i < n; i++) {
    val = linsched_gen_exp_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_exponential(rdist);
  return 0;
}


x86 assembly (clang, -O0):
<test_linsched_exponential>:
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    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <linsched_init_exponential@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1238 <test_linsched_exponential+0xd8>
mov    -0x28(%rbp),%rdi
call   1050 <linsched_gen_exp_dist@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm1
cvtsi2sdq -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x30(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
cvtsi2sdq -0x38(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11d7 <test_linsched_exponential+0x77>
cvtsi2sdq -0x30(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x48(%rbp),%xmm0
mov    -0x38(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1080 <calc_deviation@plt>
mov    -0x5c(%rbp),%edi
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
lea    0xd7b(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1060 <linsched_destroy_exponential@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_linsched_exponential>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbp
mov    0x10(%rsi),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %eax,%r14d
mov    0x18(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %eax,%r15d
mov    0x20(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %eax,%r12d
mov    %r15d,%edi
mov    %r14d,%esi
call   1030 <linsched_init_exponential@plt>
mov    %rax,%r14
xorpd  %xmm0,%xmm0
test   %r12d,%r12d
jle    11ff <test_linsched_exponential+0x9f>
xor    %ebx,%ebx
mov    %r12d,%ebp
nopl   (%rax)
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
call   1050 <linsched_gen_exp_dist@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rbx,%xmm1
mulsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
add    $0xffffffff,%ebp
jne    11c0 <test_linsched_exponential+0x60>
xorps  %xmm1,%xmm1
cvtsi2sd %r12d,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x2dc8(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
mov    %r12d,%esi
call   1080 <calc_deviation@plt>
movapd %xmm0,%xmm1
lea    0xdd0(%rip),%rsi
mov    %ebp,%edi
movsd  0x8(%rsp),%xmm0
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1060 <linsched_destroy_exponential@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
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_exponential(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.rand_dist*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca double
%13 = alloca double
store i32 %0, i32* %3
store i8** %1, i8*** %4
%14 = load i8**, i8*** %4
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
%17 = call i32 @simple_strtoul(i8* %16, i32* null, i32 0)
store i32 %17, i32* %5
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 3
%20 = load i8*, i8** %19
%21 = call i32 @simple_strtoul(i8* %20, i32* null, i32 0)
store i32 %21, i32* %6
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 4
%24 = load i8*, i8** %23
%25 = call i32 @simple_strtoul(i8* %24, i32* null, i32 0)
store i32 %25, i32* %7
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = call %struct.rand_dist* @linsched_init_exponential(i32 %26, i32 %27)
store %struct.rand_dist* %28, %struct.rand_dist** %8
store i64 0, i64* %9
store i64 0, i64* %10
store i32 0, i32* %11
br label %29
29: ; preds = %47, %2
%30 = load i32, i32* %11
%31 = load i32, i32* %7
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %50
33: ; preds = %29
%34 = load %struct.rand_dist*, %struct.rand_dist** %8
%35 = call double @linsched_gen_exp_dist(%struct.rand_dist* %34)
store double %35, double* %13
%36 = load double, double* %13
%37 = load i64, i64* %9
%38 = sitofp i64 %37 to double
%39 = fadd double %38, %36
%40 = fptosi double %39 to i64
store i64 %40, i64* %9
%41 = load double, double* %13
%42 = load double, double* %13
%43 = load i64, i64* %10
%44 = sitofp i64 %43 to double
%45 = call double @llvm.fmuladd.f64(double %41, double %42, double %44)
%46 = fptosi double %45 to i64
store i64 %46, i64* %10
br label %47
47: ; preds = %33
%48 = load i32, i32* %11
%49 = add nsw i32 %48, 1
store i32 %49, i32* %11
br label %29
50: ; preds = %29
%51 = load i64, i64* %9
%52 = sitofp i64 %51 to double
%53 = load i32, i32* %7
%54 = sitofp i32 %53 to double
%55 = fdiv double %52, %54
store double %55, double* %12
%56 = load i32, i32* @stdout
%57 = load double, double* %12
%58 = load double, double* %12
%59 = load i64, i64* %10
%60 = load i32, i32* %7
%61 = call double @calc_deviation(double %58, i64 %59, i32 %60)
%62 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %57, double %61)
%63 = load %struct.rand_dist*, %struct.rand_dist** %8
%64 = call i32 @linsched_destroy_exponential(%struct.rand_dist* %63)
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_exponential(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 = tail call %struct.rand_dist* @linsched_init_exponential(i32 %8, i32 %5)
%13 = icmp sgt i32 %11, 0
br i1 %13, label %14, label %27
14: ; preds = %2, %14
%15 = phi double [ %25, %14 ], [ 0.000000e+00, %2 ]
%16 = phi i64 [ %23, %14 ], [ 0, %2 ]
%17 = phi i32 [ %24, %14 ], [ 0, %2 ]
%18 = tail call double @linsched_gen_exp_dist(%struct.rand_dist* %12)
%19 = fadd double %15, %18
%20 = fptosi double %19 to i64
%21 = sitofp i64 %16 to double
%22 = tail call double @llvm.fmuladd.f64(double %18, double %18, double %21)
%23 = fptosi double %22 to i64
%24 = add nuw nsw i32 %17, 1
%25 = sitofp i64 %20 to double
%26 = icmp eq i32 %24, %11
br i1 %26, label %27, label %14
27: ; preds = %14, %2
%28 = phi i64 [ 0, %2 ], [ %23, %14 ]
%29 = phi double [ 0.000000e+00, %2 ], [ %25, %14 ]
%30 = sitofp i32 %11 to double
%31 = fdiv double %29, %30
%32 = load i32, i32* @stdout
%33 = tail call double @calc_deviation(double %31, i64 %28, i32 %11)
%34 = tail call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %31, double %33)
%35 = tail call i32 @linsched_destroy_exponential(%struct.rand_dist* %12)
ret i32 0
}