#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 */
int random();
double my_random_double() {
  unsigned long x;
  unsigned long mant;
  unsigned long exp = 1022;
  unsigned long mask = 1;
  union {
    float f;
    unsigned long i;
  } b;
  while (1) {
    x = (random() << 32) | random();
    if (x == 0) {
      exp -= 62;
    } else {
      break;
    }
  }
  while (x & mask) {
    mask <<= 1;
    exp--;
  }
  mant = x >> 11;
  b.i = (exp << 52) | mant;
  return b.f;
}


x86 assembly (clang, -O0):
<my_random_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x3fe,-0x18(%rbp)
movq   $0x1,-0x20(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    $0x20,%ecx
shl    %cl,%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
or     %ecx,%eax
cltq
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1169 <my_random_double+0x59>
mov    -0x18(%rbp),%rax
sub    $0x3e,%rax
mov    %rax,-0x18(%rbp)
jmp    116e <my_random_double+0x5e>
jmp    1173 <my_random_double+0x63>
jmp    1128 <my_random_double+0x18>
jmp    1178 <my_random_double+0x68>
mov    -0x8(%rbp),%rax
and    -0x20(%rbp),%rax
cmp    $0x0,%rax
je     11a7 <my_random_double+0x97>
mov    -0x20(%rbp),%rax
shl    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1178 <my_random_double+0x68>
mov    -0x8(%rbp),%rax
shr    $0xb,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x34,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_random_double>:
push   %rax
xor    %eax,%eax
call   1030 <random@plt>
xor    %eax,%eax
pop    %rcx
jmp    1030 <random@plt>

LLVM IR (-O0):
%union.anon = type { i64 }
define double @my_random_double() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca %union.anon
store i64 1022, i64* %3
store i64 1, i64* %4
br label %6
6: ; preds = %0, %18
%7 = call i32 (...) @random()
%8 = shl i32 %7, 32
%9 = call i32 (...) @random()
%10 = or i32 %8, %9
%11 = sext i32 %10 to i64
store i64 %11, i64* %1
%12 = load i64, i64* %1
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = load i64, i64* %3
%16 = sub i64 %15, 62
store i64 %16, i64* %3
br label %18
17: ; preds = %6
br label %19
18: ; preds = %14
br label %6
19: ; preds = %17
br label %20
20: ; preds = %25, %19
%21 = load i64, i64* %1
%22 = load i64, i64* %4
%23 = and i64 %21, %22
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i64, i64* %4
%27 = shl i64 %26, 1
store i64 %27, i64* %4
%28 = load i64, i64* %3
%29 = add i64 %28, -1
store i64 %29, i64* %3
br label %20
30: ; preds = %20
%31 = load i64, i64* %1
%32 = lshr i64 %31, 11
store i64 %32, i64* %2
%33 = load i64, i64* %3
%34 = shl i64 %33, 52
%35 = load i64, i64* %2
%36 = or i64 %34, %35
%37 = bitcast %union.anon* %5 to i64*
store i64 %36, i64* %37
%38 = bitcast %union.anon* %5 to float*
%39 = load float, float* %38
%40 = fpext float %39 to double
ret double %40
}

LLVM IR (-O2):
define double @my_random_double() {
%1 = tail call i32 (...) @random()
%2 = tail call i32 (...) @random()
ret double poison
}