#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_r(unsigned int *);
unsigned int fc_dl_sl_rand_level(unsigned int *seed, unsigned int max) {
  unsigned int level = 0;
  max = max > 8 - 1 ? 8 - 1 : max;
  while (rand_r(seed) > ((1 - 0.20) * RAND_MAX) && level < max)
    level++;
  return level;
}


x86 assembly (clang, -O0):
<fc_dl_sl_rand_level>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x7,-0xc(%rbp)
jbe    113d <fc_dl_sl_rand_level+0x2d>
mov    $0x7,%eax
mov    %eax,-0x14(%rbp)
jmp    1143 <fc_dl_sl_rand_level+0x33>
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rand_r@plt>
cvtsi2sd %eax,%xmm0
mov    0x2e8b(%rip),%rax
cvtsi2sdl (%rax),%xmm2
movsd  0xe97(%rip),%xmm1
mulsd  %xmm2,%xmm1
xor    %eax,%eax
ucomisd %xmm1,%xmm0
mov    %al,-0x15(%rbp)
jbe    1188 <fc_dl_sl_rand_level+0x78>
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
setb   %al
mov    %al,-0x15(%rbp)
mov    -0x15(%rbp),%al
test   $0x1,%al
jne    1198 <fc_dl_sl_rand_level+0x88>
jmp    11a6 <fc_dl_sl_rand_level+0x96>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1149 <fc_dl_sl_rand_level+0x39>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fc_dl_sl_rand_level>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x7,%esi
mov    $0x7,%ebp
cmovb  %esi,%ebp
mov    %rdi,%r14
mov    $0xffffffff,%ebx
mov    0x2eb7(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebx
mov    %r14,%rdi
call   1030 <rand_r@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdl (%r15),%xmm1
mulsd  0xe9e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    116c <fc_dl_sl_rand_level+0x5c>
cmp    %ebp,%ebx
jb     1140 <fc_dl_sl_rand_level+0x30>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i32 0
define i32 @fc_dl_sl_rand_level(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* %4
%7 = icmp ugt i32 %6, 7
br i1 %7, label %8, label %9
8: ; preds = %2
br label %11
9: ; preds = %2
%10 = load i32, i32* %4
br label %11
11: ; preds = %9, %8
%12 = phi i32 [ 7, %8 ], [ %10, %9 ]
store i32 %12, i32* %4
br label %13
13: ; preds = %27, %11
%14 = load i32*, i32** %3
%15 = call i32 @rand_r(i32* %14)
%16 = sitofp i32 %15 to double
%17 = load i32, i32* @RAND_MAX
%18 = sitofp i32 %17 to double
%19 = fmul double 8.000000e-01, %18
%20 = fcmp ogt double %16, %19
br i1 %20, label %21, label %25
21: ; preds = %13
%22 = load i32, i32* %5
%23 = load i32, i32* %4
%24 = icmp ult i32 %22, %23
br label %25
25: ; preds = %21, %13
%26 = phi i1 [ false, %13 ], [ %24, %21 ]
br i1 %26, label %27, label %30
27: ; preds = %25
%28 = load i32, i32* %5
%29 = add i32 %28, 1
store i32 %29, i32* %5
br label %13
30: ; preds = %25
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
@RAND_MAX = global i32 0
define i32 @fc_dl_sl_rand_level(i32* %0, i32 %1) {
%3 = icmp ult i32 %1, 7
%4 = select i1 %3, i32 %1, i32 7
br label %5
5: ; preds = %5, %2
%6 = phi i32 [ 0, %2 ], [ %15, %5 ]
%7 = tail call i32 @rand_r(i32* %0)
%8 = sitofp i32 %7 to double
%9 = load i32, i32* @RAND_MAX
%10 = sitofp i32 %9 to double
%11 = fmul double %10, 8.000000e-01
%12 = fcmp olt double %11, %8
%13 = icmp ult i32 %6, %4
%14 = select i1 %12, i1 %13, i1 false
%15 = add nuw nsw i32 %6, 1
br i1 %14, label %5, label %16
16: ; preds = %5
ret i32 %6
}