#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 */
double drand48();
int first;
int /*<<< orphan*/ randomize();
unsigned randomNumber(unsigned high, unsigned low) {
  static first = 1;
  double ranVal, retVal;
  unsigned rv;
  long unsigned i;
  if (first) {
    randomize();
    for (i = 0; i < 1000; i++)
      drand48();
    first = 0;
  }
  ranVal = drand48();
  if (high == low)
    retVal = high * ranVal;
  else if (high > low)
    retVal = (double)low + ((high - low) * ranVal);
  else
    retVal = 0;
  rv = (unsigned)(retVal + 0.5);
  return (rv);
}


x86 assembly (clang, -O0):
<randomNumber>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0x0,0x2efb(%rip)
je     117a <randomNumber+0x5a>
mov    $0x0,%al
call   1030 <randomize@plt>
movq   $0x0,-0x28(%rbp)
cmpq   $0x3e8,-0x28(%rbp)
jae    1170 <randomNumber+0x50>
mov    $0x0,%al
call   1040 <drand48@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    114a <randomNumber+0x2a>
movl   $0x0,0x2eb6(%rip)
mov    $0x0,%al
call   1040 <drand48@plt>
movsd  %xmm0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jne    11a9 <randomNumber+0x89>
mov    -0x4(%rbp),%eax
cvtsi2sd %rax,%xmm0
mulsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11ed <randomNumber+0xcd>
mov    -0x4(%rbp),%eax
cmp    -0x8(%rbp),%eax
jbe    11e0 <randomNumber+0xc0>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
cvtsi2sd %rax,%xmm1
mov    -0x4(%rbp),%eax
sub    %ecx,%eax
cvtsi2sd %rax,%xmm0
movsd  -0x10(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11e8 <randomNumber+0xc8>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11ed <randomNumber+0xcd>
movsd  -0x18(%rbp),%xmm0
movsd  0xe06(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<randomNumber>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %edi,%ebp
cmpb   $0x0,0x2f04(%rip)
jne    1154 <randomNumber+0x34>
xor    %eax,%eax
call   1030 <randomize@plt>
mov    $0x3e8,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <drand48@plt>
add    $0xffffffffffffffff,%rbx
jne    1140 <randomNumber+0x20>
movb   $0x1,0x2ee0(%rip)
xor    %eax,%eax
call   1040 <drand48@plt>
mov    %ebp,%eax
sub    %r14d,%eax
jne    1173 <randomNumber+0x53>
mov    %ebp,%eax
cvtsi2sd %rax,%xmm1
mulsd  %xmm1,%xmm0
movapd %xmm0,%xmm1
jmp    1191 <randomNumber+0x71>
xorpd  %xmm1,%xmm1
jbe    1191 <randomNumber+0x71>
mov    %r14d,%ecx
cvtsi2sd %rcx,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
mulsd  %xmm0,%xmm1
addsd  %xmm2,%xmm1
addsd  0xe67(%rip),%xmm1
cvttsd2si %xmm1,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@randomNumber.first = internal global i32 1
@first = global i32 0
define i32 @randomNumber(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i64
store i32 %0, i32* %3
store i32 %1, i32* %4
%9 = load i32, i32* @randomNumber.first
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %2
%12 = call i32 (...) @randomize()
store i64 0, i64* %8
br label %13
13: ; preds = %18, %11
%14 = load i64, i64* %8
%15 = icmp ult i64 %14, 1000
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = call double (...) @drand48()
br label %18
18: ; preds = %16
%19 = load i64, i64* %8
%20 = add i64 %19, 1
store i64 %20, i64* %8
br label %13
21: ; preds = %13
store i32 0, i32* @randomNumber.first
br label %22
22: ; preds = %21, %2
%23 = call double (...) @drand48()
store double %23, double* %5
%24 = load i32, i32* %3
%25 = load i32, i32* %4
%26 = icmp eq i32 %24, %25
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = load i32, i32* %3
%29 = uitofp i32 %28 to double
%30 = load double, double* %5
%31 = fmul double %29, %30
store double %31, double* %6
br label %47
32: ; preds = %22
%33 = load i32, i32* %3
%34 = load i32, i32* %4
%35 = icmp ugt i32 %33, %34
br i1 %35, label %36, label %45
36: ; preds = %32
%37 = load i32, i32* %4
%38 = uitofp i32 %37 to double
%39 = load i32, i32* %3
%40 = load i32, i32* %4
%41 = sub i32 %39, %40
%42 = uitofp i32 %41 to double
%43 = load double, double* %5
%44 = call double @llvm.fmuladd.f64(double %42, double %43, double %38)
store double %44, double* %6
br label %46
45: ; preds = %32
store double 0.000000e+00, double* %6
br label %46
46: ; preds = %45, %36
br label %47
47: ; preds = %46, %27
%48 = load double, double* %6
%49 = fadd double %48, 5.000000e-01
%50 = fptoui double %49 to i32
store i32 %50, i32* %7
%51 = load i32, i32* %7
ret i32 %51
}

LLVM IR (-O2):
@randomNumber.first = internal unnamed_addr global i1 false
@first = global i32 0
define i32 @randomNumber(i32 %0, i32 %1) {
%3 = load i1, i1* @randomNumber.first
br i1 %3, label %12, label %4
4: ; preds = %2
%5 = tail call i32 (...) @randomize()
br label %6
6: ; preds = %4, %6
%7 = phi i64 [ 0, %4 ], [ %9, %6 ]
%8 = tail call double (...) @drand48()
%9 = add nuw nsw i64 %7, 1
%10 = icmp eq i64 %9, 1000
br i1 %10, label %11, label %6
11: ; preds = %6
store i1 true, i1* @randomNumber.first
br label %12
12: ; preds = %11, %2
%13 = tail call double (...) @drand48()
%14 = icmp eq i32 %0, %1
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = uitofp i32 %0 to double
%17 = fmul double %13, %16
br label %25
18: ; preds = %12
%19 = icmp ugt i32 %0, %1
br i1 %19, label %20, label %25
20: ; preds = %18
%21 = uitofp i32 %1 to double
%22 = sub i32 %0, %1
%23 = uitofp i32 %22 to double
%24 = tail call double @llvm.fmuladd.f64(double %23, double %13, double %21)
br label %25
25: ; preds = %18, %20, %15
%26 = phi double [ %17, %15 ], [ %24, %20 ], [ 0.000000e+00, %18 ]
%27 = fadd double %26, 5.000000e-01
%28 = fptoui double %27 to i32
ret i32 %28
}