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

/* Variables and functions */
scalar_t__ rand();
int /*<<< orphan*/ srand(int);
void randvec(double *v, int n) {
  double x;
  int k, seed = 4321;
  srand(seed);
  for (k = 0; k < n; k++) {
    x = ((double)rand() / ((double)(RAND_MAX) + (double)(1)));
    v[k] = x;
  }
}


x86 assembly (clang, -O0):
<randvec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x10e1,-0x20(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <srand@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    118e <randvec+0x6e>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2sd %rax,%xmm0
movsd  0xe9b(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1145 <randvec+0x25>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randvec>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0x10e1,%edi
call   1030 <srand@plt>
test   %ebp,%ebp
jle    115e <randvec+0x3e>
mov    %ebp,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <randvec+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @randvec(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
%7 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store i32 4321, i32* %7
%8 = load i32, i32* %7
%9 = call i32 @srand(i32 %8)
store i32 0, i32* %6
br label %10
10: ; preds = %23, %2
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %26
14: ; preds = %10
%15 = call i64 (...) @rand()
%16 = sitofp i64 %15 to double
%17 = fdiv double %16, 1.000000e+00
store double %17, double* %5
%18 = load double, double* %5
%19 = load double*, double** %3
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
store double %18, double* %22
br label %23
23: ; preds = %14
%24 = load i32, i32* %6
%25 = add nsw i32 %24, 1
store i32 %25, i32* %6
br label %10
26: ; preds = %10
ret void
}

LLVM IR (-O2):
define void @randvec(double* nocapture writeonly %0, i32 %1) {
%3 = tail call i32 @srand(i32 4321)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %12, %7 ]
%9 = tail call i64 (...) @rand()
%10 = sitofp i64 %9 to double
%11 = getelementptr inbounds double, double* %0, i64 %8
store double %10, double* %11
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, %6
br i1 %13, label %14, label %7
14: ; preds = %7, %2
ret void
}