#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 */
struct drand48_data {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ drand48_r(struct drand48_data *, double *);
unsigned long mb_rand_range_ulong(struct drand48_data *rand, unsigned long from,
                                  unsigned long to) {
  unsigned long width = to - from;
  double ret;
  drand48_r(rand, &ret);
  return ret * width + from;
}


x86 assembly (clang, -O0):
<mb_rand_range_ulong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1030 <drand48_r@plt>
movsd  -0x28(%rbp),%xmm0
movaps 0xeb4(%rip),%xmm4
movq   -0x20(%rbp),%xmm2
punpckldq %xmm4,%xmm2
movapd 0xeb3(%rip),%xmm3
subpd  %xmm3,%xmm2
movaps %xmm2,%xmm1
unpckhpd %xmm2,%xmm2
addsd  %xmm1,%xmm2
movq   -0x10(%rbp),%xmm1
punpckldq %xmm4,%xmm1
subpd  %xmm3,%xmm1
movaps %xmm1,%xmm3
unpckhpd %xmm1,%xmm1
addsd  %xmm3,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movaps %xmm0,%xmm1
cvttsd2si %xmm1,%rax
mov    %rax,%rdx
sar    $0x3f,%rdx
movsd  0xe7d(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rcx
and    %rdx,%rcx
or     %rcx,%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mb_rand_range_ulong>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
sub    %rsi,%rbx
mov    %rsp,%rsi
call   1030 <drand48_r@plt>
movq   %rbx,%xmm0
movdqa 0xece(%rip),%xmm1
punpckldq %xmm1,%xmm0
movapd 0xed2(%rip),%xmm2
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm3
unpckhpd %xmm0,%xmm3
addsd  %xmm0,%xmm3
movq   %r14,%xmm0
punpckldq %xmm1,%xmm0
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
mulsd  (%rsp),%xmm3
addsd  %xmm0,%xmm1
addsd  %xmm1,%xmm3
cvttsd2si %xmm3,%rcx
mov    %rcx,%rdx
sar    $0x3f,%rdx
subsd  0xe9c(%rip),%xmm3
cvttsd2si %xmm3,%rax
and    %rdx,%rax
or     %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.drand48_data = type { i32 }
define i64 @mb_rand_range_ulong(%struct.drand48_data* %0, i64 %1, i64 %2) {
%4 = alloca %struct.drand48_data*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca double
store %struct.drand48_data* %0, %struct.drand48_data** %4
store i64 %1, i64* %5
store i64 %2, i64* %6
%9 = load i64, i64* %6
%10 = load i64, i64* %5
%11 = sub i64 %9, %10
store i64 %11, i64* %7
%12 = load %struct.drand48_data*, %struct.drand48_data** %4
%13 = call i32 @drand48_r(%struct.drand48_data* %12, double* %8)
%14 = load double, double* %8
%15 = load i64, i64* %7
%16 = uitofp i64 %15 to double
%17 = load i64, i64* %5
%18 = uitofp i64 %17 to double
%19 = call double @llvm.fmuladd.f64(double %14, double %16, double %18)
%20 = fptoui double %19 to i64
ret i64 %20
}

LLVM IR (-O2):
%struct.drand48_data = type { i32 }
define i64 @mb_rand_range_ulong(%struct.drand48_data* %0, i64 %1, i64 %2) {
%4 = alloca double
%5 = sub i64 %2, %1
%6 = bitcast double* %4 to i8*
%7 = call i32 @drand48_r(%struct.drand48_data* %0, double* %4)
%8 = load double, double* %4
%9 = uitofp i64 %5 to double
%10 = uitofp i64 %1 to double
%11 = call double @llvm.fmuladd.f64(double %8, double %9, double %10)
%12 = fptoui double %11 to i64
ret i64 %12
}