#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;
scalar_t__ generate_seed(int, int);
int rand();
int /*<<< orphan*/ srand(scalar_t__);
scalar_t__ time(int /*<<< orphan*/ *);
int int_rand_range(int min, int max) {
  int random = min - 1;
  srand(time(NULL) + generate_seed(1, 64224));
  while (!(random >= min && random <= max + 1)) {
    random = (min + rand()) / (RAND_MAX / ((max + 1) - min + 1) + 1);
  }
  return random;
}


x86 assembly (clang, -O0):
<int_rand_range>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x18(%rbp)
mov    $0x1,%edi
mov    $0xfae0,%esi
call   1050 <generate_seed@plt>
mov    -0x18(%rbp),%rdi
add    %rax,%rdi
call   1030 <srand@plt>
mov    -0xc(%rbp),%ecx
xor    %eax,%eax
cmp    -0x4(%rbp),%ecx
mov    %al,-0x19(%rbp)
jl     11a1 <int_rand_range+0x61>
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
xor    $0xff,%al
test   $0x1,%al
jne    11b3 <int_rand_range+0x73>
jmp    11f5 <int_rand_range+0xb5>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%ecx
add    $0x1,%ecx
sub    -0x4(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
jmp    117f <int_rand_range+0x3f>
mov    -0xc(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<int_rand_range>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ebp
xor    %edi,%edi
call   1040 <time@plt>
mov    %rax,%r14
mov    $0x1,%edi
mov    $0xfae0,%esi
call   1050 <generate_seed@plt>
add    %rax,%r14
mov    %r14,%rdi
call   1030 <srand@plt>
lea    0x1(%rbx),%r14d
sub    %ebp,%ebx
add    $0x2,%ebx
mov    0x2e69(%rip),%r15
nop
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,%ecx
add    %ebp,%ecx
mov    (%r15),%eax
cltd
idiv   %ebx
mov    %eax,%esi
add    $0x1,%esi
mov    %ecx,%eax
cltd
idiv   %esi
cmp    %ebp,%eax
jl     1180 <int_rand_range+0x40>
cmp    %r14d,%eax
jg     1180 <int_rand_range+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i32 0
define i32 @int_rand_range(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = sub nsw i32 %6, 1
store i32 %7, i32* %5
%8 = call i64 @time(i32* null)
%9 = call i64 @generate_seed(i32 1, i32 64224)
%10 = add nsw i64 %8, %9
%11 = call i32 @srand(i64 %10)
br label %12
12: ; preds = %24, %2
%13 = load i32, i32* %5
%14 = load i32, i32* %3
%15 = icmp sge i32 %13, %14
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i32, i32* %5
%18 = load i32, i32* %4
%19 = add nsw i32 %18, 1
%20 = icmp sle i32 %17, %19
br label %21
21: ; preds = %16, %12
%22 = phi i1 [ false, %12 ], [ %20, %16 ]
%23 = xor i1 %22, true
br i1 %23, label %24, label %37
24: ; preds = %21
%25 = load i32, i32* %3
%26 = call i32 (...) @rand()
%27 = add nsw i32 %25, %26
%28 = load i32, i32* @RAND_MAX
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
%31 = load i32, i32* %3
%32 = sub nsw i32 %30, %31
%33 = add nsw i32 %32, 1
%34 = sdiv i32 %28, %33
%35 = add nsw i32 %34, 1
%36 = sdiv i32 %27, %35
store i32 %36, i32* %5
br label %12
37: ; preds = %21
%38 = load i32, i32* %5
ret i32 %38
}

LLVM IR (-O2):
@RAND_MAX = global i32 0
define i32 @int_rand_range(i32 %0, i32 %1) {
%3 = tail call i64 @time(i32* null)
%4 = tail call i64 @generate_seed(i32 1, i32 64224)
%5 = add nsw i64 %4, %3
%6 = tail call i32 @srand(i64 %5)
%7 = add nsw i32 %1, 1
%8 = sub i32 %1, %0
%9 = add i32 %8, 2
br label %10
10: ; preds = %2, %10
%11 = tail call i32 (...) @rand()
%12 = add nsw i32 %11, %0
%13 = load i32, i32* @RAND_MAX
%14 = sdiv i32 %13, %9
%15 = add nsw i32 %14, 1
%16 = sdiv i32 %12, %15
%17 = icmp slt i32 %16, %0
%18 = icmp sgt i32 %16, %7
%19 = select i1 %17, i1 true, i1 %18
br i1 %19, label %10, label %20
20: ; preds = %10
ret i32 %16
}