#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 randint(int low, int high) {
  int x, range = high - low + 1;
  if (range < 0)
    range = -range;
  do {
    x = rand();
  } while (x > RAND_MAX - (RAND_MAX % 9));
  return low + x % range;
}


x86 assembly (clang, -O0):
<randint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
sub    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    113c <randint+0x2c>
xor    %eax,%eax
sub    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
jmp    1141 <randint+0x31>
mov    $0x0,%al
call   1030 <rand@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e90(%rip),%rax
mov    (%rax),%ecx
mov    0x2e87(%rip),%rax
mov    (%rax),%eax
mov    $0x9,%esi
cltd
idiv   %esi
mov    -0x14(%rbp),%eax
sub    %edx,%ecx
cmp    %ecx,%eax
jg     1141 <randint+0x31>
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
cltd
idivl  -0x10(%rbp)
mov    -0x18(%rbp),%eax
add    %edx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randint>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %edi,%r14d
mov    0x2ec8(%rip),%rbp
xor    %eax,%eax
call   1030 <rand@plt>
movslq 0x0(%rbp),%rcx
imul   $0x38e38e39,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x21,%rcx
add    %edx,%ecx
lea    (%rcx,%rcx,8),%ecx
cmp    %ecx,%eax
jg     1120 <randint+0x10>
sub    %r14d,%ebx
lea    0x1(%rbx),%ecx
cmp    $0xffffffff,%ebx
not    %ebx
cmovge %ecx,%ebx
cltd
idiv   %ebx
add    %edx,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i32 0
define i32 @randint(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* %4
%8 = load i32, i32* %3
%9 = sub nsw i32 %7, %8
%10 = add nsw i32 %9, 1
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* %6
%15 = sub nsw i32 0, %14
store i32 %15, i32* %6
br label %16
16: ; preds = %13, %2
br label %17
17: ; preds = %19, %16
%18 = call i32 (...) @rand()
store i32 %18, i32* %5
br label %19
19: ; preds = %17
%20 = load i32, i32* %5
%21 = load i32, i32* @RAND_MAX
%22 = load i32, i32* @RAND_MAX
%23 = srem i32 %22, 9
%24 = sub nsw i32 %21, %23
%25 = icmp sgt i32 %20, %24
br i1 %25, label %17, label %26
26: ; preds = %19
%27 = load i32, i32* %3
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = srem i32 %28, %29
%31 = add nsw i32 %27, %30
ret i32 %31
}

LLVM IR (-O2):
@RAND_MAX = global i32 0
define i32 @randint(i32 %0, i32 %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call i32 (...) @rand()
%5 = load i32, i32* @RAND_MAX
%6 = srem i32 %5, 9
%7 = sub nsw i32 %5, %6
%8 = icmp sgt i32 %4, %7
br i1 %8, label %3, label %9
9: ; preds = %3
%10 = sub nsw i32 %1, %0
%11 = icmp slt i32 %10, -1
%12 = xor i32 %10, -1
%13 = add nsw i32 %10, 1
%14 = select i1 %11, i32 %12, i32 %13
%15 = srem i32 %4, %14
%16 = add nsw i32 %15, %0
ret i32 %16
}