#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 */
scalar_t__ RAND_MAX;
long random();
long randomRange(long min, long max) {
  max = max - min;
  unsigned long numBins = (unsigned long)max + 1,
                numRand = (unsigned long)RAND_MAX + 1,
                binSize = numRand / numBins, defect = numRand % numBins;
  long x;
  while (numRand - defect <= (unsigned long)(x = random()))
    ;
  return min + x / binSize;
}


x86 assembly (clang, -O0):
<randomRange>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    0x2ea9(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x18(%rbp)
mov    %rdx,-0x30(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1030 <random@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
mov    %rcx,-0x38(%rbp)
cmp    %rcx,%rax
ja     1196 <randomRange+0x86>
jmp    116a <randomRange+0x5a>
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x38(%rbp),%rax
xor    %ecx,%ecx
mov    %ecx,%edx
divq   -0x28(%rbp)
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
add    %rcx,%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomRange>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
sub    %rdi,%rsi
add    $0x1,%rsi
mov    0x2ec2(%rip),%rax
mov    (%rax),%rbx
add    $0x1,%rbx
mov    %rbx,%rax
or     %rsi,%rax
shr    $0x20,%rax
je     1146 <randomRange+0x36>
mov    %rbx,%rax
xor    %edx,%edx
div    %rsi
mov    %rax,%r15
jmp    114f <randomRange+0x3f>
mov    %ebx,%eax
xor    %edx,%edx
div    %esi
mov    %eax,%r15d
sub    %rdx,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1030 <random@plt>
cmp    %rax,%rbx
jbe    1160 <randomRange+0x50>
mov    %rax,%rcx
or     %r15,%rcx
shr    $0x20,%rcx
je     117f <randomRange+0x6f>
xor    %edx,%edx
div    %r15
jmp    1184 <randomRange+0x74>
xor    %edx,%edx
div    %r15d
add    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
define i64 @randomRange(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%10 = load i64, i64* %4
%11 = load i64, i64* %3
%12 = sub nsw i64 %10, %11
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = add i64 %13, 1
store i64 %14, i64* %5
%15 = load i64, i64* @RAND_MAX
%16 = add i64 %15, 1
store i64 %16, i64* %6
%17 = load i64, i64* %6
%18 = load i64, i64* %5
%19 = udiv i64 %17, %18
store i64 %19, i64* %7
%20 = load i64, i64* %6
%21 = load i64, i64* %5
%22 = urem i64 %20, %21
store i64 %22, i64* %8
br label %23
23: ; preds = %29, %2
%24 = load i64, i64* %6
%25 = load i64, i64* %8
%26 = sub i64 %24, %25
%27 = call i64 (...) @random()
store i64 %27, i64* %9
%28 = icmp ule i64 %26, %27
br i1 %28, label %29, label %30
29: ; preds = %23
br label %23
30: ; preds = %23
%31 = load i64, i64* %3
%32 = load i64, i64* %9
%33 = load i64, i64* %7
%34 = udiv i64 %32, %33
%35 = add i64 %31, %34
ret i64 %35
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
define i64 @randomRange(i64 %0, i64 %1) {
%3 = sub nsw i64 %1, %0
%4 = add i64 %3, 1
%5 = load i64, i64* @RAND_MAX
%6 = add i64 %5, 1
%7 = urem i64 %6, %4
%8 = udiv i64 %6, %4
%9 = sub i64 %6, %7
br label %10
10: ; preds = %10, %2
%11 = tail call i64 (...) @random()
%12 = icmp ugt i64 %9, %11
br i1 %12, label %13, label %10
13: ; preds = %10
%14 = udiv i64 %11, %8
%15 = add i64 %14, %0
ret i64 %15
}