#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 */
scalar_t__ UINT_MAX;
double urand();
double xrand(void) {
  double x;
  do {
    x = urand() * (1.0 / ((double)UINT_MAX + 1.0)) +
        urand() * ((1.0 / ((double)UINT_MAX + 1.0)) *
                   (1.0 / ((double)UINT_MAX + 1.0)));
  } while (x >= 1);
  return x;
}


x86 assembly (clang, -O0):
<xrand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <urand@plt>
movsd  %xmm0,-0x10(%rbp)
mov    0x2ebd(%rip),%rax
cvtsi2sdq (%rax),%xmm1
movsd  0xec8(%rip),%xmm0
addsd  %xmm0,%xmm1
movsd  0xebc(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1030 <urand@plt>
movsd  -0x18(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x10(%rbp),%xmm0
mov    0x2e80(%rip),%rax
cvtsi2sdq (%rax),%xmm4
movsd  0xe8b(%rip),%xmm3
addsd  %xmm3,%xmm4
movsd  0xe7f(%rip),%xmm3
divsd  %xmm4,%xmm3
mov    0x2e5c(%rip),%rax
cvtsi2sdq (%rax),%xmm5
movsd  0xe67(%rip),%xmm4
addsd  %xmm4,%xmm5
movsd  0xe5b(%rip),%xmm4
divsd  %xmm5,%xmm4
mulsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe35(%rip),%xmm1
ucomisd %xmm1,%xmm0
jae    1118 <xrand+0x8>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xrand>:
push   %rbx
sub    $0x10,%rsp
mov    0x2ecc(%rip),%rbx
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <urand@plt>
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sdq (%rbx),%xmm0
movsd  0xec3(%rip),%xmm1
addsd  %xmm1,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1030 <urand@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq (%rbx),%xmm1
movsd  0xe9f(%rip),%xmm3
addsd  %xmm3,%xmm1
movapd %xmm3,%xmm2
divsd  %xmm1,%xmm2
mulsd  %xmm2,%xmm2
mulsd  %xmm0,%xmm2
movsd  (%rsp),%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm3,%xmm0
jae    1120 <xrand+0x10>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@UINT_MAX = global i64 0
define double @xrand() {
%1 = alloca double
br label %2
2: ; preds = %20, %0
%3 = call double (...) @urand()
%4 = load i64, i64* @UINT_MAX
%5 = sitofp i64 %4 to double
%6 = fadd double %5, 1.000000e+00
%7 = fdiv double 1.000000e+00, %6
%8 = call double (...) @urand()
%9 = load i64, i64* @UINT_MAX
%10 = sitofp i64 %9 to double
%11 = fadd double %10, 1.000000e+00
%12 = fdiv double 1.000000e+00, %11
%13 = load i64, i64* @UINT_MAX
%14 = sitofp i64 %13 to double
%15 = fadd double %14, 1.000000e+00
%16 = fdiv double 1.000000e+00, %15
%17 = fmul double %12, %16
%18 = fmul double %8, %17
%19 = call double @llvm.fmuladd.f64(double %3, double %7, double %18)
store double %19, double* %1
br label %20
20: ; preds = %2
%21 = load double, double* %1
%22 = fcmp oge double %21, 1.000000e+00
br i1 %22, label %2, label %23
23: ; preds = %20
%24 = load double, double* %1
ret double %24
}

LLVM IR (-O2):
@UINT_MAX = global i64 0
define double @xrand() {
br label %1
1: ; preds = %1, %0
%2 = tail call double (...) @urand()
%3 = load i64, i64* @UINT_MAX
%4 = sitofp i64 %3 to double
%5 = fadd double %4, 1.000000e+00
%6 = fdiv double 1.000000e+00, %5
%7 = tail call double (...) @urand()
%8 = load i64, i64* @UINT_MAX
%9 = sitofp i64 %8 to double
%10 = fadd double %9, 1.000000e+00
%11 = fdiv double 1.000000e+00, %10
%12 = fmul double %11, %11
%13 = fmul double %7, %12
%14 = tail call double @llvm.fmuladd.f64(double %2, double %6, double %13)
%15 = fcmp ult double %14, 1.000000e+00
br i1 %15, label %16, label %1
16: ; preds = %1
ret double %14
}