#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();
int randombetween(int d, int c, int rc) {
  if (c >= rc && c <= rc + d)
    return c;
  if (rand() % 3 == 0)
    return rc;
  if (rand() % 3 == 0)
    return rc + d;
  return rc + (rand() % (d + (d < 0 ? -1 : 1)) + (d < 0 ? d : 0));
}


x86 assembly (clang, -O0):
<randombetween>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jl     1149 <randombetween+0x39>
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
add    -0x8(%rbp),%ecx
cmp    %ecx,%eax
jg     1149 <randombetween+0x39>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <randombetween+0xdc>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    116c <randombetween+0x5c>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <randombetween+0xdc>
mov    $0x0,%al
call   1030 <rand@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1192 <randombetween+0x82>
mov    -0x10(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11ec <randombetween+0xdc>
mov    -0x10(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <rand@plt>
mov    -0x8(%rbp),%ecx
mov    -0x8(%rbp),%edi
mov    $0x1,%edx
mov    $0xffffffff,%esi
cmp    $0x0,%edi
cmovl  %esi,%edx
add    %edx,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    11d2 <randombetween+0xc2>
mov    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11dc <randombetween+0xcc>
xor    %eax,%eax
mov    %eax,-0x1c(%rbp)
jmp    11dc <randombetween+0xcc>
mov    -0x18(%rbp),%eax
mov    -0x14(%rbp),%ecx
mov    -0x1c(%rbp),%edx
add    %edx,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randombetween>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebx
mov    %edi,%r14d
lea    (%rbx,%r14,1),%ebp
cmp    %edx,%esi
jl     1127 <randombetween+0x17>
mov    %esi,%eax
cmp    %esi,%ebp
jge    1187 <randombetween+0x77>
xor    %eax,%eax
call   1030 <rand@plt>
imul   $0xaaaaaaab,%eax,%eax
add    $0x2aaaaaaa,%eax
cmp    $0x55555555,%eax
jb     1185 <randombetween+0x75>
xor    %eax,%eax
call   1030 <rand@plt>
imul   $0xaaaaaaab,%eax,%ecx
add    $0x2aaaaaaa,%ecx
mov    %ebp,%eax
cmp    $0x55555555,%ecx
jb     1187 <randombetween+0x77>
xor    %eax,%eax
call   1030 <rand@plt>
mov    %r14d,%ecx
not    %ecx
shr    $0x1f,%ecx
lea    (%r14,%rcx,2),%ecx
add    $0xffffffff,%ecx
cltd
idiv   %ecx
mov    %r14d,%eax
sar    $0x1f,%eax
and    %r14d,%eax
add    %ebx,%eax
add    %edx,%eax
jmp    1187 <randombetween+0x77>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @randombetween(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%8 = load i32, i32* %6
%9 = load i32, i32* %7
%10 = icmp sge i32 %8, %9
br i1 %10, label %11, label %19
11: ; preds = %3
%12 = load i32, i32* %6
%13 = load i32, i32* %7
%14 = load i32, i32* %5
%15 = add nsw i32 %13, %14
%16 = icmp sle i32 %12, %15
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i32, i32* %6
store i32 %18, i32* %4
br label %52
19: ; preds = %11, %3
%20 = call i32 (...) @rand()
%21 = srem i32 %20, 3
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load i32, i32* %7
store i32 %24, i32* %4
br label %52
25: ; preds = %19
%26 = call i32 (...) @rand()
%27 = srem i32 %26, 3
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %33
29: ; preds = %25
%30 = load i32, i32* %7
%31 = load i32, i32* %5
%32 = add nsw i32 %30, %31
store i32 %32, i32* %4
br label %52
33: ; preds = %25
%34 = load i32, i32* %7
%35 = call i32 (...) @rand()
%36 = load i32, i32* %5
%37 = load i32, i32* %5
%38 = icmp slt i32 %37, 0
%39 = zext i1 %38 to i64
%40 = select i1 %38, i32 -1, i32 1
%41 = add nsw i32 %36, %40
%42 = srem i32 %35, %41
%43 = load i32, i32* %5
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %33
%46 = load i32, i32* %5
br label %48
47: ; preds = %33
br label %48
48: ; preds = %47, %45
%49 = phi i32 [ %46, %45 ], [ 0, %47 ]
%50 = add nsw i32 %42, %49
%51 = add nsw i32 %34, %50
store i32 %51, i32* %4
br label %52
52: ; preds = %48, %29, %23, %17
%53 = load i32, i32* %4
ret i32 %53
}

LLVM IR (-O2):
define i32 @randombetween(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %1, %2
%5 = add nsw i32 %2, %0
%6 = icmp slt i32 %5, %1
%7 = select i1 %4, i1 true, i1 %6
br i1 %7, label %8, label %25
8: ; preds = %3
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 3
%11 = icmp eq i32 %10, 0
br i1 %11, label %25, label %12
12: ; preds = %8
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 3
%15 = icmp eq i32 %14, 0
br i1 %15, label %25, label %16
16: ; preds = %12
%17 = tail call i32 (...) @rand()
%18 = icmp slt i32 %0, 0
%19 = select i1 %18, i32 -1, i32 1
%20 = add nsw i32 %19, %0
%21 = srem i32 %17, %20
%22 = select i1 %18, i32 %0, i32 0
%23 = add i32 %22, %2
%24 = add i32 %23, %21
br label %25
25: ; preds = %12, %8, %3, %16
%26 = phi i32 [ %24, %16 ], [ %1, %3 ], [ %2, %8 ], [ %5, %12 ]
ret i32 %26
}