#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 */
long rand();
double doublerand() {
  double result;
  double expo;
  long a, b, c;
  long i;
  a = rand();
  b = rand();
  c = rand();
  result = (double)(a - 1073741824) * 8388608.0 + (double)(b >> 8);
  for (i = 512, expo = 2; i <= 131072; i *= 2, expo = expo * expo) {
    if (c & i) {
      result *= expo;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<doublerand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x40000000,%rax
cvtsi2sd %rax,%xmm0
mov    -0x20(%rbp),%rax
sar    $0x8,%rax
cvtsi2sd %rax,%xmm1
movsd  0xeab(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movq   $0x200,-0x30(%rbp)
movsd  0xe86(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
cmpq   $0x20000,-0x30(%rbp)
jg     11d3 <doublerand+0xc3>
mov    -0x28(%rbp),%rax
and    -0x30(%rbp),%rax
cmp    $0x0,%rax
je     11ae <doublerand+0x9e>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <doublerand+0xa3>
mov    -0x30(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    117f <doublerand+0x6f>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<doublerand>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <rand@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <rand@plt>
add    $0xffffffffc0000000,%r14
cvtsi2sd %r14,%xmm0
sar    $0x8,%rbx
cvtsi2sd %rbx,%xmm1
mulsd  0xeb4(%rip),%xmm0
addsd  %xmm1,%xmm0
xor    %ecx,%ecx
test   $0x200,%eax
sete   %cl
lea    0xea7(%rip),%rdx
mulsd  (%rdx,%rcx,8),%xmm0
xor    %ecx,%ecx
test   $0x400,%eax
sete   %cl
lea    0xea1(%rip),%rdx
mulsd  (%rdx,%rcx,8),%xmm0
xor    %ecx,%ecx
test   $0x800,%eax
sete   %cl
lea    0xe9b(%rip),%rdx
mulsd  (%rdx,%rcx,8),%xmm0
xor    %ecx,%ecx
test   $0x1000,%eax
sete   %cl
lea    0xe95(%rip),%rdx
mulsd  (%rdx,%rcx,8),%xmm0
xor    %ecx,%ecx
test   $0x2000,%eax
sete   %cl
lea    0xe8f(%rip),%rdx
mulsd  (%rdx,%rcx,8),%xmm0
xor    %ecx,%ecx
test   $0x4000,%eax
sete   %cl
lea    0xe89(%rip),%rdx
mulsd  (%rdx,%rcx,8),%xmm0
xor    %ecx,%ecx
test   $0x8000,%eax
sete   %cl
lea    0xe83(%rip),%rdx
mulsd  (%rdx,%rcx,8),%xmm0
xor    %ecx,%ecx
test   $0x10000,%eax
sete   %cl
lea    0xe7d(%rip),%rdx
mulsd  (%rdx,%rcx,8),%xmm0
xor    %ecx,%ecx
test   $0x20000,%eax
sete   %cl
lea    0xe77(%rip),%rax
mulsd  (%rax,%rcx,8),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @doublerand() {
%1 = alloca double
%2 = alloca double
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = call i64 (...) @rand()
store i64 %7, i64* %3
%8 = call i64 (...) @rand()
store i64 %8, i64* %4
%9 = call i64 (...) @rand()
store i64 %9, i64* %5
%10 = load i64, i64* %3
%11 = sub nsw i64 %10, 1073741824
%12 = sitofp i64 %11 to double
%13 = load i64, i64* %4
%14 = ashr i64 %13, 8
%15 = sitofp i64 %14 to double
%16 = call double @llvm.fmuladd.f64(double %12, double 0x4160000000000000, double %15)
store double %16, double* %1
store i64 512, i64* %6
store double 2.000000e+00, double* %2
br label %17
17: ; preds = %30, %0
%18 = load i64, i64* %6
%19 = icmp sle i64 %18, 131072
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load i64, i64* %5
%22 = load i64, i64* %6
%23 = and i64 %21, %22
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load double, double* %2
%27 = load double, double* %1
%28 = fmul double %27, %26
store double %28, double* %1
br label %29
29: ; preds = %25, %20
br label %30
30: ; preds = %29
%31 = load i64, i64* %6
%32 = mul nsw i64 %31, 2
store i64 %32, i64* %6
%33 = load double, double* %2
%34 = load double, double* %2
%35 = fmul double %33, %34
store double %35, double* %2
br label %17
36: ; preds = %17
%37 = load double, double* %1
ret double %37
}

LLVM IR (-O2):
define double @doublerand() {
%1 = tail call i64 (...) @rand()
%2 = tail call i64 (...) @rand()
%3 = tail call i64 (...) @rand()
%4 = add nsw i64 %1, -1073741824
%5 = sitofp i64 %4 to double
%6 = ashr i64 %2, 8
%7 = sitofp i64 %6 to double
%8 = tail call double @llvm.fmuladd.f64(double %5, double 0x4160000000000000, double %7)
%9 = and i64 %3, 512
%10 = icmp eq i64 %9, 0
%11 = select i1 %10, double 1.000000e+00, double 2.000000e+00
%12 = fmul double %8, %11
%13 = and i64 %3, 1024
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, double 1.000000e+00, double 4.000000e+00
%16 = fmul double %12, %15
%17 = and i64 %3, 2048
%18 = icmp eq i64 %17, 0
%19 = select i1 %18, double 1.000000e+00, double 1.600000e+01
%20 = fmul double %16, %19
%21 = and i64 %3, 4096
%22 = icmp eq i64 %21, 0
%23 = select i1 %22, double 1.000000e+00, double 2.560000e+02
%24 = fmul double %20, %23
%25 = and i64 %3, 8192
%26 = icmp eq i64 %25, 0
%27 = select i1 %26, double 1.000000e+00, double 6.553600e+04
%28 = fmul double %24, %27
%29 = and i64 %3, 16384
%30 = icmp eq i64 %29, 0
%31 = select i1 %30, double 1.000000e+00, double 0x41F0000000000000
%32 = fmul double %28, %31
%33 = and i64 %3, 32768
%34 = icmp eq i64 %33, 0
%35 = select i1 %34, double 1.000000e+00, double 0x43F0000000000000
%36 = fmul double %32, %35
%37 = and i64 %3, 65536
%38 = icmp eq i64 %37, 0
%39 = select i1 %38, double 1.000000e+00, double 0x47F0000000000000
%40 = fmul double %36, %39
%41 = and i64 %3, 131072
%42 = icmp eq i64 %41, 0
%43 = select i1 %42, double 1.000000e+00, double 0x4FF0000000000000
%44 = fmul double %40, %43
ret double %44
}