#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 /*<<< orphan*/ time_t;

/* Variables and functions */
int drand48();
scalar_t__ malloc(int);
int /*<<< orphan*/ srand48(long);
scalar_t__ time(int /*<<< orphan*/ *);
void genrandom(long *ranseed, int count, double *ranvalues) {
  static int initialized = 0;
  static double history[97];
  int i;
  double probe;
  int selection;
  time_t *tloc;
  if ((!initialized) || (ranseed == 0)) {
    initialized = 1;
    if (*ranseed == 0) {
      tloc = (time_t *)malloc(sizeof(time_t));
      *ranseed = (long)time(tloc);
    }
    srand48(*ranseed);
    for (i = 0; i < 97; i++)
      history[i] = drand48();
  }
  for (i = 0; i < count; i++) {
    probe = drand48();
    selection = (int)(97 * drand48());
    ranvalues[i] = history[selection];
    history[selection] = drand48();
  }
}


x86 assembly (clang, -O0):
<genrandom>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
cmpl   $0x0,0x2ef6(%rip)
je     116b <genrandom+0x2b>
cmpq   $0x0,-0x8(%rbp)
jne    11ef <genrandom+0xaf>
movl   $0x1,0x2edb(%rip)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jne    11a4 <genrandom+0x64>
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <time@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
call   1050 <srand48@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x61,-0x1c(%rbp)
jge    11ea <genrandom+0xaa>
mov    $0x0,%al
call   1060 <drand48@plt>
cvtsi2sd %eax,%xmm0
movslq -0x1c(%rbp),%rcx
lea    0x2e89(%rip),%rax
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11b7 <genrandom+0x77>
jmp    11ef <genrandom+0xaf>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1265 <genrandom+0x125>
mov    $0x0,%al
call   1060 <drand48@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1060 <drand48@plt>
imul   $0x61,%eax,%eax
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rcx
lea    0x2e36(%rip),%rax
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    $0x0,%al
call   1060 <drand48@plt>
cvtsi2sd %eax,%xmm0
movslq -0x2c(%rbp),%rcx
lea    0x2e0e(%rip),%rax
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f6 <genrandom+0xb6>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genrandom>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rbp
test   %rdi,%rdi
je     115f <genrandom+0x1f>
testb  $0x1,0x2ef3(%rip)
jne    11c1 <genrandom+0x81>
movb   $0x1,0x2eea(%rip)
mov    0x0(%rbp),%rdi
test   %rdi,%rdi
jne    1188 <genrandom+0x48>
mov    $0x4,%edi
call   1040 <malloc@plt>
mov    %rax,%rdi
call   1030 <time@plt>
mov    %rax,%rdi
mov    %rax,0x0(%rbp)
call   1050 <srand48@plt>
lea    0x2ecc(%rip),%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <drand48@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x0(%rbp,%rbx,1)
add    $0x8,%rbp
cmp    $0x308,%rbp
jne    11a0 <genrandom+0x60>
test   %r14d,%r14d
jle    121d <genrandom+0xdd>
mov    %r14d,%r14d
lea    0x2e90(%rip),%r12
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <drand48@plt>
xor    %eax,%eax
call   1060 <drand48@plt>
imul   $0x61,%eax,%eax
movslq %eax,%rbx
movsd  (%r12,%rbx,8),%xmm0
movsd  %xmm0,(%r15,%rbp,8)
xor    %eax,%eax
call   1060 <drand48@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,(%r12,%rbx,8)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    11e0 <genrandom+0xa0>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@genrandom.initialized = internal global i32 0
@genrandom.history = internal global [97 x double] zeroinitializer
define void @genrandom(i64* %0, i32 %1, double* %2) {
%4 = alloca i64*
%5 = alloca i32
%6 = alloca double*
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
%10 = alloca i32*
store i64* %0, i64** %4
store i32 %1, i32* %5
store double* %2, double** %6
%11 = load i32, i32* @genrandom.initialized
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i64*, i64** %4
%15 = icmp eq i64* %14, null
br i1 %15, label %16, label %43
16: ; preds = %13, %3
store i32 1, i32* @genrandom.initialized
%17 = load i64*, i64** %4
%18 = load i64, i64* %17
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = call i64 @malloc(i32 4)
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %10
%23 = load i32*, i32** %10
%24 = call i64 @time(i32* %23)
%25 = load i64*, i64** %4
store i64 %24, i64* %25
br label %26
26: ; preds = %20, %16
%27 = load i64*, i64** %4
%28 = load i64, i64* %27
%29 = call i32 @srand48(i64 %28)
store i32 0, i32* %7
br label %30
30: ; preds = %39, %26
%31 = load i32, i32* %7
%32 = icmp slt i32 %31, 97
br i1 %32, label %33, label %42
33: ; preds = %30
%34 = call i32 (...) @drand48()
%35 = sitofp i32 %34 to double
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [97 x double], [97 x double]* @genrandom.history, i64 0, i64 %37
store double %35, double* %38
br label %39
39: ; preds = %33
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %30
42: ; preds = %30
br label %43
43: ; preds = %42, %13
store i32 0, i32* %7
br label %44
44: ; preds = %66, %43
%45 = load i32, i32* %7
%46 = load i32, i32* %5
%47 = icmp slt i32 %45, %46
br i1 %47, label %48, label %69
48: ; preds = %44
%49 = call i32 (...) @drand48()
%50 = sitofp i32 %49 to double
store double %50, double* %8
%51 = call i32 (...) @drand48()
%52 = mul nsw i32 97, %51
store i32 %52, i32* %9
%53 = load i32, i32* %9
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds [97 x double], [97 x double]* @genrandom.history, i64 0, i64 %54
%56 = load double, double* %55
%57 = load double*, double** %6
%58 = load i32, i32* %7
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds double, double* %57, i64 %59
store double %56, double* %60
%61 = call i32 (...) @drand48()
%62 = sitofp i32 %61 to double
%63 = load i32, i32* %9
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds [97 x double], [97 x double]* @genrandom.history, i64 0, i64 %64
store double %62, double* %65
br label %66
66: ; preds = %48
%67 = load i32, i32* %7
%68 = add nsw i32 %67, 1
store i32 %68, i32* %7
br label %44
69: ; preds = %44
ret void
}

