#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 long randInt();
unsigned long MT_randInt(unsigned long n) {
  unsigned long used = n;
  used |= used >> 1;
  used |= used >> 2;
  used |= used >> 4;
  used |= used >> 8;
  used |= used >> 16;
  unsigned long i;
  do {
    i = randInt() & used;
  } while (i > n);
  return i;
}


x86 assembly (clang, -O0):
<MT_randInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x1,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x2,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x4,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x8,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
shr    $0x10,%rax
or     -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <randInt@plt>
and    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x8(%rbp),%rax
ja     1174 <MT_randInt+0x64>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<MT_randInt>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    %rdi,%rax
shr    %rax
or     %rdi,%rax
mov    %rax,%rcx
shr    $0x2,%rcx
or     %rax,%rcx
mov    %rcx,%rax
shr    $0x4,%rax
or     %rcx,%rax
mov    %rax,%rcx
shr    $0x8,%rcx
or     %rax,%rcx
mov    %rcx,%rbx
shr    $0x10,%rbx
or     %rcx,%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <randInt@plt>
and    %rbx,%rax
cmp    %r14,%rax
ja     1150 <MT_randInt+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define i64 @MT_randInt(i64 %0) {
%2 = lshr i64 %0, 1
%3 = or i64 %2, %0
%4 = lshr i64 %3, 2
%5 = or i64 %4, %3
%6 = lshr i64 %5, 4
%7 = or i64 %6, %5
%8 = lshr i64 %7, 8
%9 = or i64 %8, %7
%10 = lshr i64 %9, 16
%11 = or i64 %10, %9
br label %12
12: ; preds = %12, %1
%13 = tail call i64 (...) @randInt()
%14 = and i64 %13, %11
%15 = icmp ugt i64 %14, %0
br i1 %15, label %12, label %16
16: ; preds = %12
ret i64 %14
}