#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;
double rand();
__attribute__((visibility("hidden"))) int SYS_RandomInt(int fStart, int fEnd) {
  int iRandNum = 0;
  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)
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    1146 <SYS_RandomInt+0x36>
mov    $0x0,%al
call   1030 <rand@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0xc(%rbp)
jmp    117d <SYS_RandomInt+0x6d>
mov    $0x0,%al
call   1030 <rand@plt>
xorps  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mov    0x2e8d(%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
xor    %eax,%eax
call   1030 <rand@plt>
cmp    $0xffffffff,%ebp
je     114e <SYS_RandomInt+0x3e>
xorpd  %xmm1,%xmm1
addsd  %xmm1,%xmm0
mov    0x2eb6(%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):
@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* %4
%7 = icmp eq i32 -1, %6
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call double (...) @rand()
%10 = fptosi double %9 to i32
store i32 %10, i32* %5
br label %24
11: ; preds = %2
%12 = call double (...) @rand()
%13 = fadd double %12, 0.000000e+00
%14 = load double, double* @RAND_MAX
%15 = fdiv double %13, %14
%16 = load i32, i32* %4
%17 = load i32, i32* %3
%18 = sub nsw i32 %16, %17
%19 = sitofp i32 %18 to double
%20 = load i32, i32* %3
%21 = sitofp i32 %20 to double
%22 = call double @llvm.fmuladd.f64(double %15, double %19, double %21)
%23 = fptosi double %22 to i32
store i32 %23, i32* %5
br label %24
24: ; preds = %11, %8
%25 = load i32, i32* %5
ret i32 %25
}

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