#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 RAND_MAX;
int rand();
int randomHeight() {
  int r = rand();
  int pivot = (RAND_MAX / 2) + 1;
  int height = 1;
  while (r < pivot && height < 16) {
    height++;
    pivot /= 2;
  }
  return height;
}


x86 assembly (clang, -O0):
<randomHeight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1030 <rand@plt>
mov    %eax,-0x4(%rbp)
mov    0x2ebf(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
mov    -0x4(%rbp),%ecx
xor    %eax,%eax
cmp    -0x8(%rbp),%ecx
mov    %al,-0xd(%rbp)
jge    115b <randomHeight+0x4b>
cmpl   $0x10,-0xc(%rbp)
setl   %al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%al
test   $0x1,%al
jne    116b <randomHeight+0x5b>
jmp    1187 <randomHeight+0x77>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x8(%rbp)
jmp    1140 <randomHeight+0x30>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomHeight>:
push   %rax
xor    %eax,%eax
call   1030 <rand@plt>
mov    0x2ec9(%rip),%rcx
mov    (%rcx),%ecx
mov    %ecx,%edx
shr    $0x1f,%edx
add    %ecx,%edx
sar    %edx
mov    $0x1,%ecx
cmp    %edx,%eax
jg     1157 <randomHeight+0x47>
add    $0x1,%edx
mov    $0x1,%esi
nopl   0x0(%rax,%rax,1)
lea    0x1(%rsi),%ecx
mov    %edx,%edi
shr    $0x1f,%edi
add    %edi,%edx
sar    %edx
cmp    %edx,%eax
jge    1157 <randomHeight+0x47>
cmp    $0xf,%esi
mov    %ecx,%esi
jb     1140 <randomHeight+0x30>
mov    %ecx,%eax
pop    %rcx
ret

LLVM IR (-O0):
@RAND_MAX = global i32 0
define i32 @randomHeight() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = call i32 (...) @rand()
store i32 %4, i32* %1
%5 = load i32, i32* @RAND_MAX
%6 = sdiv i32 %5, 2
%7 = add nsw i32 %6, 1
store i32 %7, i32* %2
store i32 1, i32* %3
br label %8
8: ; preds = %17, %0
%9 = load i32, i32* %1
%10 = load i32, i32* %2
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 16
br label %15
15: ; preds = %12, %8
%16 = phi i1 [ false, %8 ], [ %14, %12 ]
br i1 %16, label %17, label %22
17: ; preds = %15
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
store i32 %19, i32* %3
%20 = load i32, i32* %2
%21 = sdiv i32 %20, 2
store i32 %21, i32* %2
br label %8
22: ; preds = %15
%23 = load i32, i32* %3
ret i32 %23
}

LLVM IR (-O2):
@RAND_MAX = global i32 0
define i32 @randomHeight() {
%1 = tail call i32 (...) @rand()
%2 = load i32, i32* @RAND_MAX
%3 = sdiv i32 %2, 2
%4 = icmp sgt i32 %1, %3
br i1 %4, label %15, label %5
5: ; preds = %0
%6 = add nsw i32 %3, 1
br label %7
7: ; preds = %5, %7
%8 = phi i32 [ %10, %7 ], [ 1, %5 ]
%9 = phi i32 [ %11, %7 ], [ %6, %5 ]
%10 = add nuw nsw i32 %8, 1
%11 = sdiv i32 %9, 2
%12 = icmp slt i32 %1, %11
%13 = icmp ult i32 %8, 15
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %7, label %15
15: ; preds = %7, %0
%16 = phi i32 [ 1, %0 ], [ %10, %7 ]
ret i32 %16
}