#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 CLOCKS_PER_SEC;
double clock();
int /*<<< orphan*/ nn_rng_init(int);
scalar_t__ nn_rng_uniform_double(double);
int /*<<< orphan*/ printf(char *, double, ...);
int test_doubles(void) {
  nn_rng_init(3);
  int i, j;
  double total, t;
  double ranges[3] = {1.0, 2.0, 2.71828};
  for (j = 0; j < 3; j++) {
    double top = ranges[j];
    printf("trying %d iterations, (0 to %f)", 100000000, top);
    total = 0;
    t = clock();
    for (i = 0; i < 100000000; i++) {
      total += nn_rng_uniform_double(top);
    }
    printf("... took %f seconds\n", (clock() - t) / CLOCKS_PER_SEC);
    printf("average is: %f\n", total / 100000000);
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_doubles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    $0x3,%edi
call   1060 <nn_rng_init@plt>
mov    0xeb7(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xeb4(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0xeb1(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    124f <test_doubles+0x10f>
movslq -0x8(%rbp),%rax
movsd  -0x30(%rbp,%rax,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
lea    0xe89(%rip),%rdi
movsd  0xe59(%rip),%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x5f5e100,-0x4(%rbp)
jge    11fd <test_doubles+0xbd>
movsd  -0x38(%rbp),%xmm0
call   1030 <nn_rng_uniform_double@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c9 <test_doubles+0x89>
mov    $0x0,%al
call   1040 <clock@plt>
subsd  -0x18(%rbp),%xmm0
mov    0x2dd8(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe2d(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  -0x10(%rbp),%xmm0
movsd  0xdd1(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe23(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117a <test_doubles+0x3a>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_doubles>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    $0x3,%edi
call   1060 <nn_rng_init@plt>
lea    0xec9(%rip),%rdi
movsd  0xea1(%rip),%xmm0
movsd  0xea1(%rip),%xmm1
mov    $0x2,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x5f5e100,%ebx
nopw   0x0(%rax,%rax,1)
movsd  0xe70(%rip),%xmm0
call   1030 <nn_rng_uniform_double@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0xffffffff,%ebx
jne    1190 <test_doubles+0x50>
xor    %eax,%eax
call   1040 <clock@plt>
subsd  0x10(%rsp),%xmm0
mov    0x2e1a(%rip),%rbx
divsd  (%rbx),%xmm0
lea    0xe67(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0xe18(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
lea    0xe5c(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xe19(%rip),%rdi
movsd  0xe01(%rip),%xmm1
movsd  0xde9(%rip),%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x5f5e100,%ebp
nopw   0x0(%rax,%rax,1)
movsd  0xdc8(%rip),%xmm0
call   1030 <nn_rng_uniform_double@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0xffffffff,%ebp
jne    1240 <test_doubles+0x100>
xor    %eax,%eax
call   1040 <clock@plt>
subsd  0x10(%rsp),%xmm0
divsd  (%rbx),%xmm0
lea    0xdbe(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0xd6f(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
divsd  %xmm1,%xmm0
lea    0xdb3(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
lea    0xd70(%rip),%rdi
movsd  0xd60(%rip),%xmm1
movsd  0xd40(%rip),%xmm0
mov    $0x2,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    $0x5f5e100,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsd  0xd20(%rip),%xmm0
call   1030 <nn_rng_uniform_double@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
add    $0xffffffff,%ebp
jne    12f0 <test_doubles+0x1b0>
xor    %eax,%eax
call   1040 <clock@plt>
subsd  0x10(%rsp),%xmm0
divsd  (%rbx),%xmm0
lea    0xd0e(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
movsd  0x8(%rsp),%xmm0
divsd  0xcb9(%rip),%xmm0
lea    0xd07(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@__const.test_doubles.ranges = [3 x double] [double 1.000000e+00, double 2.000000e+00, double 2.718280e+00]
@.str = [32 x i8] c"trying %d iterations, (0 to %f)\00"
@.str.1 = [21 x i8] c"... took %f seconds\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [16 x i8] c"average is: %f\0A\00"
define i32 @test_doubles() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca double
%4 = alloca double
%5 = alloca [3 x double]
%6 = alloca double
%7 = call i32 @nn_rng_init(i32 3)
%8 = bitcast [3 x double]* %5 to i8*
store i32 0, i32* %2
br label %9
9: ; preds = %42, %0
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 3
br i1 %11, label %12, label %45
12: ; preds = %9
%13 = load i32, i32* %2
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 %14
%16 = load double, double* %15
store double %16, double* %6
%17 = load double, double* %6
%18 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 1.000000e+08, double %17)
store double 0.000000e+00, double* %3
%19 = call double (...) @clock()
store double %19, double* %4
store i32 0, i32* %1
br label %20
20: ; preds = %29, %12
%21 = load i32, i32* %1
%22 = icmp slt i32 %21, 100000000
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load double, double* %6
%25 = call i64 @nn_rng_uniform_double(double %24)
%26 = sitofp i64 %25 to double
%27 = load double, double* %3
%28 = fadd double %27, %26
store double %28, double* %3
br label %29
29: ; preds = %23
%30 = load i32, i32* %1
%31 = add nsw i32 %30, 1
store i32 %31, i32* %1
br label %20
32: ; preds = %20
%33 = call double (...) @clock()
%34 = load double, double* %4
%35 = fsub double %33, %34
%36 = load double, double* @CLOCKS_PER_SEC
%37 = fdiv double %35, %36
%38 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %37)
%39 = load double, double* %3
%40 = fdiv double %39, 1.000000e+08
%41 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %40)
br label %42
42: ; preds = %32
%43 = load i32, i32* %2
%44 = add nsw i32 %43, 1
store i32 %44, i32* %2
br label %9
45: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"trying %d iterations, (0 to %f)\00"
@.str.1 = [21 x i8] c"... took %f seconds\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.2 = [16 x i8] c"average is: %f\0A\00"
define i32 @test_doubles() {
%1 = tail call i32 @nn_rng_init(i32 3)
%2 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 1.000000e+08, double 1.000000e+00)
%3 = tail call double (...) @clock()
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 0, %0 ], [ %10, %4 ]
%6 = phi double [ 0.000000e+00, %0 ], [ %9, %4 ]
%7 = tail call i64 @nn_rng_uniform_double(double 1.000000e+00)
%8 = sitofp i64 %7 to double
%9 = fadd double %6, %8
%10 = add nuw nsw i32 %5, 1
%11 = icmp eq i32 %10, 100000000
br i1 %11, label %12, label %4
12: ; preds = %4
%13 = tail call double (...) @clock()
%14 = fsub double %13, %3
%15 = load double, double* @CLOCKS_PER_SEC
%16 = fdiv double %14, %15
%17 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %16)
%18 = fdiv double %9, 1.000000e+08
%19 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %18)
%20 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 1.000000e+08, double 2.000000e+00)
%21 = tail call double (...) @clock()
br label %22
22: ; preds = %22, %12
%23 = phi i32 [ 0, %12 ], [ %28, %22 ]
%24 = phi double [ 0.000000e+00, %12 ], [ %27, %22 ]
%25 = tail call i64 @nn_rng_uniform_double(double 2.000000e+00)
%26 = sitofp i64 %25 to double
%27 = fadd double %24, %26
%28 = add nuw nsw i32 %23, 1
%29 = icmp eq i32 %28, 100000000
br i1 %29, label %30, label %22
30: ; preds = %22
%31 = tail call double (...) @clock()
%32 = fsub double %31, %21
%33 = load double, double* @CLOCKS_PER_SEC
%34 = fdiv double %32, %33
%35 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %34)
%36 = fdiv double %27, 1.000000e+08
%37 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %36)
%38 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 1.000000e+08, double 2.718280e+00)
%39 = tail call double (...) @clock()
br label %40
40: ; preds = %40, %30
%41 = phi i32 [ 0, %30 ], [ %46, %40 ]
%42 = phi double [ 0.000000e+00, %30 ], [ %45, %40 ]
%43 = tail call i64 @nn_rng_uniform_double(double 2.718280e+00)
%44 = sitofp i64 %43 to double
%45 = fadd double %42, %44
%46 = add nuw nsw i32 %41, 1
%47 = icmp eq i32 %46, 100000000
br i1 %47, label %48, label %40
48: ; preds = %40
%49 = tail call double (...) @clock()
%50 = fsub double %49, %39
%51 = load double, double* @CLOCKS_PER_SEC
%52 = fdiv double %50, %51
%53 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %52)
%54 = fdiv double %45, 1.000000e+08
%55 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %54)
ret i32 0
}