#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, double, int);
int exp(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, double, double);
int /*<<< orphan*/ linsched_destroy_lognormal(struct rand_dist *);
double linsched_gen_lognormal_dist(struct rand_dist *);
struct rand_dist *linsched_init_lognormal(int, int, unsigned int);
double pow(int, int);
int simple_strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
double sqrt(int);
int /*<<< orphan*/ stdout;
int test_linsched_lognormal(int argc, char **argv) {
  unsigned int seed = (unsigned int)simple_strtoul(argv[2], NULL, 0);
  int meanlog = simple_strtoul(argv[3], NULL, 0);
  int sdlog = simple_strtoul(argv[4], NULL, 0);
  int n = simple_strtoul(argv[5], NULL, 0);
  int i;
  double sdlog_sq = pow(sdlog, 2);
  double exp_mean = exp(meanlog + 0.5 * sdlog_sq);
  double exp_sd = sqrt((exp(sdlog_sq) - 1) * (exp(2 * meanlog + sdlog_sq)));
  struct rand_dist *rdist = linsched_init_lognormal(meanlog, sdlog, seed);
  double avg, val, sum = 0, sum_sq = 0;
  for (i = 0; i < n; i++) {
    val = linsched_gen_lognormal_dist(rdist);
    sum += val;
    sum_sq += (val * val);
  }
  avg = sum / (double)n;
  fprintf(stdout, "\nAVG(mu): %f, DEVIATION(sd) = %f\n", avg,
          calc_deviation(avg, sum_sq, n));
  fprintf(stdout, "E.AVG:   %f, Exp. DEV      = %f\n", exp_mean, exp_sd);
  linsched_destroy_lognormal(rdist);
  return 0;
}


