#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 /*<<< orphan*/ random_bits;

/* Variables and functions */
unsigned int random();
int random_level(void) {
  static unsigned int random_bits = 0;
  static unsigned int bits_left = 0;
  register int level;
  register int b;
  level = 1;
  do {
    if (bits_left == 0) {
      random_bits = random();
      bits_left = sizeof(random_bits);
    };
    b = random_bits & 1;
    if (!b)
      level++;
    random_bits >>= 1;
    bits_left--;
  } while (!b);
  return (level <= 32) ? level : 32;
}


x86 assembly (clang, -O0):
<random_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x1,-0x4(%rbp)
cmpl   $0x0,0x2f0a(%rip)
jne    1143 <random_level+0x33>
mov    $0x0,%al
call   1030 <random@plt>
mov    %eax,0x2ef3(%rip)
movl   $0x4,0x2eed(%rip)
mov    0x2ee3(%rip),%eax
and    $0x1,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1162 <random_level+0x52>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
mov    0x2ec4(%rip),%eax
shr    $0x1,%eax
mov    %eax,0x2ebb(%rip)
mov    0x2eb9(%rip),%eax
add    $0xffffffff,%eax
mov    %eax,0x2eb0(%rip)
cmpl   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    111f <random_level+0xf>
cmpl   $0x20,-0x4(%rbp)
jg     11a6 <random_level+0x96>
mov    -0x4(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    11b3 <random_level+0xa3>
mov    $0x20,%eax
mov    %eax,-0xc(%rbp)
jmp    11b3 <random_level+0xa3>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_level>:
push   %rbx
mov    0x2f19(%rip),%ecx
xor    %ebx,%ebx
jmp    1146 <random_level+0x36>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <random@plt>
mov    $0x4,%ecx
mov    %eax,%edx
shr    %edx
add    $0xffffffff,%ecx
add    $0x1,%ebx
mov    %edx,0x2ef0(%rip)
mov    %ecx,0x2eee(%rip)
test   $0x1,%al
jne    1152 <random_level+0x42>
test   %ecx,%ecx
je     1120 <random_level+0x10>
mov    0x2edc(%rip),%eax
jmp    112c <random_level+0x1c>
cmp    $0x20,%ebx
mov    $0x20,%eax
cmovb  %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@random_level.random_bits = internal global i32 0
@random_level.bits_left = internal global i32 0
define i32 @random_level() {
%1 = alloca i32
%2 = alloca i32
store i32 1, i32* %1
br label %3
3: ; preds = %21, %0
%4 = load i32, i32* @random_level.bits_left
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = call i32 (...) @random()
store i32 %7, i32* @random_level.random_bits
store i32 4, i32* @random_level.bits_left
br label %8
8: ; preds = %6, %3
%9 = load i32, i32* @random_level.random_bits
%10 = and i32 %9, 1
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp ne i32 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = load i32, i32* %1
%15 = add nsw i32 %14, 1
store i32 %15, i32* %1
br label %16
16: ; preds = %13, %8
%17 = load i32, i32* @random_level.random_bits
%18 = lshr i32 %17, 1
store i32 %18, i32* @random_level.random_bits
%19 = load i32, i32* @random_level.bits_left
%20 = add i32 %19, -1
store i32 %20, i32* @random_level.bits_left
br label %21
21: ; preds = %16
%22 = load i32, i32* %2
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
br i1 %24, label %3, label %25
25: ; preds = %21
%26 = load i32, i32* %1
%27 = icmp sle i32 %26, 32
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i32, i32* %1
br label %31
30: ; preds = %25
br label %31
31: ; preds = %30, %28
%32 = phi i32 [ %29, %28 ], [ 32, %30 ]
ret i32 %32
}

LLVM IR (-O2):
@random_level.random_bits = internal unnamed_addr global i32 0
@random_level.bits_left = internal unnamed_addr global i32 0
define i32 @random_level() {
%1 = load i32, i32* @random_level.bits_left
br label %2
2: ; preds = %10, %0
%3 = phi i32 [ %17, %10 ], [ %1, %0 ]
%4 = phi i32 [ %15, %10 ], [ 1, %0 ]
%5 = icmp eq i32 %3, 0
br i1 %5, label %8, label %6
6: ; preds = %2
%7 = load i32, i32* @random_level.random_bits
br label %10
8: ; preds = %2
%9 = tail call i32 (...) @random()
br label %10
10: ; preds = %6, %8
%11 = phi i32 [ %3, %6 ], [ 4, %8 ]
%12 = phi i32 [ %7, %6 ], [ %9, %8 ]
%13 = and i32 %12, 1
%14 = icmp eq i32 %13, 0
%15 = add nuw nsw i32 %4, 1
%16 = lshr i32 %12, 1
store i32 %16, i32* @random_level.random_bits
%17 = add i32 %11, -1
store i32 %17, i32* @random_level.bits_left
br i1 %14, label %2, label %18
18: ; preds = %10
%19 = icmp ult i32 %4, 32
%20 = select i1 %19, i32 %4, i32 32
ret i32 %20
}