#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 */
typedef int uint32_t;
struct BasePRNGObject {
  int dummy;
};
typedef scalar_t__ int8_t;
typedef int int64_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
struct BasePRNGObject *stdlib_base_random_mt19937_allocate(int *, int);
int /*<<< orphan*/ stdlib_base_random_mt19937_free(struct BasePRNGObject *);
scalar_t__ stdlib_base_random_mt19937_seed(struct BasePRNGObject *, int *);
scalar_t__ stdlib_base_random_mt19937_seed_length(struct BasePRNGObject *,
                                                  int *);
double tic();
double benchmark4() {
  uint32_t seed[1];
  double elapsed;
  int8_t status;
  int64_t len;
  double t;
  int i;
  seed[0] = 12345;
  struct BasePRNGObject *obj = stdlib_base_random_mt19937_allocate(seed, 1);
  if (obj == NULL) {
    printf("unable to allocate memory\n");
    exit(1);
  }
  t = tic();
  for (i = 0; i < 1000000; i++) {
    status = stdlib_base_random_mt19937_seed_length(obj, &len);
    if (status != 0 || len != 1) {
      printf("unexpected result\n");
    }
    status = stdlib_base_random_mt19937_seed(obj, seed);
    if (status != 0 || seed[0] != 12345) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (status != 0 || len != 1 || seed[0] != 12345) {
    printf("unexpected result\n");
  }
  stdlib_base_random_mt19937_free(obj);
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark4>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x3039,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
mov    $0x1,%esi
call   1070 <stdlib_base_random_mt19937_allocate@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    11b2 <benchmark4+0x42>
lea    0xe5d(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   1060 <tic@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xf4240,-0x2c(%rbp)
jge    1251 <benchmark4+0xe1>
mov    -0x38(%rbp),%rdi
lea    -0x1c(%rbp),%rsi
call   1080 <stdlib_base_random_mt19937_seed_length@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11f8 <benchmark4+0x88>
cmpl   $0x1,-0x1c(%rbp)
je     1204 <benchmark4+0x94>
lea    0xe1c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x4(%rbp),%rsi
call   1040 <stdlib_base_random_mt19937_seed@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    122d <benchmark4+0xbd>
cmpl   $0x3039,-0x4(%rbp)
je     123e <benchmark4+0xce>
lea    0xde7(%rip),%rdi
call   1050 <printf@plt>
jmp    1251 <benchmark4+0xe1>
jmp    1243 <benchmark4+0xd3>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11c5 <benchmark4+0x55>
mov    $0x0,%al
call   1060 <tic@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1284 <benchmark4+0x114>
cmpl   $0x1,-0x1c(%rbp)
jne    1284 <benchmark4+0x114>
cmpl   $0x3039,-0x4(%rbp)
je     1290 <benchmark4+0x120>
lea    0xd90(%rip),%rdi
call   1050 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <stdlib_base_random_mt19937_free@plt>
movsd  -0x10(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark4>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
movl   $0x3039,(%rsp)
mov    %rsp,%rdi
mov    $0x1,%esi
call   1070 <stdlib_base_random_mt19937_allocate@plt>
test   %rax,%rax
je     126c <benchmark4+0xfc>
mov    %rax,%r13
xor    %eax,%eax
call   1060 <tic@plt>
movsd  %xmm0,0x10(%rsp)
mov    $0xf4240,%ebp
lea    0x4(%rsp),%r14
lea    0xe44(%rip),%r15
mov    %rsp,%r12
nop
mov    %r13,%rdi
mov    %r14,%rsi
call   1080 <stdlib_base_random_mt19937_seed_length@plt>
test   %rax,%rax
jne    11d7 <benchmark4+0x67>
cmpl   $0x1,0x4(%rsp)
je     11df <benchmark4+0x6f>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1050 <stdlib_base_random_mt19937_seed@plt>
test   %rax,%rax
setne  %bl
jne    1204 <benchmark4+0x94>
cmpl   $0x3039,(%rsp)
jne    1204 <benchmark4+0x94>
add    $0xffffffff,%ebp
jne    11c0 <benchmark4+0x50>
xor    %ebx,%ebx
jmp    1210 <benchmark4+0xa0>
lea    0xdf5(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <tic@plt>
movsd  %xmm0,0x8(%rsp)
test   %bl,%bl
jne    1231 <benchmark4+0xc1>
cmpl   $0x1,0x4(%rsp)
jne    1231 <benchmark4+0xc1>
cmpl   $0x3039,(%rsp)
je     123d <benchmark4+0xcd>
lea    0xdc8(%rip),%rdi
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
mov    %r13,%rdi
call   1040 <stdlib_base_random_mt19937_free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd9f(%rip),%rdi
call   1030 <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 @benchmark4() {
%1 = alloca [1 x i32]
%2 = alloca double
%3 = alloca i64
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
%7 = alloca %struct.BasePRNGObject*
%8 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
store i32 12345, i32* %8
%9 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
%10 = call %struct.BasePRNGObject* @stdlib_base_random_mt19937_allocate(i32* %9, i32 1)
store %struct.BasePRNGObject* %10, %struct.BasePRNGObject** %7
%11 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %7
%12 = icmp eq %struct.BasePRNGObject* %11, null
br i1 %12, label %13, label %16
13: ; preds = %0
%14 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %0
%17 = call double (...) @tic()
store double %17, double* %5
store i32 0, i32* %6
br label %18
18: ; preds = %44, %16
%19 = load i32, i32* %6
%20 = icmp slt i32 %19, 1000000
br i1 %20, label %21, label %47
21: ; preds = %18
%22 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %7
%23 = call i64 @stdlib_base_random_mt19937_seed_length(%struct.BasePRNGObject* %22, i32* %4)
store i64 %23, i64* %3
%24 = load i64, i64* %3
%25 = icmp ne i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load i32, i32* %4
%28 = icmp ne i32 %27, 1
br i1 %28, label %29, label %31
29: ; preds = %26, %21
%30 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %26
%32 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %7
%33 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
%34 = call i64 @stdlib_base_random_mt19937_seed(%struct.BasePRNGObject* %32, i32* %33)
store i64 %34, i64* %3
%35 = load i64, i64* %3
%36 = icmp ne i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %31
%38 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
%39 = load i32, i32* %38
%40 = icmp ne i32 %39, 12345
br i1 %40, label %41, label %43
41: ; preds = %37, %31
%42 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %47
43: ; preds = %37
br label %44
44: ; preds = %43
%45 = load i32, i32* %6
%46 = add nsw i32 %45, 1
store i32 %46, i32* %6
br label %18
47: ; preds = %41, %18
%48 = call double (...) @tic()
%49 = load double, double* %5
%50 = fsub double %48, %49
store double %50, double* %2
%51 = load i64, i64* %3
%52 = icmp ne i64 %51, 0
br i1 %52, label %60, label %53
53: ; preds = %47
%54 = load i32, i32* %4
%55 = icmp ne i32 %54, 1
br i1 %55, label %60, label %56
56: ; preds = %53
%57 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
%58 = load i32, i32* %57
%59 = icmp ne i32 %58, 12345
br i1 %59, label %60, label %62
60: ; preds = %56, %53, %47
%61 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %62
62: ; preds = %60, %56
%63 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %7
%64 = call i32 @stdlib_base_random_mt19937_free(%struct.BasePRNGObject* %63)
%65 = load double, double* %2
ret double %65
}

LLVM IR (-O2):
%struct.BasePRNGObject = type { i32 }
@str.3 = [18 x i8] c"unexpected result\00"
@str.4 = [26 x i8] c"unable to allocate memory\00"
define double @benchmark4() {
%1 = alloca [1 x i32]
%2 = alloca i32
%3 = bitcast [1 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = getelementptr inbounds [1 x i32], [1 x i32]* %1, i64 0, i64 0
store i32 12345, i32* %5
%6 = call %struct.BasePRNGObject* @stdlib_base_random_mt19937_allocate(i32* %5, i32 1)
%7 = icmp eq %struct.BasePRNGObject* %6, null
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.4, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call double (...) @tic()
br label %16
13: ; preds = %25
%14 = add nuw nsw i32 %17, 1
%15 = icmp eq i32 %14, 1000000
br i1 %15, label %33, label %16
16: ; preds = %11, %13
%17 = phi i32 [ 0, %11 ], [ %14, %13 ]
%18 = call i64 @stdlib_base_random_mt19937_seed_length(%struct.BasePRNGObject* %6, i32* %2)
%19 = icmp ne i64 %18, 0
%20 = load i32, i32* %2
%21 = icmp ne i32 %20, 1
%22 = select i1 %19, i1 true, i1 %21
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
br label %25
25: ; preds = %16, %23
%26 = call i64 @stdlib_base_random_mt19937_seed(%struct.BasePRNGObject* %6, i32* %5)
%27 = icmp ne i64 %26, 0
%28 = load i32, i32* %5
%29 = icmp ne i32 %28, 12345
%30 = select i1 %27, i1 true, i1 %29
br i1 %30, label %31, label %13
31: ; preds = %25
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
br label %33
33: ; preds = %13, %31
%34 = phi i1 [ %27, %31 ], [ false, %13 ]
%35 = call double (...) @tic()
%36 = load i32, i32* %2
%37 = icmp ne i32 %36, 1
%38 = select i1 %34, i1 true, i1 %37
%39 = load i32, i32* %5
%40 = icmp ne i32 %39, 12345
%41 = select i1 %38, i1 true, i1 %40
br i1 %41, label %42, label %44
42: ; preds = %33
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.3, i64 0, i64 0))
br label %44
44: ; preds = %33, %42
%45 = fsub double %35, %12
%46 = call i32 @stdlib_base_random_mt19937_free(%struct.BasePRNGObject* %6)
ret double %45
}