#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 scalar_t__ uint;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ random_double_uniform();
uint random_uint(uint a, uint b) {
  uint r;
  assert(a <= b);
  r = a + (uint)((b - a + 1) * random_double_uniform());
  assert(a <= r && r <= b);
  return r;
}


x86 assembly (clang, -O0):
<random_uint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cmp    -0x10(%rbp),%rax
setle  %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
sub    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <random_double_uniform@plt>
mov    -0x30(%rbp),%rcx
mov    %rax,%rdx
mov    -0x28(%rbp),%rax
imul   %rdx,%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rcx
xor    %eax,%eax
cmp    -0x18(%rbp),%rcx
mov    %al,-0x19(%rbp)
jg     119b <random_uint+0x7b>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<random_uint>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
mov    %rsi,%rbx
sub    %r15,%rbx
setge  %dil
call   1030 <assert@plt>
add    $0x1,%rbx
xor    %eax,%eax
call   1040 <random_double_uniform@plt>
imul   %rbx,%rax
add    %rax,%r15
test   %rax,%rax
setns  %al
cmp    %r14,%r15
setle  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @random_uint(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%6 = load i64, i64* %3
%7 = load i64, i64* %4
%8 = icmp sle i64 %6, %7
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i64, i64* %3
%12 = load i64, i64* %4
%13 = load i64, i64* %3
%14 = sub nsw i64 %12, %13
%15 = add nsw i64 %14, 1
%16 = call i64 (...) @random_double_uniform()
%17 = mul nsw i64 %15, %16
%18 = add nsw i64 %11, %17
store i64 %18, i64* %5
%19 = load i64, i64* %3
%20 = load i64, i64* %5
%21 = icmp sle i64 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %2
%23 = load i64, i64* %5
%24 = load i64, i64* %4
%25 = icmp sle i64 %23, %24
br label %26
26: ; preds = %22, %2
%27 = phi i1 [ false, %2 ], [ %25, %22 ]
%28 = zext i1 %27 to i32
%29 = call i32 @assert(i32 %28)
%30 = load i64, i64* %5
ret i64 %30
}

LLVM IR (-O2):
define i64 @random_uint(i64 %0, i64 %1) {
%3 = icmp sge i64 %1, %0
%4 = zext i1 %3 to i32
%5 = tail call i32 @assert(i32 %4)
%6 = sub i64 1, %0
%7 = add i64 %6, %1
%8 = tail call i64 (...) @random_double_uniform()
%9 = mul nsw i64 %8, %7
%10 = add nsw i64 %9, %0
%11 = icmp sgt i64 %9, -1
%12 = icmp sle i64 %10, %1
%13 = select i1 %11, i1 %12, i1 false
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
ret i64 %10
}