#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__ malloc(int);
scalar_t__ rand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
double *rand_double_arr(int size) {
  double *res = (double *)malloc(size * sizeof(double));
  srand((unsigned)time(NULL));
  for (int i = 0; i < size; ++i) {
    res[i] = (double)rand() / RAND_MAX;
  }
  return res;
}


x86 assembly (clang, -O0):
<rand_double_arr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11b3 <rand_double_arr+0x73>
mov    $0x0,%al
call   1060 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e54(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1175 <rand_double_arr+0x35>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_double_arr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0x0(,%r14,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %r14d,%r14d
jle    11a3 <rand_double_arr+0x63>
mov    %r14d,%r12d
mov    0x2e70(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r14),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1180 <rand_double_arr+0x40>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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