LLVM IR (-O2):
@genrandom.initialized = internal unnamed_addr global i1 false
@genrandom.history = internal unnamed_addr global [97 x double] zeroinitializer
define void @genrandom(i64* %0, i32 %1, double* nocapture writeonly %2) {
%4 = load i1, i1* @genrandom.initialized
%5 = icmp ne i64* %0, null
%6 = and i1 %5, %4
br i1 %6, label %24, label %7
7: ; preds = %3
store i1 true, i1* @genrandom.initialized
%8 = load i64, i64* %0
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = tail call i64 @malloc(i32 4)
%12 = inttoptr i64 %11 to i32*
%13 = tail call i64 @time(i32* %12)
store i64 %13, i64* %0
br label %14
14: ; preds = %10, %7
%15 = phi i64 [ %13, %10 ], [ %8, %7 ]
%16 = tail call i32 @srand48(i64 %15)
br label %17
17: ; preds = %14, %17
%18 = phi i64 [ 0, %14 ], [ %22, %17 ]
%19 = tail call i32 (...) @drand48()
%20 = sitofp i32 %19 to double
%21 = getelementptr inbounds [97 x double], [97 x double]* @genrandom.history, i64 0, i64 %18
store double %20, double* %21
%22 = add nuw nsw i64 %18, 1
%23 = icmp eq i64 %22, 97
br i1 %23, label %24, label %17
24: ; preds = %17, %3
%25 = icmp sgt i32 %1, 0
br i1 %25, label %26, label %41
26: ; preds = %24
%27 = zext i32 %1 to i64
br label %28
28: ; preds = %26, %28
%29 = phi i64 [ 0, %26 ], [ %39, %28 ]
%30 = tail call i32 (...) @drand48()
%31 = tail call i32 (...) @drand48()
%32 = mul nsw i32 %31, 97
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [97 x double], [97 x double]* @genrandom.history, i64 0, i64 %33
%35 = load double, double* %34
%36 = getelementptr inbounds double, double* %2, i64 %29
store double %35, double* %36
%37 = tail call i32 (...) @drand48()
%38 = sitofp i32 %37 to double
store double %38, double* %34
%39 = add nuw nsw i64 %29, 1
%40 = icmp eq i64 %39, %27
br i1 %40, label %41, label %28
41: ; preds = %28, %24
ret void
}