#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 drand48();
int lrand48();
void fill_double_array(double *array, double min_range, double max_range) {
  for (int i = 0; i < (1024 / 2); i++) {
    double tmp = drand48();
    tmp *= (lrand48() % 2) ? 1.0 : max_range;
    while (tmp < min_range) {
      tmp = drand48() * max_range;
    }
    array[i] = tmp;
  }
}


x86 assembly (clang, -O0):
<fill_double_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x200,-0x1c(%rbp)
jge    11e3 <fill_double_array+0xc3>
mov    $0x0,%al
call   1040 <drand48@plt>
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <lrand48@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
je     1180 <fill_double_array+0x60>
movsd  0xe8a(%rip),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    118a <fill_double_array+0x6a>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c3 <fill_double_array+0xa3>
mov    $0x0,%al
call   1040 <drand48@plt>
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1199 <fill_double_array+0x79>
movsd  -0x28(%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    113d <fill_double_array+0x1d>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_double_array>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
xor    %ebx,%ebx
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
jmp    1153 <fill_double_array+0x33>
nopl   0x0(%rax)
movsd  %xmm2,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    $0x200,%rbx
je     11b2 <fill_double_array+0x92>
xor    %eax,%eax
call   1040 <drand48@plt>
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   1030 <lrand48@plt>
movsd  0x8(%rsp),%xmm0
test   $0x1,%al
je     1179 <fill_double_array+0x59>
movsd  0xe87(%rip),%xmm0
movsd  0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
movsd  (%rsp),%xmm0
ucomisd %xmm2,%xmm0
jbe    1140 <fill_double_array+0x20>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <drand48@plt>
movsd  0x8(%rsp),%xmm1
movapd %xmm0,%xmm2
movsd  (%rsp),%xmm0
mulsd  %xmm1,%xmm2
ucomisd %xmm2,%xmm0
ja     1190 <fill_double_array+0x70>
jmp    1140 <fill_double_array+0x20>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @fill_double_array(double* %0, double %1, double %2) {
%4 = alloca double*
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca double
store double* %0, double** %4
store double %1, double* %5
store double %2, double* %6
store i32 0, i32* %7
br label %9
9: ; preds = %38, %3
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 512
br i1 %11, label %12, label %41
12: ; preds = %9
%13 = call double (...) @drand48()
store double %13, double* %8
%14 = call i32 (...) @lrand48()
%15 = srem i32 %14, 2
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %12
br label %20
18: ; preds = %12
%19 = load double, double* %6
br label %20
20: ; preds = %18, %17
%21 = phi double [ 1.000000e+00, %17 ], [ %19, %18 ]
%22 = load double, double* %8
%23 = fmul double %22, %21
store double %23, double* %8
br label %24
24: ; preds = %28, %20
%25 = load double, double* %8
%26 = load double, double* %5
%27 = fcmp olt double %25, %26
br i1 %27, label %28, label %32
28: ; preds = %24
%29 = call double (...) @drand48()
%30 = load double, double* %6
%31 = fmul double %29, %30
store double %31, double* %8
br label %24
32: ; preds = %24
%33 = load double, double* %8
%34 = load double*, double** %4
%35 = load i32, i32* %7
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds double, double* %34, i64 %36
store double %33, double* %37
br label %38
38: ; preds = %32
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
store i32 %40, i32* %7
br label %9
41: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @fill_double_array(double* nocapture writeonly %0, double %1, double %2) {
br label %5
4: ; preds = %18
ret void
5: ; preds = %3, %18
%6 = phi i64 [ 0, %3 ], [ %21, %18 ]
%7 = tail call double (...) @drand48()
%8 = tail call i32 (...) @lrand48()
%9 = and i32 %8, 1
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, double %2, double 1.000000e+00
%12 = fmul double %7, %11
%13 = fcmp olt double %12, %1
br i1 %13, label %14, label %18
14: ; preds = %5, %14
%15 = tail call double (...) @drand48()
%16 = fmul double %15, %2
%17 = fcmp olt double %16, %1
br i1 %17, label %14, label %18
18: ; preds = %14, %5
%19 = phi double [ %12, %5 ], [ %16, %14 ]
%20 = getelementptr inbounds double, double* %0, i64 %6
store double %19, double* %20
%21 = add nuw nsw i64 %6, 1
%22 = icmp eq i64 %21, 512
br i1 %22, label %4, label %5
}