#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*/ printf(char *);
int stdlib_base_prng_min(struct BasePRNGObject *);
struct BasePRNGObject *stdlib_base_random_randi_allocate(int /*<<< orphan*/);
int /*<<< orphan*/ stdlib_base_random_randi_free(struct BasePRNGObject *);
double tic();
double benchmark1() {
  double elapsed;
  double t;
  int i;
  struct BasePRNGObject *obj;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    obj = stdlib_base_random_randi_allocate(0);
    if (obj == NULL || stdlib_base_prng_min(obj) != 1) {
      printf("unexpected result\n");
      break;
    }
    if (i < 1000000 - 1) {
      stdlib_base_random_randi_free(obj);
    }
  }
  elapsed = tic() - t;
  if (obj == NULL || stdlib_base_prng_min(obj) != 1) {
    printf("unexpected result\n");
  }
  stdlib_base_random_randi_free(obj);
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <tic@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0xf4240,-0x14(%rbp)
jge    11da <benchmark1+0x8a>
xor    %edi,%edi
call   1070 <stdlib_base_random_randi_allocate@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a0 <benchmark1+0x50>
mov    -0x20(%rbp),%rdi
call   1060 <stdlib_base_prng_min@plt>
cmp    $0x1,%eax
je     11b1 <benchmark1+0x61>
lea    0xe59(%rip),%rdi
call   1040 <printf@plt>
jmp    11da <benchmark1+0x8a>
cmpl   $0xf423f,-0x14(%rbp)
jge    11c7 <benchmark1+0x77>
mov    -0x20(%rbp),%rdi
call   1030 <stdlib_base_random_randi_free@plt>
jmp    11cc <benchmark1+0x7c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116b <benchmark1+0x1b>
mov    $0x0,%al
call   1050 <tic@plt>
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1208 <benchmark1+0xb8>
mov    -0x20(%rbp),%rdi
call   1060 <stdlib_base_prng_min@plt>
cmp    $0x1,%eax
je     1214 <benchmark1+0xc4>
lea    0xdf1(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <stdlib_base_random_randi_free@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark1>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,0x10(%rsp)
jmp    117b <benchmark1+0x2b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0xf4240,%ebp
je     11cb <benchmark1+0x7b>
xor    %edi,%edi
call   1070 <stdlib_base_random_randi_allocate@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11a9 <benchmark1+0x59>
mov    %rbx,%rdi
call   1060 <stdlib_base_prng_min@plt>
cmp    $0x1,%eax
jne    11a9 <benchmark1+0x59>
cmp    $0xf423e,%ebp
ja     1170 <benchmark1+0x20>
mov    %rbx,%rdi
call   1040 <stdlib_base_random_randi_free@plt>
jmp    1170 <benchmark1+0x20>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,0x8(%rsp)
test   %rbx,%rbx
jne    11d8 <benchmark1+0x88>
xor    %ebx,%ebx
jmp    11e5 <benchmark1+0x95>
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1060 <stdlib_base_prng_min@plt>
cmp    $0x1,%eax
je     11f1 <benchmark1+0xa1>
lea    0xe14(%rip),%rdi
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %rbx,%rdi
call   1040 <stdlib_base_random_randi_free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.BasePRNGObject = type { i32 }
@.str = [19 x i8] c"unexpected result\0A\00"
define double @benchmark1() {
%1 = alloca double
%2 = alloca double
%3 = alloca i32
%4 = alloca %struct.BasePRNGObject*
%5 = call double (...) @tic()
store double %5, double* %2
store i32 0, i32* %3
br label %6
6: ; preds = %26, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 1000000
br i1 %8, label %9, label %29
9: ; preds = %6
%10 = call %struct.BasePRNGObject* @stdlib_base_random_randi_allocate(i32 0)
store %struct.BasePRNGObject* %10, %struct.BasePRNGObject** %4
%11 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %4
%12 = icmp eq %struct.BasePRNGObject* %11, null
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %4
%15 = call i32 @stdlib_base_prng_min(%struct.BasePRNGObject* %14)
%16 = icmp ne i32 %15, 1
br i1 %16, label %17, label %19
17: ; preds = %13, %9
%18 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %29
19: ; preds = %13
%20 = load i32, i32* %3
%21 = icmp slt i32 %20, 999999
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %4
%24 = call i32 @stdlib_base_random_randi_free(%struct.BasePRNGObject* %23)
br label %25
25: ; preds = %22, %19
br label %26
26: ; preds = %25
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %6
29: ; preds = %17, %6
%30 = call double (...) @tic()
%31 = load double, double* %2
%32 = fsub double %30, %31
store double %32, double* %1
%33 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %4
%34 = icmp eq %struct.BasePRNGObject* %33, null
br i1 %34, label %39, label %35
35: ; preds = %29
%36 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %4
%37 = call i32 @stdlib_base_prng_min(%struct.BasePRNGObject* %36)
%38 = icmp ne i32 %37, 1
br i1 %38, label %39, label %41
39: ; preds = %35, %29
%40 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %41
41: ; preds = %39, %35
%42 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %4
%43 = call i32 @stdlib_base_random_randi_free(%struct.BasePRNGObject* %42)
%44 = load double, double* %1
ret double %44
}

LLVM IR (-O2):
%struct.BasePRNGObject = type { i32 }
@str.1 = [18 x i8] c"unexpected result\00"
define double @benchmark1() {
%1 = tail call double (...) @tic()
br label %2
2: ; preds = %0, %13
%3 = phi i32 [ 0, %0 ], [ %14, %13 ]
%4 = tail call %struct.BasePRNGObject* @stdlib_base_random_randi_allocate(i32 0)
%5 = icmp eq %struct.BasePRNGObject* %4, null
br i1 %5, label %18, label %6
6: ; preds = %2
%7 = tail call i32 @stdlib_base_prng_min(%struct.BasePRNGObject* %4)
%8 = icmp eq i32 %7, 1
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = icmp ult i32 %3, 999999
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @stdlib_base_random_randi_free(%struct.BasePRNGObject* %4)
br label %13
13: ; preds = %9, %11
%14 = add nuw nsw i32 %3, 1
%15 = icmp eq i32 %14, 1000000
br i1 %15, label %16, label %2
16: ; preds = %13
%17 = tail call double (...) @tic()
br label %22
18: ; preds = %2, %6
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
%20 = tail call double (...) @tic()
%21 = icmp eq %struct.BasePRNGObject* %4, null
br i1 %21, label %26, label %22
22: ; preds = %16, %18
%23 = phi double [ %17, %16 ], [ %20, %18 ]
%24 = tail call i32 @stdlib_base_prng_min(%struct.BasePRNGObject* %4)
%25 = icmp eq i32 %24, 1
br i1 %25, label %30, label %26
26: ; preds = %22, %18
%27 = phi double [ %23, %22 ], [ %20, %18 ]
%28 = phi %struct.BasePRNGObject* [ %4, %22 ], [ null, %18 ]
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
br label %30
30: ; preds = %26, %22
%31 = phi double [ %27, %26 ], [ %23, %22 ]
%32 = phi %struct.BasePRNGObject* [ %28, %26 ], [ %4, %22 ]
%33 = fsub double %31, %1
%34 = tail call i32 @stdlib_base_random_randi_free(%struct.BasePRNGObject* %32)
ret double %33
}