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


x86 assembly (clang, -O0):
<test_ints>:
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)
jae    124f <test_ints+0x10f>
mov    -0x8(%rbp),%eax
cvttsd2si -0x30(%rbp,%rax,8),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xe8e(%rip),%rdi
movsd  0xe5e(%rip),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
movl   $0x0,-0xc(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x4(%rbp)
cmpl   $0x5f5e100,-0x4(%rbp)
jae    11f2 <test_ints+0xb2>
mov    -0x34(%rbp),%edi
call   1050 <nn_rng_uniform_int@plt>
mov    %rax,%rcx
mov    -0xc(%rbp),%eax
add    %rcx,%rax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11c3 <test_ints+0x83>
xor    %eax,%eax
call   1030 <clock@plt>
movsd  -0x18(%rbp),%xmm1
subsd  %xmm1,%xmm0
mov    0x2ddf(%rip),%rax
movsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
lea    0xe30(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
cvtsi2sd %rax,%xmm0
movsd  0xdd1(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe23(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    117a <test_ints+0x3a>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_ints>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    $0x3,%edi
call   1060 <nn_rng_init@plt>
lea    0xeaf(%rip),%rdi
movsd  0xe9f(%rip),%xmm0
mov    $0x1,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x5f5e100,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1050 <nn_rng_uniform_int@plt>
add    %eax,%ebx
add    $0xffffffff,%ebp
jne    1190 <test_ints+0x50>
xor    %ebp,%ebp
xor    %eax,%eax
call   1030 <clock@plt>
subsd  0x8(%rsp),%xmm0
mov    0x2e31(%rip),%r14
divsd  (%r14),%xmm0
lea    0xe65(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0xe24(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe56(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe13(%rip),%rdi
movsd  0xe03(%rip),%xmm0
mov    $0x2,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x5f5e100,%ebx
nopl   0x0(%rax,%rax,1)
mov    $0x2,%edi
call   1050 <nn_rng_uniform_int@plt>
add    %eax,%ebp
add    $0xffffffff,%ebx
jne    1220 <test_ints+0xe0>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clock@plt>
subsd  0x8(%rsp),%xmm0
divsd  (%r14),%xmm0
lea    0xddc(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %ebp,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0xd9b(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xdcd(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xd8a(%rip),%rdi
movsd  0xd7a(%rip),%xmm0
mov    $0x3,%esi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0x5f5e100,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    $0x3,%edi
call   1050 <nn_rng_uniform_int@plt>
add    %eax,%ebx
add    $0xffffffff,%ebp
jne    12b0 <test_ints+0x170>
xor    %eax,%eax
call   1030 <clock@plt>
subsd  0x8(%rsp),%xmm0
divsd  (%r14),%xmm0
lea    0xd4e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0xd0d(%rip),%xmm0
lea    0xd43(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@__const.test_ints.ranges = [3 x double] [double 1.000000e+00, double 2.000000e+00, double 3.000000e+00]
@.str = [32 x i8] c"trying %d iterations, (0 to %d)\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_ints() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca [3 x double]
%6 = alloca i32
%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 = %45, %0
%10 = load i32, i32* %2
%11 = icmp ult i32 %10, 3
br i1 %11, label %12, label %48
12: ; preds = %9
%13 = load i32, i32* %2
%14 = zext i32 %13 to i64
%15 = getelementptr inbounds [3 x double], [3 x double]* %5, i64 0, i64 %14
%16 = load double, double* %15
%17 = fptosi double %16 to i32
store i32 %17, i32* %6
%18 = load i32, i32* %6
%19 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 1.000000e+08, i32 %18)
store i32 0, i32* %3
%20 = call double (...) @clock()
store double %20, double* %4
store i32 0, i32* %1
br label %21
21: ; preds = %31, %12
%22 = load i32, i32* %1
%23 = icmp ult i32 %22, 100000000
br i1 %23, label %24, label %34
24: ; preds = %21
%25 = load i32, i32* %6
%26 = call i64 @nn_rng_uniform_int(i32 %25)
%27 = load i32, i32* %3
%28 = zext i32 %27 to i64
%29 = add nsw i64 %28, %26
%30 = trunc i64 %29 to i32
store i32 %30, i32* %3
br label %31
31: ; preds = %24
%32 = load i32, i32* %1
%33 = add i32 %32, 1
store i32 %33, i32* %1
br label %21
34: ; preds = %21
%35 = call double (...) @clock()
%36 = load double, double* %4
%37 = fsub double %35, %36
%38 = load double, double* @CLOCKS_PER_SEC
%39 = fdiv double %37, %38
%40 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %39)
%41 = load i32, i32* %3
%42 = uitofp i32 %41 to double
%43 = fdiv double %42, 1.000000e+08
%44 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %43)
br label %45
45: ; preds = %34
%46 = load i32, i32* %2
%47 = add i32 %46, 1
store i32 %47, i32* %2
br label %9
48: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"trying %d iterations, (0 to %d)\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_ints() {
%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, i32 1)
%3 = tail call double (...) @clock()
br label %4
4: ; preds = %0, %4
%5 = phi i32 [ 0, %0 ], [ %10, %4 ]
%6 = phi i32 [ 0, %0 ], [ %9, %4 ]
%7 = tail call i64 @nn_rng_uniform_int(i32 1)
%8 = trunc i64 %7 to i32
%9 = add i32 %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 = uitofp i32 %9 to double
%19 = fdiv double %18, 1.000000e+08
%20 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %19)
%21 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 1.000000e+08, i32 2)
%22 = tail call double (...) @clock()
br label %23
23: ; preds = %23, %12
%24 = phi i32 [ 0, %12 ], [ %29, %23 ]
%25 = phi i32 [ 0, %12 ], [ %28, %23 ]
%26 = tail call i64 @nn_rng_uniform_int(i32 2)
%27 = trunc i64 %26 to i32
%28 = add i32 %25, %27
%29 = add nuw nsw i32 %24, 1
%30 = icmp eq i32 %29, 100000000
br i1 %30, label %31, label %23
31: ; preds = %23
%32 = tail call double (...) @clock()
%33 = fsub double %32, %22
%34 = load double, double* @CLOCKS_PER_SEC
%35 = fdiv double %33, %34
%36 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %35)
%37 = uitofp i32 %28 to double
%38 = fdiv double %37, 1.000000e+08
%39 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %38)
%40 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 1.000000e+08, i32 3)
%41 = tail call double (...) @clock()
br label %42
42: ; preds = %42, %31
%43 = phi i32 [ 0, %31 ], [ %48, %42 ]
%44 = phi i32 [ 0, %31 ], [ %47, %42 ]
%45 = tail call i64 @nn_rng_uniform_int(i32 3)
%46 = trunc i64 %45 to i32
%47 = add i32 %44, %46
%48 = add nuw nsw i32 %43, 1
%49 = icmp eq i32 %48, 100000000
br i1 %49, label %50, label %42
50: ; preds = %42
%51 = tail call double (...) @clock()
%52 = fsub double %51, %41
%53 = load double, double* @CLOCKS_PER_SEC
%54 = fdiv double %52, %53
%55 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), double %54)
%56 = uitofp i32 %47 to double
%57 = fdiv double %56, 1.000000e+08
%58 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), double %57)
ret i32 0
}