#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 RAND_MAX;
int /*<<< orphan*/ SYS_GetSeed();
double rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
__attribute__((visibility("hidden"))) int SYS_RandomInt(int fStart, int fEnd) {
  static int iInitialized = 0;
  int iRandNum = 0;
  if (0 == iInitialized) {
    srand(SYS_GetSeed());
    iInitialized = 1;
  }
  if (-1 == fEnd)
    iRandNum = rand();
  else
    iRandNum = ((rand() + 0.0) / RAND_MAX * (fEnd - fStart)) + fStart;
  return iRandNum;
}


x86 assembly (clang, -O0):
<SYS_RandomInt>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
xor    %eax,%eax
cmp    0x2ef3(%rip),%eax
jne    116b <SYS_RandomInt+0x3b>
mov    $0x0,%al
call   1030 <SYS_GetSeed@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movl   $0x1,0x2ed5(%rip)
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    118c <SYS_RandomInt+0x5c>
mov    $0x0,%al
call   1050 <rand@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
jmp    11c3 <SYS_RandomInt+0x93>
mov    $0x0,%al
call   1050 <rand@plt>
xorps  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mov    0x2e47(%rip),%rax
divsd  (%rax),%xmm0
mov    -0x8(%rbp),%eax
sub    -0x4(%rbp),%eax
cvtsi2sd %eax,%xmm2
cvtsi2sdl -0x4(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SYS_RandomInt>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
cmpb   $0x0,0x2f02(%rip)
jne    1155 <SYS_RandomInt+0x25>
xor    %eax,%eax
call   1030 <SYS_GetSeed@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movb   $0x1,0x2eeb(%rip)
xor    %eax,%eax
call   1050 <rand@plt>
cmp    $0xffffffff,%ebp
je     118c <SYS_RandomInt+0x5c>
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mov    0x2e78(%rip),%rax
divsd  (%rax),%xmm0
sub    %ebx,%ebp
xorps  %xmm1,%xmm1
cvtsi2sd %ebp,%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SYS_RandomInt.iInitialized = internal global i32 0
@RAND_MAX = global double 0.000000e+00
define hidden i32 @SYS_RandomInt(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
%6 = load i32, i32* @SYS_RandomInt.iInitialized
%7 = icmp eq i32 0, %6
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 (...) @SYS_GetSeed()
%10 = call i32 @srand(i32 %9)
store i32 1, i32* @SYS_RandomInt.iInitialized
br label %11
11: ; preds = %8, %2
%12 = load i32, i32* %4
%13 = icmp eq i32 -1, %12
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call double (...) @rand()
%16 = fptosi double %15 to i32
store i32 %16, i32* %5
br label %30
17: ; preds = %11
%18 = call double (...) @rand()
%19 = fadd double %18, 0.000000e+00
%20 = load double, double* @RAND_MAX
%21 = fdiv double %19, %20
%22 = load i32, i32* %4
%23 = load i32, i32* %3
%24 = sub nsw i32 %22, %23
%25 = sitofp i32 %24 to double
%26 = load i32, i32* %3
%27 = sitofp i32 %26 to double
%28 = call double @llvm.fmuladd.f64(double %21, double %25, double %27)
%29 = fptosi double %28 to i32
store i32 %29, i32* %5
br label %30
30: ; preds = %17, %14
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
@SYS_RandomInt.iInitialized = internal unnamed_addr global i1 false
@RAND_MAX = global double 0.000000e+00
define hidden i32 @SYS_RandomInt(i32 %0, i32 %1) {
%3 = load i1, i1* @SYS_RandomInt.iInitialized
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = tail call i32 (...) @SYS_GetSeed()
%6 = tail call i32 @srand(i32 %5)
store i1 true, i1* @SYS_RandomInt.iInitialized
br label %7
7: ; preds = %4, %2
%8 = icmp eq i32 %1, -1
%9 = tail call double (...) @rand()
br i1 %8, label %18, label %10
10: ; preds = %7
%11 = fadd double %9, 0.000000e+00
%12 = load double, double* @RAND_MAX
%13 = fdiv double %11, %12
%14 = sub nsw i32 %1, %0
%15 = sitofp i32 %14 to double
%16 = sitofp i32 %0 to double
%17 = tail call double @llvm.fmuladd.f64(double %13, double %15, double %16)
br label %18
18: ; preds = %7, %10
%19 = phi double [ %17, %10 ], [ %9, %7 ]
%20 = fptosi double %19 to i32
ret i32 %20
}