#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 */
double frand();
int /*<<< orphan*/ srand(unsigned int);
scalar_t__ time(int /*<<< orphan*/ *);
int random_level() {
  static int first = 1;
  int lvl = 0;
  if (first) {
    srand((unsigned)time(NULL));
    first = 0;
  }
  while (frand() < 0.5 && lvl < 6)
    lvl++;
  return lvl;
}


x86 assembly (clang, -O0):
<random_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
cmpl   $0x0,0x2ef2(%rip)
je     1166 <random_level+0x36>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,0x2ed2(%rip)
jmp    116b <random_level+0x3b>
mov    $0x0,%al
call   1050 <frand@plt>
movaps %xmm0,%xmm1
xor    %eax,%eax
movsd  0xe81(%rip),%xmm0
ucomisd %xmm1,%xmm0
mov    %al,-0x5(%rbp)
jbe    1196 <random_level+0x66>
cmpl   $0x6,-0x4(%rbp)
setl   %al
mov    %al,-0x5(%rbp)
mov    -0x5(%rbp),%al
test   $0x1,%al
jne    11a6 <random_level+0x76>
jmp    11b4 <random_level+0x84>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    116b <random_level+0x3b>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_level>:
push   %rbx
cmpb   $0x0,0x2f04(%rip)
jne    114f <random_level+0x1f>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movb   $0x1,0x2eed(%rip)
mov    $0xffffffff,%ebx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%ebx
xor    %eax,%eax
call   1050 <frand@plt>
movsd  0xe8e(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    117d <random_level+0x4d>
cmp    $0x6,%ebx
jb     1160 <random_level+0x30>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@random_level.first = internal global i32 1
define i32 @random_level() {
%1 = alloca i32
store i32 0, i32* %1
%2 = load i32, i32* @random_level.first
%3 = icmp ne i32 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = call i64 @time(i32* null)
%6 = trunc i64 %5 to i32
%7 = call i32 @srand(i32 %6)
store i32 0, i32* @random_level.first
br label %8
8: ; preds = %4, %0
br label %9
9: ; preds = %17, %8
%10 = call double (...) @frand()
%11 = fcmp olt double %10, 5.000000e-01
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load i32, i32* %1
%14 = icmp slt i32 %13, 6
br label %15
15: ; preds = %12, %9
%16 = phi i1 [ false, %9 ], [ %14, %12 ]
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = load i32, i32* %1
%19 = add nsw i32 %18, 1
store i32 %19, i32* %1
br label %9
20: ; preds = %15
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@random_level.first = internal unnamed_addr global i1 false
define i32 @random_level() {
%1 = load i1, i1* @random_level.first
br i1 %1, label %6, label %2
2: ; preds = %0
%3 = tail call i64 @time(i32* null)
%4 = trunc i64 %3 to i32
%5 = tail call i32 @srand(i32 %4)
store i1 true, i1* @random_level.first
br label %6
6: ; preds = %2, %0
br label %7
7: ; preds = %6, %7
%8 = phi i32 [ %13, %7 ], [ 0, %6 ]
%9 = tail call double (...) @frand()
%10 = fcmp olt double %9, 5.000000e-01
%11 = icmp ult i32 %8, 6
%12 = select i1 %10, i1 %11, i1 false
%13 = add nuw nsw i32 %8, 1
br i1 %12, label %7, label %14
14: ; preds = %7
ret i32 %8
}