#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_poisson(struct rand_dist *);
int linsched_gen_poisson_dist(struct rand_dist *);
struct rand_dist *linsched_init_poisson(int, unsigned int);
int simple_strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int test_linsched_poisson(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);
  int i, val;
  struct rand_dist *rdist = linsched_init_poisson(mu, seed);
  long sum = 0, sum_sq = 0;
  double avg;
  for (i = 0; i < n; i++) {
    val = linsched_gen_poisson_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_poisson(rdist);
  return 0;
}


x86 assembly (clang, -O0):
<test_linsched_poisson>:
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    -0x18(%rbp),%edi
mov    -0x14(%rbp),%esi
call   1030 <linsched_init_poisson@plt>
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    121a <test_linsched_poisson+0xba>
mov    -0x30(%rbp),%rdi
call   1070 <linsched_gen_poisson_dist@plt>
mov    %eax,-0x24(%rbp)
movslq -0x24(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x24(%rbp),%eax
imul   -0x24(%rbp),%eax
cltq
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11d7 <test_linsched_poisson+0x77>
cvtsi2sdq -0x38(%rbp),%xmm0
cvtsi2sdl -0x1c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    0x2dab(%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    -0x1c(%rbp),%esi
call   1080 <calc_deviation@plt>
mov    -0x54(%rbp),%edi
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
lea    0xd99(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <linsched_destroy_poisson@plt>
xor    %eax,%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_linsched_poisson>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    0x10(%rsi),%rdi
xor    %r13d,%r13d
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,%r15d
mov    0x20(%rbp),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <simple_strtoul@plt>
mov    %eax,%r12d
mov    %r15d,%edi
mov    %r14d,%esi
call   1030 <linsched_init_poisson@plt>
mov    %rax,%r14
test   %r12d,%r12d
jle    11df <test_linsched_poisson+0x7f>
xor    %r13d,%r13d
mov    %r12d,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %r14,%rdi
call   1070 <linsched_gen_poisson_dist@plt>
cltq
add    %rax,%rbx
imul   %eax,%eax
add    %rax,%r13
add    $0xffffffff,%ebp
jne    11c0 <test_linsched_poisson+0x60>
cvtsi2sd %rbx,%xmm0
jmp    11e3 <test_linsched_poisson+0x83>
xorpd  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
mov    0x2de8(%rip),%rax
mov    (%rax),%ebp
mov    %r13,%rdi
mov    %r12d,%esi
call   1080 <calc_deviation@plt>
movapd %xmm0,%xmm1
lea    0xdf0(%rip),%rsi
mov    %ebp,%edi
movsd  (%rsp),%xmm0
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1050 <linsched_destroy_poisson@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_poisson(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 %struct.rand_dist*
%11 = alloca i64
%12 = alloca i64
%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_poisson(i32 %26, i32 %27)
store %struct.rand_dist* %28, %struct.rand_dist** %10
store i64 0, i64* %11
store i64 0, i64* %12
store i32 0, i32* %8
br label %29
29: ; preds = %46, %2
%30 = load i32, i32* %8
%31 = load i32, i32* %7
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %49
33: ; preds = %29
%34 = load %struct.rand_dist*, %struct.rand_dist** %10
%35 = call i32 @linsched_gen_poisson_dist(%struct.rand_dist* %34)
store i32 %35, i32* %9
%36 = load i32, i32* %9
%37 = sext i32 %36 to i64
%38 = load i64, i64* %11
%39 = add nsw i64 %38, %37
store i64 %39, i64* %11
%40 = load i32, i32* %9
%41 = load i32, i32* %9
%42 = mul nsw i32 %40, %41
%43 = sext i32 %42 to i64
%44 = load i64, i64* %12
%45 = add nsw i64 %44, %43
store i64 %45, i64* %12
br label %46
46: ; preds = %33
%47 = load i32, i32* %8
%48 = add nsw i32 %47, 1
store i32 %48, i32* %8
br label %29
49: ; preds = %29
%50 = load i64, i64* %11
%51 = sitofp i64 %50 to double
%52 = load i32, i32* %7
%53 = sitofp i32 %52 to double
%54 = fdiv double %51, %53
store double %54, double* %13
%55 = load i32, i32* @stdout
%56 = load double, double* %13
%57 = load double, double* %13
%58 = load i64, i64* %12
%59 = load i32, i32* %7
%60 = call double @calc_deviation(double %57, i64 %58, i32 %59)
%61 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %56, double %60)
%62 = load %struct.rand_dist*, %struct.rand_dist** %10
%63 = call i32 @linsched_destroy_poisson(%struct.rand_dist* %62)
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_poisson(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_poisson(i32 %8, i32 %5)
%13 = icmp sgt i32 %11, 0
br i1 %13, label %14, label %28
14: ; preds = %2, %14
%15 = phi i32 [ %24, %14 ], [ 0, %2 ]
%16 = phi i64 [ %23, %14 ], [ 0, %2 ]
%17 = phi i64 [ %20, %14 ], [ 0, %2 ]
%18 = tail call i32 @linsched_gen_poisson_dist(%struct.rand_dist* %12)
%19 = sext i32 %18 to i64
%20 = add nsw i64 %17, %19
%21 = mul nsw i32 %18, %18
%22 = zext i32 %21 to i64
%23 = add nuw nsw i64 %16, %22
%24 = add nuw nsw i32 %15, 1
%25 = icmp eq i32 %24, %11
br i1 %25, label %26, label %14
26: ; preds = %14
%27 = sitofp i64 %20 to double
br label %28
28: ; preds = %26, %2
%29 = phi double [ 0.000000e+00, %2 ], [ %27, %26 ]
%30 = phi i64 [ 0, %2 ], [ %23, %26 ]
%31 = sitofp i32 %11 to double
%32 = fdiv double %29, %31
%33 = load i32, i32* @stdout
%34 = tail call double @calc_deviation(double %32, i64 %30, i32 %11)
%35 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), double %32, double %34)
%36 = tail call i32 @linsched_destroy_poisson(%struct.rand_dist* %12)
ret i32 0
}