#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 */
unsigned int genrand_int32();
int RLFL_randint(int limit) {
  unsigned int n, r;
  if (limit <= 1)
    return (0);
  if (limit > 0x10000000)
    limit = 0x10000000;
  n = (0x10000000 / limit);
  while (1) {
    r = genrand_int32();
    r = (r >> 4) / n;
    if (r < limit) {
      break;
    }
  }
  return r;
}


x86 assembly (clang, -O0):
<RLFL_randint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
cmpl   $0x1,-0x8(%rbp)
jg     1131 <RLFL_randint+0x21>
movl   $0x0,-0x4(%rbp)
jmp    1185 <RLFL_randint+0x75>
cmpl   $0x10000000,-0x8(%rbp)
jle    1145 <RLFL_randint+0x35>
movl   $0x10000000,-0x8(%rbp)
mov    $0x10000000,%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <genrand_int32@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shr    $0x4,%eax
xor    %edx,%edx
divl   -0xc(%rbp)
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    117a <RLFL_randint+0x6a>
jmp    117f <RLFL_randint+0x6f>
jmp    1151 <RLFL_randint+0x41>
mov    -0x10(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RLFL_randint>:
xor    %eax,%eax
cmp    $0x2,%edi
jl     1158 <RLFL_randint+0x48>
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
cmp    $0x10000000,%edi
mov    $0x10000000,%eax
cmovae %eax,%ebx
mov    $0x10000000,%eax
xor    %edx,%edx
div    %ebx
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1030 <genrand_int32@plt>
shr    $0x4,%eax
xor    %edx,%edx
div    %ebp
cmp    %ebx,%eax
jae    1140 <RLFL_randint+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i32 @RLFL_randint(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp sle i32 %6, 1
br i1 %7, label %8, label %9
8: ; preds = %1
store i32 0, i32* %2
br label %29
9: ; preds = %1
%10 = load i32, i32* %3
%11 = icmp sgt i32 %10, 268435456
br i1 %11, label %12, label %13
12: ; preds = %9
store i32 268435456, i32* %3
br label %13
13: ; preds = %12, %9
%14 = load i32, i32* %3
%15 = sdiv i32 268435456, %14
store i32 %15, i32* %4
br label %16
16: ; preds = %13, %26
%17 = call i32 (...) @genrand_int32()
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = lshr i32 %18, 4
%20 = load i32, i32* %4
%21 = udiv i32 %19, %20
store i32 %21, i32* %5
%22 = load i32, i32* %5
%23 = load i32, i32* %3
%24 = icmp ult i32 %22, %23
br i1 %24, label %25, label %26
25: ; preds = %16
br label %27
26: ; preds = %16
br label %16
27: ; preds = %25
%28 = load i32, i32* %5
store i32 %28, i32* %2
br label %29
29: ; preds = %27, %8
%30 = load i32, i32* %2
ret i32 %30
}

LLVM IR (-O2):
define i32 @RLFL_randint(i32 %0) {
%2 = icmp slt i32 %0, 2
br i1 %2, label %12, label %3
3: ; preds = %1
%4 = icmp ult i32 %0, 268435456
%5 = select i1 %4, i32 %0, i32 268435456
%6 = udiv i32 268435456, %5
br label %7
7: ; preds = %7, %3
%8 = tail call i32 (...) @genrand_int32()
%9 = lshr i32 %8, 4
%10 = udiv i32 %9, %6
%11 = icmp ult i32 %10, %5
br i1 %11, label %12, label %7
12: ; preds = %7, %1
%13 = phi i32 [ 0, %1 ], [ %10, %7 ]
ret i32 %13
}