#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 */
double RAND_MAX;
scalar_t__ calloc(int, int);
scalar_t__ rand();
double *random_vect(int n) {
  int i;
  double *v = (double *)calloc(n, sizeof(double));
  for (i = 0; i < n; i++)
    v[i] = (double)rand() / (RAND_MAX + 1.0);
  return (v);
}


x86 assembly (clang, -O0):
<random_vect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    118d <random_vect+0x6d>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2sd %rax,%xmm0
movsd  0xe9d(%rip),%xmm1
mov    0x2e7e(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1143 <random_vect+0x23>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_vect>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x8,%esi
call   1030 <calloc@plt>
mov    %rax,%r15
test   %ebp,%ebp
jle    117f <random_vect+0x5f>
mov    %ebp,%ebp
mov    0x2ea5(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%r14),%xmm1
addsd  0xe94(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1150 <random_vect+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define double* @random_vect(i32 %0) {
%2 = tail call i64 @calloc(i32 %0, i32 8)
%3 = inttoptr i64 %2 to double*
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %17
5: ; preds = %1
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %15, %7 ]
%9 = tail call i64 (...) @rand()
%10 = sitofp i64 %9 to double
%11 = load double, double* @RAND_MAX
%12 = fadd double %11, 1.000000e+00
%13 = fdiv double %10, %12
%14 = getelementptr inbounds double, double* %3, i64 %8
store double %13, double* %14
%15 = add nuw nsw i64 %8, 1
%16 = icmp eq i64 %15, %6
br i1 %16, label %17, label %7
17: ; preds = %7, %1
ret double* %3
}