#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(unsigned int *);
unsigned int *linsched_init_rand(unsigned int);
double linsched_rand_range(unsigned long, unsigned long, unsigned int *);
void *simple_strtoul(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int test_linsched_rand_range(int argc, char **argv) {
  unsigned int seed = (unsigned int)simple_strtoul(argv[2], NULL, 0);
  unsigned long low = simple_strtoul(argv[3], NULL, 0);
  unsigned long high = simple_strtoul(argv[4], NULL, 0);
  int n = simple_strtoul(argv[5], NULL, 0);
  unsigned int *state = linsched_init_rand(seed);
  int i;
  double sum = 0, sum_sq = 0, avg, val;
  for (i = 0; i < n; i++) {
    val = linsched_rand_range(low, high, state);
    sum += val;
    sum_sq += (val * val);
    fprintf(stdout, "val = %f\n", val);
  }
  avg = sum / (double)n;
  fprintf(stdout, "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_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%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    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <linsched_init_rand@plt>
mov    %rax,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1263 <test_linsched_rand_range+0x103>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1060 <linsched_rand_range@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  -0x60(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
movsd  -0x60(%rbp),%xmm0
lea    0xdb2(%rip),%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11ec <test_linsched_rand_range+0x8c>
movsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x2c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x58(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm1
mov    -0x2c(%rbp),%edi
call   1080 <calc_deviation@plt>
mov    -0x6c(%rbp),%edi
movaps %xmm0,%xmm1
movsd  -0x68(%rbp),%xmm0
lea    0xd5a(%rip),%rsi
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    -0x38(%rbp),%rdi
call   1040 <linsched_destroy_rand@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_linsched_rand_range>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    0x10(%rsi),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %rax,%r15
mov    0x18(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %rax,%r12
mov    0x20(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %rax,%rbx
mov    0x28(%r14),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <simple_strtoul@plt>
mov    %rax,%r14
mov    %r15d,%edi
call   1030 <linsched_init_rand@plt>
mov    %rax,%r15
test   %r14d,%r14d
mov    %r14,0x10(%rsp)
xorpd  %xmm0,%xmm0
jle    1239 <test_linsched_rand_range+0xd9>
movsd  %xmm0,(%rsp)
mov    0x2e0a(%rip),%rbp
lea    0xe23(%rip),%r13
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1060 <linsched_rand_range@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    0x0(%rbp),%edi
mov    %r13,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    $0xffffffff,%r14d
jne    11f0 <test_linsched_rand_range+0x90>
jmp    1248 <test_linsched_rand_range+0xe8>
movsd  %xmm0,0x8(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
mov    0x10(%rsp),%rdi
xorps  %xmm1,%xmm1
cvtsi2sd %edi,%xmm1
movsd  (%rsp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
mov    0x2d77(%rip),%rax
mov    (%rax),%ebx
movsd  0x8(%rsp),%xmm1
call   1080 <calc_deviation@plt>
movapd %xmm0,%xmm1
lea    0xd89(%rip),%rsi
mov    %ebx,%edi
movsd  (%rsp),%xmm0
mov    $0x2,%al
call   1050 <fprintf@plt>
mov    %r15,%rdi
call   1040 <linsched_destroy_rand@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
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 = [34 x i8] c"AVG(mu) : %f, DEVIATION(sd) = %f\0A\00"
define i32 @test_linsched_rand_range(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca double
%12 = alloca double
%13 = alloca double
%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 i8* @simple_strtoul(i8* %17, i32* null, i32 0)
%19 = ptrtoint i8* %18 to i32
store i32 %19, i32* %5
%20 = load i8**, i8*** %4
%21 = getelementptr inbounds i8*, i8** %20, i64 3
%22 = load i8*, i8** %21
%23 = call i8* @simple_strtoul(i8* %22, i32* null, i32 0)
%24 = ptrtoint i8* %23 to i64
store i64 %24, i64* %6
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 4
%27 = load i8*, i8** %26
%28 = call i8* @simple_strtoul(i8* %27, i32* null, i32 0)
%29 = ptrtoint i8* %28 to i64
store i64 %29, i64* %7
%30 = load i8**, i8*** %4
%31 = getelementptr inbounds i8*, i8** %30, i64 5
%32 = load i8*, i8** %31
%33 = call i8* @simple_strtoul(i8* %32, i32* null, i32 0)
%34 = ptrtoint i8* %33 to i32
store i32 %34, i32* %8
%35 = load i32, i32* %5
%36 = call i32* @linsched_init_rand(i32 %35)
store i32* %36, i32** %9
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
store i32 0, i32* %10
br label %37
37: ; preds = %56, %2
%38 = load i32, i32* %10
%39 = load i32, i32* %8
%40 = icmp slt i32 %38, %39
br i1 %40, label %41, label %59
41: ; preds = %37
%42 = load i64, i64* %6
%43 = load i64, i64* %7
%44 = load i32*, i32** %9
%45 = call double @linsched_rand_range(i64 %42, i64 %43, i32* %44)
store double %45, double* %14
%46 = load double, double* %14
%47 = load double, double* %11
%48 = fadd double %47, %46
store double %48, double* %11
%49 = load double, double* %14
%50 = load double, double* %14
%51 = load double, double* %12
%52 = call double @llvm.fmuladd.f64(double %49, double %50, double %51)
store double %52, double* %12
%53 = load i32, i32* @stdout
%54 = load double, double* %14
%55 = call i32 (i32, i8*, double, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), double %54)
br label %56
56: ; preds = %41
%57 = load i32, i32* %10
%58 = add nsw i32 %57, 1
store i32 %58, i32* %10
br label %37
59: ; preds = %37
%60 = load double, double* %11
%61 = load i32, i32* %8
%62 = sitofp i32 %61 to double
%63 = fdiv double %60, %62
store double %63, double* %13
%64 = load i32, i32* @stdout
%65 = load double, double* %13
%66 = load double, double* %13
%67 = load double, double* %12
%68 = load i32, i32* %8
%69 = call double @calc_deviation(double %66, double %67, i32 %68)
%70 = call i32 (i32, i8*, double, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), double %65, double %69)
%71 = load i32*, i32** %9
%72 = call i32 @linsched_destroy_rand(i32* %71)
ret i32 0
}

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