#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*/ free(void *);
int /*<<< orphan*/ printf(char *);
struct BasePRNGObject *stdlib_base_random_minstd_allocate(int);
int /*<<< orphan*/ stdlib_base_random_minstd_free(struct BasePRNGObject *);
void *stdlib_base_random_minstd_state(struct BasePRNGObject *);
double tic();
double benchmark5() {
  double elapsed;
  void *state;
  double t;
  int i;
  struct BasePRNGObject *obj = stdlib_base_random_minstd_allocate(12345);
  if (obj == NULL) {
    printf("unable to allocate memory\n");
    exit(1);
  }
  t = tic();
  for (i = 0; i < 1000000; i++) {
    state = stdlib_base_random_minstd_state(obj);
    if (state == NULL) {
      printf("unexpected result\n");
      break;
    }
    if (i < 1000000 - 1) {
      free(state);
    }
  }
  elapsed = tic() - t;
  if (state == NULL) {
    printf("unexpected result\n");
  }
  stdlib_base_random_minstd_free(obj);
  free(state);
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark5>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x3039,%edi
call   1040 <stdlib_base_random_minstd_allocate@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11a7 <benchmark5+0x37>
lea    0xe68(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1060 <tic@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    1219 <benchmark5+0xa9>
mov    -0x28(%rbp),%rdi
call   1070 <stdlib_base_random_minstd_state@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f0 <benchmark5+0x80>
lea    0xe35(%rip),%rdi
call   1050 <printf@plt>
jmp    1219 <benchmark5+0xa9>
cmpl   $0xf423f,-0x1c(%rbp)
jge    1206 <benchmark5+0x96>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    120b <benchmark5+0x9b>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ba <benchmark5+0x4a>
mov    $0x0,%al
call   1060 <tic@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1241 <benchmark5+0xd1>
lea    0xddf(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <stdlib_base_random_minstd_free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark5>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x3039,%edi
call   1040 <stdlib_base_random_minstd_allocate@plt>
test   %rax,%rax
je     1243 <benchmark5+0xd3>
mov    %rax,%r14
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <tic@plt>
movsd  %xmm0,0x10(%rsp)
jmp    11bb <benchmark5+0x4b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0xf4240,%ebp
je     1203 <benchmark5+0x93>
mov    %r14,%rdi
call   1070 <stdlib_base_random_minstd_state@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11dd <benchmark5+0x6d>
cmp    $0xf423e,%ebp
ja     11b0 <benchmark5+0x40>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    11b0 <benchmark5+0x40>
lea    0xe1c(%rip),%r15
mov    %r15,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1060 <tic@plt>
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
call   1050 <puts@plt>
jmp    1210 <benchmark5+0xa0>
xor    %eax,%eax
call   1060 <tic@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
call   1080 <stdlib_base_random_minstd_free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc8(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1090 <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 @benchmark5() {
%1 = alloca double
%2 = alloca i8*
%3 = alloca double
%4 = alloca i32
%5 = alloca %struct.BasePRNGObject*
%6 = call %struct.BasePRNGObject* @stdlib_base_random_minstd_allocate(i32 12345)
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 = %31, %12
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 1000000
br i1 %16, label %17, label %34
17: ; preds = %14
%18 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %5
%19 = call i8* @stdlib_base_random_minstd_state(%struct.BasePRNGObject* %18)
store i8* %19, i8** %2
%20 = load i8*, i8** %2
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %34
24: ; preds = %17
%25 = load i32, i32* %4
%26 = icmp slt i32 %25, 999999
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load i8*, i8** %2
%29 = call i32 @free(i8* %28)
br label %30
30: ; preds = %27, %24
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %14
34: ; preds = %22, %14
%35 = call double (...) @tic()
%36 = load double, double* %3
%37 = fsub double %35, %36
store double %37, double* %1
%38 = load i8*, i8** %2
%39 = icmp eq i8* %38, null
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %40, %34
%43 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %5
%44 = call i32 @stdlib_base_random_minstd_free(%struct.BasePRNGObject* %43)
%45 = load i8*, i8** %2
%46 = call i32 @free(i8* %45)
%47 = load double, double* %1
ret double %47
}

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 @benchmark5() {
%1 = tail call %struct.BasePRNGObject* @stdlib_base_random_minstd_allocate(i32 12345)
%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 %8
8: ; preds = %6, %16
%9 = phi i32 [ 0, %6 ], [ %17, %16 ]
%10 = tail call i8* @stdlib_base_random_minstd_state(%struct.BasePRNGObject* %1)
%11 = icmp eq i8* %10, null
br i1 %11, label %21, label %12
12: ; preds = %8
%13 = icmp ult i32 %9, 999999
br i1 %13, label %14, label %16
14: ; preds = %12
%15 = tail call i32 @free(i8* %10)
br label %16
16: ; preds = %12, %14
%17 = add nuw nsw i32 %9, 1
%18 = icmp eq i32 %17, 1000000
br i1 %18, label %19, label %8
19: ; preds = %16
%20 = tail call double (...) @tic()
br label %25
21: ; preds = %8
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
%23 = tail call double (...) @tic()
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
br label %25
25: ; preds = %19, %21
%26 = phi double [ %23, %21 ], [ %20, %19 ]
%27 = fsub double %26, %7
%28 = tail call i32 @stdlib_base_random_minstd_free(%struct.BasePRNGObject* %1)
%29 = tail call i32 @free(i8* %10)
ret double %27
}