x86 assembly (clang, -O0):
<test_linsched_lognormal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%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   1080 <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   1080 <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   1080 <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   1080 <simple_strtoul@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    $0x2,%esi
call   1070 <pow@plt>
movsd  %xmm0,-0x30(%rbp)
cvtsi2sdl -0x18(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  0xde2(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1050 <exp@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
cvttsd2si -0x30(%rbp),%edi
call   1050 <exp@plt>
sub    $0x1,%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <exp@plt>
mov    -0x6c(%rbp),%edi
imul   %eax,%edi
call   1090 <sqrt@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
mov    -0x14(%rbp),%edx
call   10a0 <linsched_init_lognormal@plt>
mov    %rax,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    12ec <test_linsched_lognormal+0x15c>
mov    -0x48(%rbp),%rdi
call   1030 <linsched_gen_lognormal_dist@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movsd  -0x68(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1299 <test_linsched_lognormal+0x109>
movsd  -0x60(%rbp),%xmm0
cvtsi2sdl -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    0x2cda(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm1
mov    -0x20(%rbp),%edi
call   10b0 <calc_deviation@plt>
mov    -0x7c(%rbp),%edi
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
lea    0xccf(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2c9b(%rip),%rax
mov    (%rax),%edi
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
lea    0xcd2(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1060 <linsched_destroy_lognormal@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_linsched_lognormal>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <simple_strtoul@plt>
mov    %eax,%r15d
mov    0x18(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <simple_strtoul@plt>
mov    %eax,%ebp
mov    0x20(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <simple_strtoul@plt>
mov    %eax,%r13d
mov    0x28(%rbx),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1080 <simple_strtoul@plt>
mov    %eax,%r12d
mov    %r13d,%edi
mov    $0x2,%esi
call   1070 <pow@plt>
movsd  %xmm0,(%rsp)
cvtsi2sd %ebp,%xmm2
movsd  0xe02(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
cvttsd2si %xmm1,%edi
call   1050 <exp@plt>
mov    %eax,%r14d
cvttsd2si (%rsp),%edi
call   1050 <exp@plt>
lea    0x0(%rbp,%rbp,1),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
lea    -0x1(%rax),%ebx
addsd  (%rsp),%xmm0
cvttsd2si %xmm0,%edi
call   1050 <exp@plt>
imul   %eax,%ebx
mov    %ebx,%edi
call   1090 <sqrt@plt>
movsd  %xmm0,0x10(%rsp)
mov    %ebp,%edi
mov    %r13d,%esi
mov    %r15d,%edx
call   10a0 <linsched_init_lognormal@plt>
mov    %rax,%rbp
test   %r12d,%r12d
jle    12a1 <test_linsched_lognormal+0x111>
xorpd  %xmm1,%xmm1
mov    %r12d,%ebx
xorpd  %xmm2,%xmm2
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm2,(%rsp)
mov    %rbp,%rdi
call   1030 <linsched_gen_lognormal_dist@plt>
movsd  0x8(%rsp),%xmm1
movsd  (%rsp),%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm0,%xmm0
addsd  %xmm0,%xmm1
add    $0xffffffff,%ebx
jne    1270 <test_linsched_lognormal+0xe0>
jmp    12a9 <test_linsched_lognormal+0x119>
xorpd  %xmm2,%xmm2
xorpd  %xmm1,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r12d,%xmm0
divsd  %xmm0,%xmm2
movsd  %xmm2,(%rsp)
mov    0x2d11(%rip),%r14
mov    (%r14),%ebx
movapd %xmm2,%xmm0
mov    %r12d,%edi
call   10b0 <calc_deviation@plt>
movapd %xmm0,%xmm1
lea    0xd1f(%rip),%rsi
mov    %ebx,%edi
movsd  (%rsp),%xmm0
call   1040 <fprintf@plt>
mov    (%r14),%edi
lea    0xd2b(%rip),%rsi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
call   1040 <fprintf@plt>
mov    %rbp,%rdi
call   1060 <linsched_destroy_lognormal@plt>
xor    %eax,%eax
add    $0x18,%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 = [34 x i8] c"\0AAVG(mu): %f, DEVIATION(sd) = %f\0A\00"
@.str.1 = [33 x i8] c"E.AVG: %f, Exp. DEV = %f\0A\00"
define i32 @test_linsched_lognormal(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 double
%11 = alloca double
%12 = alloca double
%13 = alloca %struct.rand_dist*
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
store i32 %0, i32* %3
store i8** %1, i8*** %4
%18 = load i8**, i8*** %4
%19 = getelementptr inbounds i8*, i8** %18, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @simple_strtoul(i8* %20, i32* null, i32 0)
store i32 %21, i32* %5
%22 = load i8**, i8*** %4
%23 = getelementptr inbounds i8*, i8** %22, i64 3
%24 = load i8*, i8** %23
%25 = call i32 @simple_strtoul(i8* %24, i32* null, i32 0)
store i32 %25, i32* %6
%26 = load i8**, i8*** %4
%27 = getelementptr inbounds i8*, i8** %26, i64 4
%28 = load i8*, i8** %27
%29 = call i32 @simple_strtoul(i8* %28, i32* null, i32 0)
store i32 %29, i32* %7
%30 = load i8**, i8*** %4
%31 = getelementptr inbounds i8*, i8** %30, i64 5
%32 = load i8*, i8** %31
%33 = call i32 @simple_strtoul(i8* %32, i32* null, i32 0)
store i32 %33, i32* %8
%34 = load i32, i32* %7
%35 = call double @pow(i32 %34, i32 2)
store double %35, double* %10
%36 = load i32, i32* %6
%37 = sitofp i32 %36 to double
%38 = load double, double* %10
%39 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %38, double %37)
%40 = fptosi double %39 to i32
%41 = call i32 @exp(i32 %40)
%42 = sitofp i32 %41 to double
store double %42, double* %11
%43 = load double, double* %10
%44 = fptosi double %43 to i32
%45 = call i32 @exp(i32 %44)
%46 = sub nsw i32 %45, 1
%47 = load i32, i32* %6
%48 = mul nsw i32 2, %47
%49 = sitofp i32 %48 to double
%50 = load double, double* %10
%51 = fadd double %49, %50
%52 = fptosi double %51 to i32
%53 = call i32 @exp(i32 %52)
%54 = mul nsw i32 %46, %53
%55 = call double @sqrt(i32 %54)
store double %55, double* %12
%56 = load i32, i32* %6
%57 = load i32, i32* %7
%58 = load i32, i32* %5
%59 = call %struct.rand_dist* @linsched_init_lognormal(i32 %56, i32 %57, i32 %58)
store %struct.rand_dist* %59, %struct.rand_dist** %13
store double 0.000000e+00, double* %16
store double 0.000000e+00, double* %17
store i32 0, i32* %9
br label %60
60: ; preds = %74, %2
%61 = load i32, i32* %9
%62 = load i32, i32* %8
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %77
64: ; preds = %60
%65 = load %struct.rand_dist*, %struct.rand_dist** %13
%66 = call double @linsched_gen_lognormal_dist(%struct.rand_dist* %65)
store double %66, double* %15
%67 = load double, double* %15
%68 = load double, double* %16
%69 = fadd double %68, %67
store double %69, double* %16
%70 = load double, double* %15
%71 = load double, double* %15
%72 = load double, double* %17
%73 = call double @llvm.fmuladd.f64(double %70, double %71, double %72)
store double %73, double* %17
br label %74
74: ; preds = %64
%75 = load i32, i32* %9
%76 = add nsw i32 %75, 1
store i32 %76, i32* %9
br label %60
77: ; preds = %60
%78 = load double, double* %16
%79 = load i32, i32* %8
%80 = sitofp i32 %79 to double
%81 = fdiv double %78, %80
store double %81, double* %14
%82 = load i32, i32* @stdout
%83 = load double, double* %14
%84 = load double, double* %14
%85 = load double, double* %17
%86 = load i32, i32* %8
%87 = call double @calc_deviation(double %84, double %85, i32 %86)
%88 = call i32 @fprintf(i32 %82, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), double %83, double %87)
%89 = load i32, i32* @stdout
%90 = load double, double* %11
%91 = load double, double* %12
%92 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), double %90, double %91)
%93 = load %struct.rand_dist*, %struct.rand_dist** %13
%94 = call i32 @linsched_destroy_lognormal(%struct.rand_dist* %93)
ret i32 0
}

LLVM IR (-O2):
%struct.rand_dist = type { i32 }
@stdout = global i32 0
@.str = [34 x i8] c"\0AAVG(mu): %f, DEVIATION(sd) = %f\0A\00"
@.str.1 = [33 x i8] c"E.AVG: %f, Exp. DEV = %f\0A\00"
define i32 @test_linsched_lognormal(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 double @pow(i32 %11, i32 2)
%16 = sitofp i32 %8 to double
%17 = tail call double @llvm.fmuladd.f64(double %15, double 5.000000e-01, double %16)
%18 = fptosi double %17 to i32
%19 = tail call i32 @exp(i32 %18)
%20 = fptosi double %15 to i32
%21 = tail call i32 @exp(i32 %20)
%22 = add nsw i32 %21, -1
%23 = shl nsw i32 %8, 1
%24 = sitofp i32 %23 to double
%25 = fadd double %15, %24
%26 = fptosi double %25 to i32
%27 = tail call i32 @exp(i32 %26)
%28 = mul nsw i32 %22, %27
%29 = tail call double @sqrt(i32 %28)
%30 = tail call %struct.rand_dist* @linsched_init_lognormal(i32 %8, i32 %11, i32 %5)
%31 = icmp sgt i32 %14, 0
br i1 %31, label %32, label %41
32: ; preds = %2, %32
%33 = phi double [ %38, %32 ], [ 0.000000e+00, %2 ]
%34 = phi double [ %37, %32 ], [ 0.000000e+00, %2 ]
%35 = phi i32 [ %39, %32 ], [ 0, %2 ]
%36 = tail call double @linsched_gen_lognormal_dist(%struct.rand_dist* %30)
%37 = fadd double %34, %36
%38 = tail call double @llvm.fmuladd.f64(double %36, double %36, double %33)
%39 = add nuw nsw i32 %35, 1
%40 = icmp eq i32 %39, %14
br i1 %40, label %41, label %32
41: ; preds = %32, %2
%42 = phi double [ 0.000000e+00, %2 ], [ %37, %32 ]
%43 = phi double [ 0.000000e+00, %2 ], [ %38, %32 ]
%44 = sitofp i32 %19 to double
%45 = sitofp i32 %14 to double
%46 = fdiv double %42, %45
%47 = load i32, i32* @stdout
%48 = tail call double @calc_deviation(double %46, double %43, i32 %14)
%49 = tail call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), double %46, double %48)
%50 = load i32, i32* @stdout
%51 = tail call i32 @fprintf(i32 %50, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), double %44, double %29)
%52 = tail call i32 @linsched_destroy_lognormal(%struct.rand_dist* %30)
ret i32 0
}