#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 DBL_EPSILON;
int INT_MAX;
int random();
double drand2() {
  double x, y;
  double maxran, maxran1;
  static double eps = -1.0;
  if (eps < 0.0) {
    maxran = 1.0 - DBL_EPSILON;
    maxran1 = (double)(INT_MAX - 1) / (double)INT_MAX;
    eps = maxran - maxran1;
  }
  x = ((double)(random() % INT_MAX) / (double)(INT_MAX));
  y = ((double)(random() % INT_MAX) / (double)(INT_MAX));
  return x + y * eps;
}


x86 assembly (clang, -O0):
<drand2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
xorps  %xmm0,%xmm0
ucomisd 0x2f05(%rip),%xmm0
jbe    1177 <drand2+0x67>
movsd  0xecf(%rip),%xmm0
mov    0x2eb0(%rip),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    0x2e98(%rip),%rax
mov    (%rax),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
mov    0x2e88(%rip),%rax
cvtsi2sdl (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,0x2eb1(%rip)
mov    $0x0,%al
call   1030 <random@plt>
mov    0x2e5b(%rip),%rcx
cltd
idivl  (%rcx)
cvtsi2sd %edx,%xmm0
mov    0x2e4d(%rip),%rax
cvtsi2sdl (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    0x2e32(%rip),%rcx
cltd
idivl  (%rcx)
cvtsi2sd %edx,%xmm0
mov    0x2e24(%rip),%rax
cvtsi2sdl (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  0x2e4d(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<drand2>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm0,%xmm0
ucomisd 0x2f07(%rip),%xmm0
jbe    115a <drand2+0x4a>
mov    0x2ebe(%rip),%rax
movsd  0xece(%rip),%xmm0
subsd  (%rax),%xmm0
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
lea    -0x1(%rax),%ecx
cvtsi2sd %ecx,%xmm1
cvtsi2sd %eax,%xmm2
divsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,0x2ece(%rip)
xor    %eax,%eax
call   1030 <random@plt>
mov    0x2e78(%rip),%rbx
mov    (%rbx),%ecx
cltd
idiv   %ecx
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
call   1030 <random@plt>
mov    (%rbx),%ecx
cltd
idiv   %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %edx,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %ecx,%xmm1
divsd  %xmm1,%xmm0
mulsd  0x2e7d(%rip),%xmm0
addsd  0x8(%rsp),%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@drand2.eps = internal global double -1.000000e+00
@DBL_EPSILON = global double 0.000000e+00
@INT_MAX = global i32 0
define double @drand2() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = load double, double* @drand2.eps
%6 = fcmp olt double %5, 0.000000e+00
br i1 %6, label %7, label %19
7: ; preds = %0
%8 = load double, double* @DBL_EPSILON
%9 = fsub double 1.000000e+00, %8
store double %9, double* %3
%10 = load i32, i32* @INT_MAX
%11 = sub nsw i32 %10, 1
%12 = sitofp i32 %11 to double
%13 = load i32, i32* @INT_MAX
%14 = sitofp i32 %13 to double
%15 = fdiv double %12, %14
store double %15, double* %4
%16 = load double, double* %3
%17 = load double, double* %4
%18 = fsub double %16, %17
store double %18, double* @drand2.eps
br label %19
19: ; preds = %7, %0
%20 = call i32 (...) @random()
%21 = load i32, i32* @INT_MAX
%22 = srem i32 %20, %21
%23 = sitofp i32 %22 to double
%24 = load i32, i32* @INT_MAX
%25 = sitofp i32 %24 to double
%26 = fdiv double %23, %25
store double %26, double* %1
%27 = call i32 (...) @random()
%28 = load i32, i32* @INT_MAX
%29 = srem i32 %27, %28
%30 = sitofp i32 %29 to double
%31 = load i32, i32* @INT_MAX
%32 = sitofp i32 %31 to double
%33 = fdiv double %30, %32
store double %33, double* %2
%34 = load double, double* %1
%35 = load double, double* %2
%36 = load double, double* @drand2.eps
%37 = call double @llvm.fmuladd.f64(double %35, double %36, double %34)
ret double %37
}

LLVM IR (-O2):
@drand2.eps = internal unnamed_addr global double -1.000000e+00
@DBL_EPSILON = global double 0.000000e+00
@INT_MAX = global i32 0
define double @drand2() {
%1 = load double, double* @drand2.eps
%2 = fcmp olt double %1, 0.000000e+00
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = load double, double* @DBL_EPSILON
%5 = fsub double 1.000000e+00, %4
%6 = load i32, i32* @INT_MAX
%7 = add nsw i32 %6, -1
%8 = sitofp i32 %7 to double
%9 = sitofp i32 %6 to double
%10 = fdiv double %8, %9
%11 = fsub double %5, %10
store double %11, double* @drand2.eps
br label %12
12: ; preds = %3, %0
%13 = tail call i32 (...) @random()
%14 = load i32, i32* @INT_MAX
%15 = srem i32 %13, %14
%16 = sitofp i32 %15 to double
%17 = sitofp i32 %14 to double
%18 = fdiv double %16, %17
%19 = tail call i32 (...) @random()
%20 = load i32, i32* @INT_MAX
%21 = srem i32 %19, %20
%22 = sitofp i32 %21 to double
%23 = sitofp i32 %20 to double
%24 = fdiv double %22, %23
%25 = load double, double* @drand2.eps
%26 = tail call double @llvm.fmuladd.f64(double %24, double %25, double %18)
ret double %26
}