#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 /*<<< orphan*/ printf(char *, int);
int random();
float my_random_float2() {
  int x;
  int mant;
  int exp = 126;
  int mask = 1;
  union {
    float f;
    int i;
  } b;
  while (1) {
    x = random();
    if (x == 0) {
      exp -= 31;
    } else {
      break;
    }
  }
  while (x & mask) {
    mask <<= 1;
    exp--;
    printf("  exp: %d\n", exp);
  }
  mant = x >> 8;
  b.i = (exp << 23) | mant;
  return b.f;
}


x86 assembly (clang, -O0):
<my_random_float2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x7e,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    $0x0,%al
call   1040 <random@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jne    1158 <my_random_float2+0x38>
mov    -0xc(%rbp),%eax
sub    $0x1f,%eax
mov    %eax,-0xc(%rbp)
jmp    115d <my_random_float2+0x3d>
jmp    1162 <my_random_float2+0x42>
jmp    1136 <my_random_float2+0x16>
jmp    1167 <my_random_float2+0x47>
mov    -0x4(%rbp),%eax
and    -0x10(%rbp),%eax
cmp    $0x0,%eax
je     119c <my_random_float2+0x7c>
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe6e(%rip),%rdi
call   1030 <printf@plt>
jmp    1167 <my_random_float2+0x47>
mov    -0x4(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x17,%eax
or     -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<my_random_float2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x9d,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <random@plt>
add    $0xffffffe1,%ebx
test   %eax,%eax
je     1130 <my_random_float2+0x10>
mov    %eax,%r15d
test   $0x1,%r15b
je     1174 <my_random_float2+0x54>
mov    $0x1,%ebp
lea    0xead(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %ebp,%ebp
add    $0xffffffff,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
test   %r15d,%ebp
jne    1160 <my_random_float2+0x40>
sar    $0x8,%r15d
shl    $0x17,%ebx
or     %r15d,%ebx
movd   %ebx,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%union.anon = type { float }
@.str = [11 x i8] c" exp: %d\0A\00"
define float @my_random_float2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %union.anon
store i32 126, i32* %3
store i32 1, i32* %4
br label %6
6: ; preds = %0, %14
%7 = call i32 (...) @random()
store i32 %7, i32* %1
%8 = load i32, i32* %1
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* %3
%12 = sub nsw i32 %11, 31
store i32 %12, i32* %3
br label %14
13: ; preds = %6
br label %15
14: ; preds = %10
br label %6
15: ; preds = %13
br label %16
16: ; preds = %21, %15
%17 = load i32, i32* %1
%18 = load i32, i32* %4
%19 = and i32 %17, %18
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %16
%22 = load i32, i32* %4
%23 = shl i32 %22, 1
store i32 %23, i32* %4
%24 = load i32, i32* %3
%25 = add nsw i32 %24, -1
store i32 %25, i32* %3
%26 = load i32, i32* %3
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %26)
br label %16
28: ; preds = %16
%29 = load i32, i32* %1
%30 = ashr i32 %29, 8
store i32 %30, i32* %2
%31 = load i32, i32* %3
%32 = shl i32 %31, 23
%33 = load i32, i32* %2
%34 = or i32 %32, %33
%35 = bitcast %union.anon* %5 to i32*
store i32 %34, i32* %35
%36 = bitcast %union.anon* %5 to float*
%37 = load float, float* %36
ret float %37
}

LLVM IR (-O2):
@.str = [11 x i8] c" exp: %d\0A\00"
define float @my_random_float2() {
br label %1
1: ; preds = %1, %0
%2 = phi i32 [ 126, %0 ], [ %5, %1 ]
%3 = tail call i32 (...) @random()
%4 = icmp eq i32 %3, 0
%5 = add nsw i32 %2, -31
br i1 %4, label %1, label %6
6: ; preds = %1
%7 = and i32 %3, 1
%8 = icmp eq i32 %7, 0
br i1 %8, label %17, label %9
9: ; preds = %6, %9
%10 = phi i32 [ %13, %9 ], [ %2, %6 ]
%11 = phi i32 [ %12, %9 ], [ 1, %6 ]
%12 = shl i32 %11, 1
%13 = add nsw i32 %10, -1
%14 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = and i32 %12, %3
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %9
17: ; preds = %9, %6
%18 = phi i32 [ %2, %6 ], [ %13, %9 ]
%19 = ashr i32 %3, 8
%20 = shl i32 %18, 23
%21 = or i32 %20, %19
%22 = bitcast i32 %21 to float
ret float %22
}