#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_range(int /*<<< orphan*/, int);
char rand_percent(short percent) {
  return (rand_range(0, 99) <
          (((0) > ((((100) < (percent)) ? (100) : (percent))))
               ? (0)
               : ((((100) < (percent)) ? (100) : (percent)))));
}


x86 assembly (clang, -O0):
<rand_percent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
xor    %edi,%edi
mov    $0x63,%esi
call   1030 <rand_range@plt>
mov    %eax,-0x8(%rbp)
movswl -0x2(%rbp),%ecx
mov    $0x64,%eax
cmp    %ecx,%eax
jge    114c <rand_percent+0x3c>
mov    $0x64,%eax
mov    %eax,-0xc(%rbp)
jmp    1153 <rand_percent+0x43>
movswl -0x2(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jle    116a <rand_percent+0x5a>
xor    %eax,%eax
mov    %eax,-0x10(%rbp)
jmp    1195 <rand_percent+0x85>
movswl -0x2(%rbp),%ecx
mov    $0x64,%eax
cmp    %ecx,%eax
jge    1188 <rand_percent+0x78>
mov    $0x64,%eax
mov    %eax,-0x14(%rbp)
jmp    118f <rand_percent+0x7f>
movswl -0x2(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    -0x10(%rbp),%ecx
cmp    %ecx,%eax
setl   %al
and    $0x1,%al
movzbl %al,%eax
movsbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_percent>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
xor    %ebp,%ebp
xor    %edi,%edi
mov    $0x63,%esi
call   1030 <rand_range@plt>
cmp    $0x64,%ebx
mov    $0x64,%ecx
cmovl  %ebx,%ecx
test   %ecx,%ecx
cmovs  %ebp,%ecx
cmp    %ecx,%eax
setl   %al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define signext i8 @rand_percent(i16 signext %0) {
%2 = alloca i16
store i16 %0, i16* %2
%3 = call i32 @rand_range(i32 0, i32 99)
%4 = load i16, i16* %2
%5 = sext i16 %4 to i32
%6 = icmp slt i32 100, %5
br i1 %6, label %7, label %8
7: ; preds = %1
br label %11
8: ; preds = %1
%9 = load i16, i16* %2
%10 = sext i16 %9 to i32
br label %11
11: ; preds = %8, %7
%12 = phi i32 [ 100, %7 ], [ %10, %8 ]
%13 = icmp sgt i32 0, %12
br i1 %13, label %14, label %15
14: ; preds = %11
br label %25
15: ; preds = %11
%16 = load i16, i16* %2
%17 = sext i16 %16 to i32
%18 = icmp slt i32 100, %17
br i1 %18, label %19, label %20
19: ; preds = %15
br label %23
20: ; preds = %15
%21 = load i16, i16* %2
%22 = sext i16 %21 to i32
br label %23
23: ; preds = %20, %19
%24 = phi i32 [ 100, %19 ], [ %22, %20 ]
br label %25
25: ; preds = %23, %14
%26 = phi i32 [ 0, %14 ], [ %24, %23 ]
%27 = icmp slt i32 %3, %26
%28 = zext i1 %27 to i32
%29 = trunc i32 %28 to i8
ret i8 %29
}

LLVM IR (-O2):
define signext i8 @rand_percent(i16 signext %0) {
%2 = tail call i32 @rand_range(i32 0, i32 99)
%3 = sext i16 %0 to i32
%4 = icmp slt i32 %3, 100
%5 = select i1 %4, i32 %3, i32 100
%6 = icmp sgt i32 %5, 0
%7 = select i1 %6, i32 %5, i32 0
%8 = icmp slt i32 %2, %7
%9 = zext i1 %8 to i8
ret i8 %9
}