#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 LONG_MAX;
int random();
void gen_doubles(double *val, unsigned card) {
  unsigned i;
  for (i = 0; i < card; i++) {
    val[i] = (double)(random() - (LONG_MAX / 2)) / ((LONG_MAX / 2) + 1);
  }
}


x86 assembly (clang, -O0):
<gen_doubles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jae    118e <gen_doubles+0x7e>
mov    $0x0,%al
call   1030 <random@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e9d(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <gen_doubles+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_doubles>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
je     1169 <gen_doubles+0x59>
mov    %rdi,%r14
mov    %esi,%r12d
mov    0x2eb7(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <random@plt>
mov    (%r15),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
sub    %edx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x1,%edx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1130 <gen_doubles+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LONG_MAX = global i32 0
define void @gen_doubles(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %6
6: ; preds = %25, %2
%7 = load i32, i32* %5
%8 = load i32, i32* %4
%9 = icmp ult i32 %7, %8
br i1 %9, label %10, label %28
10: ; preds = %6
%11 = call i32 (...) @random()
%12 = load i32, i32* @LONG_MAX
%13 = sdiv i32 %12, 2
%14 = sub nsw i32 %11, %13
%15 = sitofp i32 %14 to double
%16 = load i32, i32* @LONG_MAX
%17 = sdiv i32 %16, 2
%18 = add nsw i32 %17, 1
%19 = sitofp i32 %18 to double
%20 = fdiv double %15, %19
%21 = load double*, double** %3
%22 = load i32, i32* %5
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds double, double* %21, i64 %23
store double %20, double* %24
br label %25
25: ; preds = %10
%26 = load i32, i32* %5
%27 = add i32 %26, 1
store i32 %27, i32* %5
br label %6
28: ; preds = %6
ret void
}

LLVM IR (-O2):
@LONG_MAX = global i32 0
define void @gen_doubles(double* nocapture writeonly %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %19, label %4
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %17, %6 ]
%8 = tail call i32 (...) @random()
%9 = load i32, i32* @LONG_MAX
%10 = sdiv i32 %9, 2
%11 = sub nsw i32 %8, %10
%12 = sitofp i32 %11 to double
%13 = add nsw i32 %10, 1
%14 = sitofp i32 %13 to double
%15 = fdiv double %12, %14
%16 = getelementptr inbounds double, double* %0, i64 %7
store double %15, double* %16
%17 = add nuw nsw i64 %7, 1
%18 = icmp eq i64 %17, %5
br i1 %18, label %19, label %6
19: ; preds = %6, %2
ret void
}