#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 */
scalar_t__ random();
double my_random_double2() {
  uint64_t x;
  uint64_t y;
  uint64_t z;
  uint64_t mant;
  uint64_t exp = 1023;
  uint64_t mask = 1;
  union {
    double d;
    uint64_t i;
  } b;
  while (1) {
    x = (uint64_t)random();
    y = (uint64_t)random();
    z = y << 32 | x;
    if (x == 0 || y == 0) {
      exp -= 63;
    } else {
      break;
    }
  }
  while (z & mask) {
    mask <<= 1;
    exp--;
  }
  mant = z >> 11;
  b.i = (exp << 52) | mant;
  return b.d / 2.0;
}


x86 assembly (clang, -O0):
<my_random_double2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x3ff,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x20,%ecx
shl    %cl,%eax
or     -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     115e <my_random_double2+0x4e>
cmpl   $0x0,-0x8(%rbp)
jne    116c <my_random_double2+0x5c>
mov    -0x14(%rbp),%eax
sub    $0x3f,%eax
mov    %eax,-0x14(%rbp)
jmp    1171 <my_random_double2+0x61>
jmp    1176 <my_random_double2+0x66>
jmp    1126 <my_random_double2+0x16>
jmp    117b <my_random_double2+0x6b>
mov    -0xc(%rbp),%eax
and    -0x18(%rbp),%eax
cmp    $0x0,%eax
je     11a1 <my_random_double2+0x91>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    117b <my_random_double2+0x6b>
mov    -0xc(%rbp),%eax
sar    $0xb,%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x34,%ecx
shl    %cl,%eax
or     -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe39(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_random_double2>:
push   %rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <random@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <random@plt>
test   %ebx,%ebx
je     1120 <my_random_double2+0x10>
test   %eax,%eax
je     1120 <my_random_double2+0x10>
pop    %rbx
ret

LLVM IR (-O0):
%union.anon = type { double }
define double @my_random_double2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca %union.anon
store i32 1023, i32* %5
store i32 1, i32* %6
br label %8
8: ; preds = %0, %26
%9 = call i64 (...) @random()
%10 = trunc i64 %9 to i32
store i32 %10, i32* %1
%11 = call i64 (...) @random()
%12 = trunc i64 %11 to i32
store i32 %12, i32* %2
%13 = load i32, i32* %2
%14 = shl i32 %13, 32
%15 = load i32, i32* %1
%16 = or i32 %14, %15
store i32 %16, i32* %3
%17 = load i32, i32* %1
%18 = icmp eq i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %8
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19, %8
%23 = load i32, i32* %5
%24 = sub nsw i32 %23, 63
store i32 %24, i32* %5
br label %26
25: ; preds = %19
br label %27
26: ; preds = %22
br label %8
27: ; preds = %25
br label %28
28: ; preds = %33, %27
%29 = load i32, i32* %3
%30 = load i32, i32* %6
%31 = and i32 %29, %30
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %28
%34 = load i32, i32* %6
%35 = shl i32 %34, 1
store i32 %35, i32* %6
%36 = load i32, i32* %5
%37 = add nsw i32 %36, -1
store i32 %37, i32* %5
br label %28
38: ; preds = %28
%39 = load i32, i32* %3
%40 = ashr i32 %39, 11
store i32 %40, i32* %4
%41 = load i32, i32* %5
%42 = shl i32 %41, 52
%43 = load i32, i32* %4
%44 = or i32 %42, %43
%45 = bitcast %union.anon* %7 to i32*
store i32 %44, i32* %45
%46 = bitcast %union.anon* %7 to double*
%47 = load double, double* %46
%48 = fdiv double %47, 2.000000e+00
ret double %48
}

LLVM IR (-O2):
define double @my_random_double2() {
br label %1
1: ; preds = %1, %0
%2 = tail call i64 (...) @random()
%3 = trunc i64 %2 to i32
%4 = tail call i64 (...) @random()
%5 = trunc i64 %4 to i32
%6 = icmp eq i32 %3, 0
%7 = icmp eq i32 %5, 0
%8 = select i1 %6, i1 true, i1 %7
br i1 %8, label %1, label %9
9: ; preds = %1
ret double poison
}