#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 narrowdoublerand() {
  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 <= 2048; i *= 2, expo = expo * expo) {
    if (c & i) {
      result *= expo;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<narrowdoublerand>:
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   $0x800,-0x30(%rbp)
jg     11d3 <narrowdoublerand+0xc3>
mov    -0x28(%rbp),%rax
and    -0x30(%rbp),%rax
cmp    $0x0,%rax
je     11ae <narrowdoublerand+0x9e>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <narrowdoublerand+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 <narrowdoublerand+0x6f>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<narrowdoublerand>:
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),%rax
mulsd  (%rax,%rcx,8),%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define double @narrowdoublerand() {
%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, 2048
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 @narrowdoublerand() {
%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
ret double %20
}