#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 */
typedef int uint64_t;

/* Variables and functions */
int random();
double my_random_double() {
  uint64_t x;
  uint64_t mant;
  uint64_t exp = 1022;
  uint64_t mask = 1;
  union {
    double d;
    uint64_t i;
  } b;
  while (1) {
    x = (random() << 32) | random();
    if (x == 0) {
      exp -= 63;
    } else {
      break;
    }
  }
  while (x & mask) {
    mask <<= 1;
    exp--;
  }
  mant = x >> 11;
  b.i = (exp << 52) | mant;
  return b.d;
}


x86 assembly (clang, -O0):
<my_random_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x3fe,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    $0x20,%ecx
shl    %cl,%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    %eax,%ecx
mov    -0x1c(%rbp),%eax
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1160 <my_random_double+0x50>
mov    -0xc(%rbp),%eax
sub    $0x3f,%eax
mov    %eax,-0xc(%rbp)
jmp    1165 <my_random_double+0x55>
jmp    116a <my_random_double+0x5a>
jmp    1126 <my_random_double+0x16>
jmp    116f <my_random_double+0x5f>
mov    -0x4(%rbp),%eax
and    -0x10(%rbp),%eax
cmp    $0x0,%eax
je     1195 <my_random_double+0x85>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    116f <my_random_double+0x5f>
mov    -0x4(%rbp),%eax
sar    $0xb,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x34,%ecx
shl    %cl,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x20,%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 { double }
define double @my_random_double() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %union.anon
store i32 1022, i32* %3
store i32 1, i32* %4
br label %6
6: ; preds = %0, %17
%7 = call i32 (...) @random()
%8 = shl i32 %7, 32
%9 = call i32 (...) @random()
%10 = or i32 %8, %9
store i32 %10, i32* %1
%11 = load i32, i32* %1
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = load i32, i32* %3
%15 = sub nsw i32 %14, 63
store i32 %15, i32* %3
br label %17
16: ; preds = %6
br label %18
17: ; preds = %13
br label %6
18: ; preds = %16
br label %19
19: ; preds = %24, %18
%20 = load i32, i32* %1
%21 = load i32, i32* %4
%22 = and i32 %20, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %19
%25 = load i32, i32* %4
%26 = shl i32 %25, 1
store i32 %26, i32* %4
%27 = load i32, i32* %3
%28 = add nsw i32 %27, -1
store i32 %28, i32* %3
br label %19
29: ; preds = %19
%30 = load i32, i32* %1
%31 = ashr i32 %30, 11
store i32 %31, i32* %2
%32 = load i32, i32* %3
%33 = shl i32 %32, 52
%34 = load i32, i32* %2
%35 = or i32 %33, %34
%36 = bitcast %union.anon* %5 to i32*
store i32 %35, i32* %36
%37 = bitcast %union.anon* %5 to double*
%38 = load double, double* %37
ret double %38
}

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