#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;

/* Variables and functions */
struct BasePRNGObject *mock_prng_allocate(int);
int /*<<< orphan*/ printf(char *);
scalar_t__ stdlib_base_prng_copy_state(struct BasePRNGObject *,
                                       struct BasePRNGObject *);
int /*<<< orphan*/ stdlib_base_prng_free(struct BasePRNGObject *);
double tic();
double benchmark9() {
  double elapsed;
  int8_t status;
  double t;
  int i;
  struct BasePRNGObject *src[] = {mock_prng_allocate(1), mock_prng_allocate(2),
                                  mock_prng_allocate(3)};
  struct BasePRNGObject *dest = mock_prng_allocate(2);
  t = tic();
  for (i = 0; i < 1000000; i++) {
    status = stdlib_base_prng_copy_state(dest, src[i % 3]);
    if (status != 0) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (status != 0) {
    printf("unexpected result\n");
  }
  for (i = 0; i < 3; i++) {
    stdlib_base_prng_free(src[i]);
  }
  stdlib_base_prng_free(dest);
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark9>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    $0x1,%edi
call   1050 <mock_prng_allocate@plt>
mov    %rax,-0x40(%rbp)
mov    $0x2,%edi
call   1050 <mock_prng_allocate@plt>
mov    %rax,-0x38(%rbp)
mov    $0x3,%edi
call   1050 <mock_prng_allocate@plt>
mov    %rax,-0x30(%rbp)
mov    $0x2,%edi
call   1050 <mock_prng_allocate@plt>
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0xf4240,-0x1c(%rbp)
jge    11ff <benchmark9+0xaf>
mov    -0x48(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    $0x3,%ecx
cltd
idiv   %ecx
movslq %edx,%rax
mov    -0x40(%rbp,%rax,8),%rsi
call   1060 <stdlib_base_prng_copy_state@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ec <benchmark9+0x9c>
lea    0xe1e(%rip),%rdi
call   1030 <printf@plt>
jmp    11ff <benchmark9+0xaf>
jmp    11f1 <benchmark9+0xa1>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a3 <benchmark9+0x53>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1227 <benchmark9+0xd7>
lea    0xdde(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
jge    1254 <benchmark9+0x104>
movslq -0x1c(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%rdi
call   1070 <stdlib_base_prng_free@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    122e <benchmark9+0xde>
mov    -0x48(%rbp),%rdi
call   1070 <stdlib_base_prng_free@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark9>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    $0x1,%edi
call   1050 <mock_prng_allocate@plt>
mov    %rax,0x18(%rsp)
mov    %rax,0x20(%rsp)
mov    $0x2,%edi
call   1050 <mock_prng_allocate@plt>
mov    %rax,0x10(%rsp)
mov    %rax,0x28(%rsp)
mov    $0x3,%edi
call   1050 <mock_prng_allocate@plt>
mov    %rax,%r12
mov    %rax,0x30(%rsp)
mov    $0x2,%edi
call   1050 <mock_prng_allocate@plt>
mov    %rax,%r13
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xf4240,%ebp
lea    0x20(%rsp),%r14
movabs $0xaaaaaaaaaaaaaaab,%r15
aa aa aa
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rax
mul    %r15
shl    $0x2,%rdx
and    $0xfffffffffffffff8,%rdx
lea    (%rdx,%rdx,2),%rax
mov    %r14,%rcx
sub    %rax,%rcx
mov    (%rcx),%rsi
mov    %r13,%rdi
call   1060 <stdlib_base_prng_copy_state@plt>
test   %rax,%rax
jne    1213 <benchmark9+0xc3>
add    $0x8,%r14
add    $0x1,%rbx
add    $0xffffffff,%ebp
jne    11d0 <benchmark9+0x80>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,(%rsp)
jmp    1236 <benchmark9+0xe6>
lea    0xde6(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x18(%rsp),%rdi
call   1070 <stdlib_base_prng_free@plt>
mov    0x10(%rsp),%rdi
call   1070 <stdlib_base_prng_free@plt>
mov    %r12,%rdi
call   1070 <stdlib_base_prng_free@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %r13,%rdi
call   1070 <stdlib_base_prng_free@plt>
movsd  (%rsp),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.BasePRNGObject = type { i32 }
@.str = [19 x i8] c"unexpected result\0A\00"
define double @benchmark9() {
%1 = alloca double
%2 = alloca i64
%3 = alloca double
%4 = alloca i32
%5 = alloca [3 x %struct.BasePRNGObject*]
%6 = alloca %struct.BasePRNGObject*
%7 = getelementptr inbounds [3 x %struct.BasePRNGObject*], [3 x %struct.BasePRNGObject*]* %5, i64 0, i64 0
%8 = call %struct.BasePRNGObject* @mock_prng_allocate(i32 1)
store %struct.BasePRNGObject* %8, %struct.BasePRNGObject** %7
%9 = getelementptr inbounds %struct.BasePRNGObject*, %struct.BasePRNGObject** %7, i64 1
%10 = call %struct.BasePRNGObject* @mock_prng_allocate(i32 2)
store %struct.BasePRNGObject* %10, %struct.BasePRNGObject** %9
%11 = getelementptr inbounds %struct.BasePRNGObject*, %struct.BasePRNGObject** %9, i64 1
%12 = call %struct.BasePRNGObject* @mock_prng_allocate(i32 3)
store %struct.BasePRNGObject* %12, %struct.BasePRNGObject** %11
%13 = call %struct.BasePRNGObject* @mock_prng_allocate(i32 2)
store %struct.BasePRNGObject* %13, %struct.BasePRNGObject** %6
%14 = call double (...) @tic()
store double %14, double* %3
store i32 0, i32* %4
br label %15
15: ; preds = %31, %0
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 1000000
br i1 %17, label %18, label %34
18: ; preds = %15
%19 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %6
%20 = load i32, i32* %4
%21 = srem i32 %20, 3
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds [3 x %struct.BasePRNGObject*], [3 x %struct.BasePRNGObject*]* %5, i64 0, i64 %22
%24 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %23
%25 = call i64 @stdlib_base_prng_copy_state(%struct.BasePRNGObject* %19, %struct.BasePRNGObject* %24)
store i64 %25, i64* %2
%26 = load i64, i64* %2
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %34
30: ; preds = %18
br label %31
31: ; preds = %30
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 1
store i32 %33, i32* %4
br label %15
34: ; preds = %28, %15
%35 = call double (...) @tic()
%36 = load double, double* %3
%37 = fsub double %35, %36
store double %37, double* %1
%38 = load i64, i64* %2
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %34
%41 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %42
42: ; preds = %40, %34
store i32 0, i32* %4
br label %43
43: ; preds = %52, %42
%44 = load i32, i32* %4
%45 = icmp slt i32 %44, 3
br i1 %45, label %46, label %55
46: ; preds = %43
%47 = load i32, i32* %4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds [3 x %struct.BasePRNGObject*], [3 x %struct.BasePRNGObject*]* %5, i64 0, i64 %48
%50 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %49
%51 = call i32 @stdlib_base_prng_free(%struct.BasePRNGObject* %50)
br label %52
52: ; preds = %46
%53 = load i32, i32* %4
%54 = add nsw i32 %53, 1
store i32 %54, i32* %4
br label %43
55: ; preds = %43
%56 = load %struct.BasePRNGObject*, %struct.BasePRNGObject** %6
%57 = call i32 @stdlib_base_prng_free(%struct.BasePRNGObject* %56)
%58 = load double, double* %1
ret double %58
}

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