#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 BasePRNGObject {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
struct BasePRNGObject *stdlib_base_random_randu_allocate(int /*<<< orphan*/);
int /*<<< orphan*/ stdlib_base_random_randu_free(struct BasePRNGObject *);
double stdlib_base_random_uniform(struct BasePRNGObject *, double, double);
double tic();
double benchmark() {
  double elapsed;
  double v;
  double t;
  int i;
  struct BasePRNGObject *randu = stdlib_base_random_randu_allocate(0);
  if (randu == NULL) {
    printf("unable to allocate memory\n");
    exit(1);
  }
  t = tic();
  for (i = 0; i < 1000000; i++) {
    v = stdlib_base_random_uniform(randu, -10.0, 10.0);
    if (v != v) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (v != v) {
    printf("unexpected result\n");
  }
  stdlib_base_random_randu_free(randu);
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
xor    %edi,%edi
call   1060 <stdlib_base_random_randu_allocate@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1194 <benchmark+0x34>
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    1211 <benchmark+0xb1>
mov    -0x28(%rbp),%rdi
movsd  0xe40(%rip),%xmm0
movsd  0xe40(%rip),%xmm1
call   1050 <stdlib_base_random_uniform@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    11ed <benchmark+0x8d>
jp     11ed <benchmark+0x8d>
jmp    11fe <benchmark+0x9e>
lea    0xe37(%rip),%rdi
call   1030 <printf@plt>
jmp    1211 <benchmark+0xb1>
jmp    1203 <benchmark+0xa3>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a7 <benchmark+0x47>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    123d <benchmark+0xdd>
jp     123d <benchmark+0xdd>
jmp    1249 <benchmark+0xe9>
lea    0xde7(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <stdlib_base_random_randu_free@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1060 <stdlib_base_random_randu_allocate@plt>
test   %rax,%rax
je     120a <benchmark+0xaa>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xf4240,%ebp
nopl   (%rax)
mov    %rbx,%rdi
movsd  0xe65(%rip),%xmm0
movsd  0xe65(%rip),%xmm1
call   1050 <stdlib_base_random_uniform@plt>
ucomisd %xmm0,%xmm0
jp     11c1 <benchmark+0x61>
add    $0xffffffff,%ebp
jne    1190 <benchmark+0x30>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,(%rsp)
jmp    11e4 <benchmark+0x84>
lea    0xe48(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
call   1030 <puts@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1080 <stdlib_base_random_randu_free@plt>
movsd  (%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe11(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.BasePRNGObject = type { i32 }
@.str = [27 x i8] c"unable to allocate memory\0A\00"
@.str.1 = [19 x i8] c"unexpected result\0A\00"
define double @benchmark() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca %struct.BasePRNGObject*
%6 = call %struct.BasePRNGObject* @stdlib_base_random_randu_allocate(i32 0)
store %struct.BasePRNGObject* %6, %struct.BasePRNGObject** %5
%7 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %5
%8 = icmp eq %struct.BasePRNGObject* %7, null
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = call double (...) @tic()
store double %13, double* %3
store i32 0, i32* %4
br label %14
14: ; preds = %26, %12
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 1000000
br i1 %16, label %17, label %29
17: ; preds = %14
%18 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %5
%19 = call double @stdlib_base_random_uniform(%struct.BasePRNGObject* %18, double -1.000000e+01, double 1.000000e+01)
store double %19, double* %2
%20 = load double, double* %2
%21 = load double, double* %2
%22 = fcmp une double %20, %21
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %29
25: ; preds = %17
br label %26
26: ; preds = %25
%27 = load i32, i32* %4
%28 = add nsw i32 %27, 1
store i32 %28, i32* %4
br label %14
29: ; preds = %23, %14
%30 = call double (...) @tic()
%31 = load double, double* %3
%32 = fsub double %30, %31
store double %32, double* %1
%33 = load double, double* %2
%34 = load double, double* %2
%35 = fcmp une double %33, %34
br i1 %35, label %36, label %38
36: ; preds = %29
%37 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %38
38: ; preds = %36, %29
%39 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %5
%40 = call i32 @stdlib_base_random_randu_free(%struct.BasePRNGObject* %39)
%41 = load double, double* %1
ret double %41
}

LLVM IR (-O2):
%struct.BasePRNGObject = type { i32 }
@str.2 = [18 x i8] c"unexpected result\00"
@str.3 = [26 x i8] c"unable to allocate memory\00"
define double @benchmark() {
%1 = tail call %struct.BasePRNGObject* @stdlib_base_random_randu_allocate(i32 0)
%2 = icmp eq %struct.BasePRNGObject* %1, null
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.3, i64 0, i64 0))
%5 = tail call i32 @exit(i32 1)
unreachable
6: ; preds = %0
%7 = tail call double (...) @tic()
br label %11
8: ; preds = %11
%9 = add nuw nsw i32 %12, 1
%10 = icmp eq i32 %9, 1000000
br i1 %10, label %15, label %11
11: ; preds = %6, %8
%12 = phi i32 [ 0, %6 ], [ %9, %8 ]
%13 = tail call double @stdlib_base_random_uniform(%struct.BasePRNGObject* %1, double -1.000000e+01, double 1.000000e+01)
%14 = fcmp uno double %13, 0.000000e+00
br i1 %14, label %17, label %8
15: ; preds = %8
%16 = tail call double (...) @tic()
br label %21
17: ; preds = %11
%18 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
%19 = tail call double (...) @tic()
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
br label %21
21: ; preds = %15, %17
%22 = phi double [ %19, %17 ], [ %16, %15 ]
%23 = fsub double %22, %7
%24 = tail call i32 @stdlib_base_random_randu_free(%struct.BasePRNGObject* %1)
ret double %23
}