#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 /*<<< orphan*/ printf(char *);
int 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 = random();
    y = random();
    z = (x << 31) + y;
    if (z == 0) {
      exp -= 63;
    } else {
      break;
    }
  }
  while (z & mask) {
    mask <<= 1;
    exp--;
  }
  mant = z >> 11;
  b.i = (exp << 52) | mant;
  long n = b.i;
  while (n) {
    if (n & 1)
      printf("1");
    else
      printf("0");
    n >>= 1;
  }
  printf("\n");
  return b.d;
}


x86 assembly (clang, -O0):
<my_random_double2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x3ff,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    %eax,-0x4(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%eax
shl    $0x1f,%eax
add    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    116e <my_random_double2+0x4e>
mov    -0x14(%rbp),%eax
sub    $0x3f,%eax
mov    %eax,-0x14(%rbp)
jmp    1173 <my_random_double2+0x53>
jmp    1178 <my_random_double2+0x58>
jmp    1136 <my_random_double2+0x16>
jmp    117d <my_random_double2+0x5d>
mov    -0xc(%rbp),%eax
and    -0x18(%rbp),%eax
cmp    $0x0,%eax
je     11a3 <my_random_double2+0x83>
mov    -0x18(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    117d <my_random_double2+0x5d>
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)
movslq -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     120f <my_random_double2+0xef>
mov    -0x28(%rbp),%rax
and    $0x1,%rax
cmp    $0x0,%rax
je     11f2 <my_random_double2+0xd2>
lea    0xe18(%rip),%rdi
call   1030 <printf@plt>
jmp    11fe <my_random_double2+0xde>
lea    0xe09(%rip),%rdi
call   1030 <printf@plt>
mov    -0x28(%rbp),%rax
sar    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11c4 <my_random_double2+0xa4>
lea    0xdee(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
add    $0x30,%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   1040 <random@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1040 <random@plt>
shl    $0x1f,%ebx
add    %eax,%ebx
je     1130 <my_random_double2+0x10>
mov    $0x31,%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

LLVM IR (-O0):
%union.anon = type { double }
@.str = [2 x i8] c"1\00"
@.str.1 = [2 x i8] c"0\00"
@.str.2 = [2 x i8] c"\0A\00"
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
%8 = alloca i64
store i32 1023, i32* %5
store i32 1, i32* %6
br label %9
9: ; preds = %0, %22
%10 = call i32 (...) @random()
store i32 %10, i32* %1
%11 = call i32 (...) @random()
store i32 %11, i32* %2
%12 = load i32, i32* %1
%13 = shl i32 %12, 31
%14 = load i32, i32* %2
%15 = add nsw i32 %13, %14
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %9
%19 = load i32, i32* %5
%20 = sub nsw i32 %19, 63
store i32 %20, i32* %5
br label %22
21: ; preds = %9
br label %23
22: ; preds = %18
br label %9
23: ; preds = %21
br label %24
24: ; preds = %29, %23
%25 = load i32, i32* %3
%26 = load i32, i32* %6
%27 = and i32 %25, %26
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = load i32, i32* %6
%31 = shl i32 %30, 1
store i32 %31, i32* %6
%32 = load i32, i32* %5
%33 = add nsw i32 %32, -1
store i32 %33, i32* %5
br label %24
34: ; preds = %24
%35 = load i32, i32* %3
%36 = ashr i32 %35, 11
store i32 %36, i32* %4
%37 = load i32, i32* %5
%38 = shl i32 %37, 52
%39 = load i32, i32* %4
%40 = or i32 %38, %39
%41 = bitcast %union.anon* %7 to i32*
store i32 %40, i32* %41
%42 = bitcast %union.anon* %7 to i32*
%43 = load i32, i32* %42
%44 = sext i32 %43 to i64
store i64 %44, i64* %8
br label %45
45: ; preds = %56, %34
%46 = load i64, i64* %8
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %59
48: ; preds = %45
%49 = load i64, i64* %8
%50 = and i64 %49, 1
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %54
52: ; preds = %48
%53 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %56
54: ; preds = %48
%55 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %56
56: ; preds = %54, %52
%57 = load i64, i64* %8
%58 = ashr i64 %57, 1
store i64 %58, i64* %8
br label %45
59: ; preds = %45
%60 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%61 = bitcast %union.anon* %7 to double*
%62 = load double, double* %61
ret double %62
}

LLVM IR (-O2):
define double @my_random_double2() {
br label %1
1: ; preds = %1, %0
%2 = tail call i32 (...) @random()
%3 = tail call i32 (...) @random()
%4 = shl i32 %2, 31
%5 = sub i32 0, %3
%6 = icmp eq i32 %4, %5
br i1 %6, label %1, label %7
7: ; preds = %1
%8 = tail call i32 @putchar(i32 49)
%9 = tail call i32 @putchar(i32 10)
ret double poison
}