#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int rand();
int /*<<< orphan*/ srand(char);
char time(int /*<<< orphan*/);
int generate_random_pct(int lower, int upper) {
  int i;
  int num = 0;
  char random_seed = 0;
  FILE *fp;
  fp = fopen("/dev/random", "r");
  if (!fp) {
    srand(time(0));
  } else {
    random_seed = getc(fp);
    fclose(fp);
    srand(random_seed);
  }
  num = (rand() % (upper - lower + 1)) + lower;
  if (num < 0)
    num = 0;
  if (num > 100)
    num = 99;
  return num;
}


x86 assembly (clang, -O0):
<generate_random_pct>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
lea    0xe80(%rip),%rdi
lea    0xe85(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11af <generate_random_pct+0x4f>
xor    %edi,%edi
call   1050 <time@plt>
movsbl %al,%edi
call   1040 <srand@plt>
jmp    11cd <generate_random_pct+0x6d>
mov    -0x20(%rbp),%rdi
call   1070 <getc@plt>
mov    %al,-0x11(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movsbl -0x11(%rbp),%edi
call   1040 <srand@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    -0x8(%rbp),%ecx
sub    -0x4(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
add    -0x4(%rbp),%edx
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11f7 <generate_random_pct+0x97>
movl   $0x0,-0x10(%rbp)
cmpl   $0x64,-0x10(%rbp)
jle    1208 <generate_random_pct+0xa8>
movl   $0x63,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_random_pct>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %edi,%ebx
lea    0xe8d(%rip),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119c <generate_random_pct+0x3c>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <getc@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1030 <fclose@plt>
jmp    11a6 <generate_random_pct+0x46>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%r14d
movsbl %r14b,%edi
call   1040 <srand@plt>
xor    %ebp,%ebp
xor    %eax,%eax
call   1080 <rand@plt>
sub    %ebx,%r15d
add    $0x1,%r15d
cltd
idiv   %r15d
add    %edx,%ebx
cmovs  %ebp,%ebx
cmp    $0x65,%ebx
mov    $0x63,%eax
cmovb  %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"/dev/random\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @generate_random_pct(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8
%8 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %6
store i8 0, i8* %7
%9 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %8
%10 = load i32*, i32** %8
%11 = icmp ne i32* %10, null
br i1 %11, label %15, label %12
12: ; preds = %2
%13 = call signext i8 @time(i32 0)
%14 = call i32 @srand(i8 signext %13)
br label %22
15: ; preds = %2
%16 = load i32*, i32** %8
%17 = call signext i8 @getc(i32* %16)
store i8 %17, i8* %7
%18 = load i32*, i32** %8
%19 = call i32 @fclose(i32* %18)
%20 = load i8, i8* %7
%21 = call i32 @srand(i8 signext %20)
br label %22
22: ; preds = %15, %12
%23 = call i32 (...) @rand()
%24 = load i32, i32* %4
%25 = load i32, i32* %3
%26 = sub nsw i32 %24, %25
%27 = add nsw i32 %26, 1
%28 = srem i32 %23, %27
%29 = load i32, i32* %3
%30 = add nsw i32 %28, %29
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %22
store i32 0, i32* %6
br label %34
34: ; preds = %33, %22
%35 = load i32, i32* %6
%36 = icmp sgt i32 %35, 100
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 99, i32* %6
br label %38
38: ; preds = %37, %34
%39 = load i32, i32* %6
ret i32 %39
}

LLVM IR (-O2):
@.str = [12 x i8] c"/dev/random\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @generate_random_pct(i32 %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call signext i8 @time(i32 0)
br label %10
7: ; preds = %2
%8 = tail call signext i8 @getc(i32* %3)
%9 = tail call i32 @fclose(i32* %3)
br label %10
10: ; preds = %7, %5
%11 = phi i8 [ %8, %7 ], [ %6, %5 ]
%12 = tail call i32 @srand(i8 signext %11)
%13 = tail call i32 (...) @rand()
%14 = sub i32 1, %0
%15 = add i32 %14, %1
%16 = srem i32 %13, %15
%17 = add nsw i32 %16, %0
%18 = icmp sgt i32 %17, 0
%19 = select i1 %18, i32 %17, i32 0
%20 = icmp ugt i32 %19, 100
%21 = select i1 %20, i32 99, i32 %19
ret i32 %21
}