#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 /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int _get_level(int len) {
  int i = 1;
  int level = 1;
  srand(time(NULL));
  int half = RAND_MAX / 2;
  while (i < len) {
    i *= 2;
    if (rand() > half) {
      level++;
    }
  }
  return level;
}


x86 assembly (clang, -O0):
<_get_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11a0 <_get_level+0x70>
mov    -0x8(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <rand@plt>
cmp    -0x10(%rbp),%eax
jle    119b <_get_level+0x6b>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116d <_get_level+0x3d>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_get_level>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
mov    $0x1,%ebp
cmp    $0x2,%r14d
jl     1198 <_get_level+0x68>
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,%r15d
shr    $0x1f,%r15d
add    %eax,%r15d
sar    %r15d
mov    $0x1,%ebx
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
add    %ebx,%ebx
xor    %eax,%eax
call   1050 <rand@plt>
xor    %ecx,%ecx
cmp    %r15d,%eax
setg   %cl
add    %ecx,%ebp
cmp    %r14d,%ebx
jl     1180 <_get_level+0x50>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

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