#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 */
int /*<<< orphan*/ check_srand_called();
scalar_t__ malloc(int);
scalar_t__ random();
double *malloc_double_array(int n, double min, double max) {
  double *x;
  int i;
  check_srand_called();
  x = (double *)malloc(sizeof(double) * n);
  for (i = 0; i < n; i++) {
    x[i] = min + ((double)random() / 2147483647) * (max - min);
  }
  return x;
}


x86 assembly (clang, -O0):
<malloc_double_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    $0x0,%al
call   1030 <check_srand_called@plt>
movslq -0x4(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c6 <malloc_double_array+0x96>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
movsd  -0x30(%rbp),%xmm1
cvtsi2sd %rax,%xmm0
movsd  0xe6b(%rip),%xmm2
divsd  %xmm2,%xmm0
movsd  -0x18(%rbp),%xmm2
subsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1166 <malloc_double_array+0x36>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<malloc_double_array>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
movsd  %xmm1,(%rsp)
movsd  %xmm0,0x8(%rsp)
mov    %edi,%r14d
xor    %eax,%eax
call   1030 <check_srand_called@plt>
lea    0x0(,%r14,8),%edi
call   1050 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    11b1 <malloc_double_array+0x81>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rsp)
mov    %r14d,%r14d
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <random@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  0xe69(%rip),%xmm0
mulsd  (%rsp),%xmm0
addsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%r15,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1180 <malloc_double_array+0x50>
mov    %r15,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double* @malloc_double_array(i32 %0, double %1, double %2) {
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca double*
%8 = alloca i32
store i32 %0, i32* %4
store double %1, double* %5
store double %2, double* %6
%9 = call i32 (...) @check_srand_called()
%10 = load i32, i32* %4
%11 = sext i32 %10 to i64
%12 = mul i64 8, %11
%13 = trunc i64 %12 to i32
%14 = call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to double*
store double* %15, double** %7
store i32 0, i32* %8
br label %16
16: ; preds = %33, %3
%17 = load i32, i32* %8
%18 = load i32, i32* %4
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %36
20: ; preds = %16
%21 = load double, double* %5
%22 = call i64 (...) @random()
%23 = sitofp i64 %22 to double
%24 = fdiv double %23, 0x41DFFFFFFFC00000
%25 = load double, double* %6
%26 = load double, double* %5
%27 = fsub double %25, %26
%28 = call double @llvm.fmuladd.f64(double %24, double %27, double %21)
%29 = load double*, double** %7
%30 = load i32, i32* %8
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
store double %28, double* %32
br label %33
33: ; preds = %20
%34 = load i32, i32* %8
%35 = add nsw i32 %34, 1
store i32 %35, i32* %8
br label %16
36: ; preds = %16
%37 = load double*, double** %7
ret double* %37
}

LLVM IR (-O2):
define double* @malloc_double_array(i32 %0, double %1, double %2) {
%4 = tail call i32 (...) @check_srand_called()
%5 = shl i32 %0, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to double*
%8 = icmp sgt i32 %0, 0
br i1 %8, label %9, label %21
9: ; preds = %3
%10 = fsub double %2, %1
%11 = zext i32 %0 to i64
br label %12
12: ; preds = %9, %12
%13 = phi i64 [ 0, %9 ], [ %19, %12 ]
%14 = tail call i64 (...) @random()
%15 = sitofp i64 %14 to double
%16 = fdiv double %15, 0x41DFFFFFFFC00000
%17 = tail call double @llvm.fmuladd.f64(double %16, double %10, double %1)
%18 = getelementptr inbounds double, double* %7, i64 %13
store double %17, double* %18
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %11
br i1 %20, label %21, label %12
21: ; preds = %12, %3
ret double* %7
}