#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();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int random_number(int min, int max) {
  static int initialized = 0;
  int divisor = RAND_MAX / (max - min + 1);
  int retval;
  if (!initialized) {
    srand(time(NULL));
    initialized = 1;
  }
  do {
    retval = rand() / divisor;
  } while (retval > max - min);
  return retval + min;
}


x86 assembly (clang, -O0):
<random_number>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    0x2ea3(%rip),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%ecx
sub    -0x4(%rbp),%ecx
add    $0x1,%ecx
cltd
idiv   %ecx
mov    %eax,-0xc(%rbp)
cmpl   $0x0,0x2edf(%rip)
jne    117d <random_number+0x4d>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x1,0x2ebf(%rip)
jmp    1182 <random_number+0x52>
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    -0x4(%rbp),%ecx
cmp    %ecx,%eax
jg     1182 <random_number+0x52>
mov    -0x10(%rbp),%eax
add    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_number>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%r14d
mov    0x2ea8(%rip),%rax
mov    (%rax),%eax
sub    %edi,%ebx
lea    0x1(%rbx),%ecx
cltd
idiv   %ecx
mov    %eax,%ebp
cmpb   $0x0,0x2ee9(%rip)
jne    1170 <random_number+0x40>
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movb   $0x1,0x2ed2(%rip)
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %ebp
cmp    %ebx,%eax
jg     1170 <random_number+0x40>
add    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@random_number.initialized = internal global i32 0
@RAND_MAX = global i32 0
define i32 @random_number(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* @RAND_MAX
%8 = load i32, i32* %4
%9 = load i32, i32* %3
%10 = sub nsw i32 %8, %9
%11 = add nsw i32 %10, 1
%12 = sdiv i32 %7, %11
store i32 %12, i32* %5
%13 = load i32, i32* @random_number.initialized
%14 = icmp ne i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = call i32 @time(i32* null)
%17 = call i32 @srand(i32 %16)
store i32 1, i32* @random_number.initialized
br label %18
18: ; preds = %15, %2
br label %19
19: ; preds = %23, %18
%20 = call i32 (...) @rand()
%21 = load i32, i32* %5
%22 = sdiv i32 %20, %21
store i32 %22, i32* %6
br label %23
23: ; preds = %19
%24 = load i32, i32* %6
%25 = load i32, i32* %4
%26 = load i32, i32* %3
%27 = sub nsw i32 %25, %26
%28 = icmp sgt i32 %24, %27
br i1 %28, label %19, label %29
29: ; preds = %23
%30 = load i32, i32* %6
%31 = load i32, i32* %3
%32 = add nsw i32 %30, %31
ret i32 %32
}

LLVM IR (-O2):
@random_number.initialized = internal unnamed_addr global i1 false
@RAND_MAX = global i32 0
define i32 @random_number(i32 %0, i32 %1) {
%3 = load i32, i32* @RAND_MAX
%4 = sub nsw i32 %1, %0
%5 = add nsw i32 %4, 1
%6 = sdiv i32 %3, %5
%7 = load i1, i1* @random_number.initialized
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = tail call i32 @time(i32* null)
%10 = tail call i32 @srand(i32 %9)
store i1 true, i1* @random_number.initialized
br label %11
11: ; preds = %8, %2
br label %12
12: ; preds = %11, %12
%13 = tail call i32 (...) @rand()
%14 = sdiv i32 %13, %6
%15 = icmp sgt i32 %14, %4
br i1 %15, label %12, label %16
16: ; preds = %12
%17 = add nsw i32 %14, %0
ret i32 %17
}