#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 */

/* Variables and functions */
scalar_t__ nrandom(unsigned long *);
unsigned long srnd(unsigned int);
int nrand(double *p, const int leng, const int seed) {
  int i;
  unsigned long next;
  if (seed != 1)
    next = srnd((unsigned int)seed);
  for (i = 0; i < leng; i++)
    p[i] = (double)nrandom(&next);
  return (0);
}


x86 assembly (clang, -O0):
<nrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
je     1148 <nrand+0x28>
mov    -0x10(%rbp),%edi
call   1030 <srnd@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1184 <nrand+0x64>
lea    -0x20(%rbp),%rdi
call   1040 <nrandom@plt>
cvtsi2sd %rax,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114f <nrand+0x2f>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nrand>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r15
cmp    $0x1,%edx
je     113c <nrand+0x1c>
mov    %edx,%edi
call   1030 <srnd@plt>
mov    %rax,(%rsp)
test   %ebp,%ebp
jle    116f <nrand+0x4f>
mov    %ebp,%ebp
xor    %ebx,%ebx
mov    %rsp,%r14
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <nrandom@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <nrand+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @nrand(double* %0, i32 %1, i32 %2) {
%4 = alloca double*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store double* %0, double** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32, i32* %6
%13 = call i64 @srnd(i32 %12)
store i64 %13, i64* %8
br label %14
14: ; preds = %11, %3
store i32 0, i32* %7
br label %15
15: ; preds = %26, %14
%16 = load i32, i32* %7
%17 = load i32, i32* %5
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %29
19: ; preds = %15
%20 = call i64 @nrandom(i64* %8)
%21 = sitofp i64 %20 to double
%22 = load double*, double** %4
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
store double %21, double* %25
br label %26
26: ; preds = %19
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %15
29: ; preds = %15
ret i32 0
}

LLVM IR (-O2):
define i32 @nrand(double* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = alloca i64
%5 = bitcast i64* %4 to i8*
%6 = icmp eq i32 %2, 1
br i1 %6, label %9, label %7
7: ; preds = %3
%8 = tail call i64 @srnd(i32 %2)
store i64 %8, i64* %4
br label %9
9: ; preds = %7, %3
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %20
11: ; preds = %9
%12 = zext i32 %1 to i64
br label %13
13: ; preds = %11, %13
%14 = phi i64 [ 0, %11 ], [ %18, %13 ]
%15 = call i64 @nrandom(i64* %4)
%16 = sitofp i64 %15 to double
%17 = getelementptr inbounds double, double* %0, i64 %14
store double %16, double* %17
%18 = add nuw nsw i64 %14, 1
%19 = icmp eq i64 %18, %12
br i1 %19, label %20, label %13
20: ; preds = %13, %9
ret i32 0
}