#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;
};
typedef scalar_t__ int8_t;
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
struct BasePRNGObject *stdlib_base_random_minstd_allocate(int);
int /*<<< orphan*/ stdlib_base_random_minstd_free(struct BasePRNGObject *);
scalar_t__ stdlib_base_random_minstd_seed(struct BasePRNGObject *, int *);
double tic();
double benchmark4() {
  double elapsed;
  int8_t status;
  int32_t v;
  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++) {
    status = stdlib_base_random_minstd_seed(obj, &v);
    if (status != 0 || v != 12345) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (status != 0 || v != 12345) {
    printf("unexpected result\n");
  }
  stdlib_base_random_minstd_free(obj);
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x3039,%edi
call   1030 <stdlib_base_random_minstd_allocate@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1197 <benchmark4+0x37>
lea    0xe78(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1050 <tic@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0xf4240,-0x24(%rbp)
jge    1204 <benchmark4+0xa4>
mov    -0x30(%rbp),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <stdlib_base_random_minstd_seed@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e0 <benchmark4+0x80>
cmpl   $0x3039,-0x14(%rbp)
je     11f1 <benchmark4+0x91>
lea    0xe34(%rip),%rdi
call   1040 <printf@plt>
jmp    1204 <benchmark4+0xa4>
jmp    11f6 <benchmark4+0x96>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11aa <benchmark4+0x4a>
mov    $0x0,%al
call   1050 <tic@plt>
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    122d <benchmark4+0xcd>
cmpl   $0x3039,-0x14(%rbp)
je     1239 <benchmark4+0xd9>
lea    0xde7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1060 <stdlib_base_random_minstd_free@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark4>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    $0x3039,%edi
call   1030 <stdlib_base_random_minstd_allocate@plt>
test   %rax,%rax
je     1226 <benchmark4+0xc6>
mov    %rax,%r15
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,0x10(%rsp)
mov    $0xf4240,%ebx
lea    0x4(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <stdlib_base_random_minstd_seed@plt>
test   %rax,%rax
setne  %bpl
jne    11c7 <benchmark4+0x67>
cmpl   $0x3039,0x4(%rsp)
jne    11c7 <benchmark4+0x67>
add    $0xffffffff,%ebx
jne    11a0 <benchmark4+0x40>
xor    %ebp,%ebp
jmp    11d3 <benchmark4+0x73>
lea    0xe32(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,0x8(%rsp)
test   %bpl,%bpl
jne    11ef <benchmark4+0x8f>
cmpl   $0x3039,0x4(%rsp)
je     11fb <benchmark4+0x9b>
lea    0xe0a(%rip),%rdi
call   1040 <puts@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r15,%rdi
call   1060 <stdlib_base_random_minstd_free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   1080 <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 @benchmark4() {
%1 = alloca double
%2 = alloca i64
%3 = alloca i32
%4 = alloca double
%5 = alloca i32
%6 = alloca %struct.BasePRNGObject*
%7 = call %struct.BasePRNGObject* @stdlib_base_random_minstd_allocate(i32 12345)
store %struct.BasePRNGObject* %7, %struct.BasePRNGObject** %6
%8 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %6
%9 = icmp eq %struct.BasePRNGObject* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call double (...) @tic()
store double %14, double* %4
store i32 0, i32* %5
br label %15
15: ; preds = %29, %13
%16 = load i32, i32* %5
%17 = icmp slt i32 %16, 1000000
br i1 %17, label %18, label %32
18: ; preds = %15
%19 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %6
%20 = call i64 @stdlib_base_random_minstd_seed(%struct.BasePRNGObject* %19, i32* %3)
store i64 %20, i64* %2
%21 = load i64, i64* %2
%22 = icmp ne i64 %21, 0
br i1 %22, label %26, label %23
23: ; preds = %18
%24 = load i32, i32* %3
%25 = icmp ne i32 %24, 12345
br i1 %25, label %26, label %28
26: ; preds = %23, %18
%27 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %32
28: ; preds = %23
br label %29
29: ; preds = %28
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %15
32: ; preds = %26, %15
%33 = call double (...) @tic()
%34 = load double, double* %4
%35 = fsub double %33, %34
store double %35, double* %1
%36 = load i64, i64* %2
%37 = icmp ne i64 %36, 0
br i1 %37, label %41, label %38
38: ; preds = %32
%39 = load i32, i32* %3
%40 = icmp ne i32 %39, 12345
br i1 %40, label %41, label %43
41: ; preds = %38, %32
%42 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %43
43: ; preds = %41, %38
%44 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %6
%45 = call i32 @stdlib_base_random_minstd_free(%struct.BasePRNGObject* %44)
%46 = load double, double* %1
ret double %46
}

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 @benchmark4() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call %struct.BasePRNGObject* @stdlib_base_random_minstd_allocate(i32 12345)
%4 = icmp eq %struct.BasePRNGObject* %3, null
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.3, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = tail call double (...) @tic()
br label %13
10: ; preds = %13
%11 = add nuw nsw i32 %14, 1
%12 = icmp eq i32 %11, 1000000
br i1 %12, label %22, label %13
13: ; preds = %8, %10
%14 = phi i32 [ 0, %8 ], [ %11, %10 ]
%15 = call i64 @stdlib_base_random_minstd_seed(%struct.BasePRNGObject* %3, i32* %1)
%16 = icmp ne i64 %15, 0
%17 = load i32, i32* %1
%18 = icmp ne i32 %17, 12345
%19 = select i1 %16, i1 true, i1 %18
br i1 %19, label %20, label %10
20: ; preds = %13
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
br label %22
22: ; preds = %10, %20
%23 = phi i1 [ %16, %20 ], [ false, %10 ]
%24 = call double (...) @tic()
%25 = load i32, i32* %1
%26 = icmp ne i32 %25, 12345
%27 = select i1 %23, i1 true, i1 %26
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.2, i64 0, i64 0))
br label %30
30: ; preds = %22, %28
%31 = fsub double %24, %9
%32 = call i32 @stdlib_base_random_minstd_free(%struct.BasePRNGObject* %3)
ret double %31
}