#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 rand();
double double_rand() {
  double result = 0;
  for (int i = 0; i < 20; i++)
    result += (double)(rand() % 1000) / 400;
  return (double)((int)(result * 100)) / 100;
}


x86 assembly (clang, -O0):
<double_rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x14,-0xc(%rbp)
jge    1168 <double_rand+0x58>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cvtsi2sd %edx,%xmm0
movsd  0xebc(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1127 <double_rand+0x17>
movsd  0xe90(%rip),%xmm0
mulsd  -0x8(%rbp),%xmm0
cvttsd2si %xmm0,%eax
cvtsi2sd %eax,%xmm0
movsd  0xe7b(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<double_rand>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm0,%xmm0
mov    $0x14,%ebx
xchg   %ax,%ax
movapd %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <rand@plt>
cltq
imul   $0x10624dd3,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
imul   $0x3e8,%ecx,%ecx
sub    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  0xea7(%rip),%xmm0
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movapd (%rsp),%xmm0
add    $0xffffffff,%ebx
jne    1120 <double_rand+0x10>
movsd  0xe8f(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm0
divsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @double_rand() {
%1 = alloca double
%2 = alloca i32
store double 0.000000e+00, double* %1
store i32 0, i32* %2
br label %3
3: ; preds = %13, %0
%4 = load i32, i32* %2
%5 = icmp slt i32 %4, 20
br i1 %5, label %6, label %16
6: ; preds = %3
%7 = call i32 (...) @rand()
%8 = srem i32 %7, 1000
%9 = sitofp i32 %8 to double
%10 = fdiv double %9, 4.000000e+02
%11 = load double, double* %1
%12 = fadd double %11, %10
store double %12, double* %1
br label %13
13: ; preds = %6
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
br label %3
16: ; preds = %3
%17 = load double, double* %1
%18 = fmul double %17, 1.000000e+02
%19 = fptosi double %18 to i32
%20 = sitofp i32 %19 to double
%21 = fdiv double %20, 1.000000e+02
ret double %21
}

LLVM IR (-O2):
define double @double_rand() {
br label %6
1: ; preds = %6
%2 = fmul double %13, 1.000000e+02
%3 = fptosi double %2 to i32
%4 = sitofp i32 %3 to double
%5 = fdiv double %4, 1.000000e+02
ret double %5
6: ; preds = %0, %6
%7 = phi i32 [ 0, %0 ], [ %14, %6 ]
%8 = phi double [ 0.000000e+00, %0 ], [ %13, %6 ]
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 1000
%11 = sitofp i32 %10 to double
%12 = fdiv double %11, 4.000000e+02
%13 = fadd double %8, %12
%14 = add nuw nsw i32 %7, 1
%15 = icmp eq i32 %14, 20
br i1 %15, label %1, label %6
}