#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() {
  long x;
  long mant;
  long exp = 1022;
  int mask = 1;
  union {
    double d;
    long l;
  } b;
  while (1) {
    x = random() << 32 | random();
    if (x == 0) {
      exp -= 31;
    } else {
      break;
    }
  }
  while (x & mask) {
    mask <<= 1;
    exp--;
  }
  mant = x >> 11;
  b.l = (exp << 52) | mant;
  return b.d;
}


x86 assembly (clang, -O0):
<my_random_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x3fe,-0x18(%rbp)
movl   $0x1,-0x1c(%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    1168 <my_random_double+0x58>
mov    -0x18(%rbp),%rax
sub    $0x1f,%rax
mov    %rax,-0x18(%rbp)
jmp    116d <my_random_double+0x5d>
jmp    1172 <my_random_double+0x62>
jmp    1127 <my_random_double+0x17>
jmp    1177 <my_random_double+0x67>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
and    %rcx,%rax
cmp    $0x0,%rax
je     11a6 <my_random_double+0x96>
mov    -0x1c(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1177 <my_random_double+0x67>
mov    -0x8(%rbp),%rax
sar    $0xb,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
shl    $0x34,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movsd  -0x28(%rbp),%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 { double }
define double @my_random_double() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca %union.anon
store i64 1022, i64* %3
store i32 1, i32* %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 nsw i64 %15, 31
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 = %26, %19
%21 = load i64, i64* %1
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = and i64 %21, %23
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %20
%27 = load i32, i32* %4
%28 = shl i32 %27, 1
store i32 %28, i32* %4
%29 = load i64, i64* %3
%30 = add nsw i64 %29, -1
store i64 %30, i64* %3
br label %20
31: ; preds = %20
%32 = load i64, i64* %1
%33 = ashr i64 %32, 11
store i64 %33, i64* %2
%34 = load i64, i64* %3
%35 = shl i64 %34, 52
%36 = load i64, i64* %2
%37 = or i64 %35, %36
%38 = bitcast %union.anon* %5 to i64*
store i64 %37, i64* %38
%39 = bitcast %union.anon* %5 to double*
%40 = load double, double* %39
ret double %40
}

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