#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 scalar_t__ uint32_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ UINT32_MAX;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, double, double);
scalar_t__ time(int /*<<< orphan*/ *);
void test_rand(int nsteps, FILE *fout, double (*prand)(double)) {
  double z;
  double z_next;
  int i;
  uint32_t x;
  x = time(NULL);
  z = prand((double)x / (double)UINT32_MAX);
  for (i = 0; i < nsteps; i++) {
    z_next = prand(z);
    fprintf(fout, "%.12f\t%.12f\n", z, z_next);
    z = z_next;
  }
}


x86 assembly (clang, -O0):
<test_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
cvtsi2sdq -0x38(%rbp),%xmm0
mov    0x2ea7(%rip),%rcx
cvtsi2sdq (%rcx),%xmm1
divsd  %xmm1,%xmm0
call   *%rax
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b6 <test_rand+0x96>
mov    -0x18(%rbp),%rax
movsd  -0x20(%rbp),%xmm0
call   *%rax
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
lea    0xe67(%rip),%rsi
call   1030 <fprintf@plt>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1168 <test_rand+0x48>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_rand>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%ebp
xor    %edi,%edi
call   1040 <time@plt>
cvtsi2sd %rax,%xmm0
mov    0x2eb3(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
call   *%rbx
test   %ebp,%ebp
jle    118e <test_rand+0x6e>
lea    0xea5(%rip),%r15
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,0x10(%rsp)
call   *%rbx
movapd %xmm0,%xmm1
movsd  %xmm0,0x8(%rsp)
mov    %r14,%rdi
mov    %r15,%rsi
movsd  0x10(%rsp),%xmm0
call   1030 <fprintf@plt>
movsd  0x8(%rsp),%xmm0
add    $0xffffffff,%ebp
jne    1160 <test_rand+0x40>
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@UINT32_MAX = global i64 0
@.str = [13 x i8] c"%.12f\09%.12f\0A\00"
define void @test_rand(i32 %0, i32* %1, double (double)* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca double (double)*
%7 = alloca double
%8 = alloca double
%9 = alloca i32
%10 = alloca i64
store i32 %0, i32* %4
store i32* %1, i32** %5
store double (double)* %2, double (double)** %6
%11 = call i64 @time(i32* null)
store i64 %11, i64* %10
%12 = load double (double)*, double (double)** %6
%13 = load i64, i64* %10
%14 = sitofp i64 %13 to double
%15 = load i64, i64* @UINT32_MAX
%16 = sitofp i64 %15 to double
%17 = fdiv double %14, %16
%18 = call double %12(double %17)
store double %18, double* %7
store i32 0, i32* %9
br label %19
19: ; preds = %32, %3
%20 = load i32, i32* %9
%21 = load i32, i32* %4
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %35
23: ; preds = %19
%24 = load double (double)*, double (double)** %6
%25 = load double, double* %7
%26 = call double %24(double %25)
store double %26, double* %8
%27 = load i32*, i32** %5
%28 = load double, double* %7
%29 = load double, double* %8
%30 = call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %28, double %29)
%31 = load double, double* %8
store double %31, double* %7
br label %32
32: ; preds = %23
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %19
35: ; preds = %19
ret void
}

LLVM IR (-O2):
@UINT32_MAX = global i64 0
@.str = [13 x i8] c"%.12f\09%.12f\0A\00"
define void @test_rand(i32 %0, i32* nocapture %1, double (double)* nocapture %2) {
%4 = tail call i64 @time(i32* null)
%5 = sitofp i64 %4 to double
%6 = load i64, i64* @UINT32_MAX
%7 = sitofp i64 %6 to double
%8 = fdiv double %5, %7
%9 = tail call double %2(double %8)
%10 = icmp sgt i32 %0, 0
br i1 %10, label %11, label %18
11: ; preds = %3, %11
%12 = phi double [ %14, %11 ], [ %9, %3 ]
%13 = phi i32 [ %16, %11 ], [ 0, %3 ]
%14 = tail call double %2(double %12)
%15 = tail call i32 @fprintf(i32* %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), double %12, double %14)
%16 = add nuw nsw i32 %13, 1
%17 = icmp eq i32 %16, %0
br i1 %17, label %18, label %11
18: ; preds = %11, %3
ret void
}