#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 maxrand(int);
double rand() {
  double rst = 0;
  int count = 4;
  while (count-- > 0) {
    rst = (rst + maxrand(10)) / 10.0;
  }
  return rst > 1 ? 1 : rst;
}


x86 assembly (clang, -O0):
<rand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movl   $0x4,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    1171 <rand+0x61>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0xa,%edi
call   1030 <maxrand@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
addsd  %xmm1,%xmm0
movsd  0xea5(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1127 <rand+0x17>
movsd  -0x8(%rbp),%xmm0
movsd  0xe82(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    119a <rand+0x8a>
movsd  0xe70(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11a4 <rand+0x94>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand>:
push   %rax
mov    $0xa,%edi
call   1030 <maxrand@plt>
xorpd  %xmm1,%xmm1
addsd  %xmm0,%xmm1
divsd  0xed5(%rip),%xmm1
movsd  %xmm1,(%rsp)
mov    $0xa,%edi
call   1030 <maxrand@plt>
addsd  (%rsp),%xmm0
divsd  0xeb9(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    $0xa,%edi
call   1030 <maxrand@plt>
addsd  (%rsp),%xmm0
divsd  0xe9d(%rip),%xmm0
movsd  %xmm0,(%rsp)
mov    $0xa,%edi
call   1030 <maxrand@plt>
addsd  (%rsp),%xmm0
divsd  0xe81(%rip),%xmm0
movsd  0xe81(%rip),%xmm1
minsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @rand() {
%1 = alloca double
%2 = alloca i32
store double 0.000000e+00, double* %1
store i32 4, i32* %2
br label %3
3: ; preds = %7, %0
%4 = load i32, i32* %2
%5 = add nsw i32 %4, -1
store i32 %5, i32* %2
%6 = icmp sgt i32 %4, 0
br i1 %6, label %7, label %12
7: ; preds = %3
%8 = load double, double* %1
%9 = call double @maxrand(i32 10)
%10 = fadd double %8, %9
%11 = fdiv double %10, 1.000000e+01
store double %11, double* %1
br label %3
12: ; preds = %3
%13 = load double, double* %1
%14 = fcmp ogt double %13, 1.000000e+00
br i1 %14, label %15, label %16
15: ; preds = %12
br label %18
16: ; preds = %12
%17 = load double, double* %1
br label %18
18: ; preds = %16, %15
%19 = phi double [ 1.000000e+00, %15 ], [ %17, %16 ]
ret double %19
}

LLVM IR (-O2):
define double @rand() {
%1 = tail call double @maxrand(i32 10)
%2 = fadd double %1, 0.000000e+00
%3 = fdiv double %2, 1.000000e+01
%4 = tail call double @maxrand(i32 10)
%5 = fadd double %3, %4
%6 = fdiv double %5, 1.000000e+01
%7 = tail call double @maxrand(i32 10)
%8 = fadd double %6, %7
%9 = fdiv double %8, 1.000000e+01
%10 = tail call double @maxrand(i32 10)
%11 = fadd double %9, %10
%12 = fdiv double %11, 1.000000e+01
%13 = fcmp ogt double %12, 1.000000e+00
%14 = select i1 %13, double 1.000000e+00, double %12
ret double %14
}