#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 */
typedef int uint64_t;
typedef int uint32_t;

/* Variables and functions */
int UINT32_MAX;
int pcg32_random();
uint32_t __attribute__((no)) ranged_random_recycle_mult(uint32_t range) {
  uint64_t rotations = 0;
  uint64_t random32bit = pcg32_random();
  while (1) {
    uint32_t candidate = (random32bit * range) >> 32;
    if (random32bit - candidate > UINT32_MAX - range + 1) {
      if (rotations == 31) {
        rotations = 0;
        random32bit = pcg32_random();
      } else {
        rotations++;
        random32bit = (random32bit >> 1) | (random32bit << 31);
      }
    } else {
      return candidate;
    }
  }
}


x86 assembly (clang, -O0):
<ranged_random_recycle_mult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <pcg32_random@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
imul   -0x4(%rbp),%eax
mov    $0x20,%ecx
sar    %cl,%eax
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
sub    -0x10(%rbp),%eax
mov    0x2eae(%rip),%rcx
mov    (%rcx),%ecx
sub    -0x4(%rbp),%ecx
add    $0x1,%ecx
cmp    %ecx,%eax
jle    1199 <ranged_random_recycle_mult+0x89>
cmpl   $0x1f,-0x8(%rbp)
jne    117a <ranged_random_recycle_mult+0x6a>
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1030 <pcg32_random@plt>
mov    %eax,-0xc(%rbp)
jmp    1194 <ranged_random_recycle_mult+0x84>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0xc(%rbp),%eax
sar    $0x1,%eax
mov    -0xc(%rbp),%ecx
shl    $0x1f,%ecx
or     %ecx,%eax
mov    %eax,-0xc(%rbp)
jmp    11a2 <ranged_random_recycle_mult+0x92>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret
jmp    112c <ranged_random_recycle_mult+0x1c>

x86 assembly (clang, -O2):
<ranged_random_recycle_mult>:
xor    %eax,%eax
jmp    1030 <pcg32_random@plt>

LLVM IR (-O0):
@UINT32_MAX = global i32 0
define i32 @ranged_random_recycle_mult(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
%6 = call i32 (...) @pcg32_random()
store i32 %6, i32* %4
br label %7
7: ; preds = %1, %36
%8 = load i32, i32* %4
%9 = load i32, i32* %2
%10 = mul nsw i32 %8, %9
%11 = ashr i32 %10, 32
store i32 %11, i32* %5
%12 = load i32, i32* %4
%13 = load i32, i32* %5
%14 = sub nsw i32 %12, %13
%15 = load i32, i32* @UINT32_MAX
%16 = load i32, i32* %2
%17 = sub nsw i32 %15, %16
%18 = add nsw i32 %17, 1
%19 = icmp sgt i32 %14, %18
br i1 %19, label %20, label %34
20: ; preds = %7
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, 31
br i1 %22, label %23, label %25
23: ; preds = %20
store i32 0, i32* %3
%24 = call i32 (...) @pcg32_random()
store i32 %24, i32* %4
br label %33
25: ; preds = %20
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
%28 = load i32, i32* %4
%29 = ashr i32 %28, 1
%30 = load i32, i32* %4
%31 = shl i32 %30, 31
%32 = or i32 %29, %31
store i32 %32, i32* %4
br label %33
33: ; preds = %25, %23
br label %36
34: ; preds = %7
%35 = load i32, i32* %5
ret i32 %35
36: ; preds = %33
br label %7
}

LLVM IR (-O2):
@UINT32_MAX = global i32 0
define i32 @ranged_random_recycle_mult(i32 %0) {
%2 = tail call i32 (...) @pcg32_random()
ret i32 undef
}