#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 */
scalar_t__ RAND_MAX;
int /*<<< orphan*/ printf(char *, int);
scalar_t__ rand();
void RangedRandDemo(int range_min, int range_max, int n) {
  int i;
  for (i = 0; i < n; i++) {
    int u = (double)rand() / ((long)RAND_MAX + 1) * (range_max - range_min) +
            range_min;
    printf("%10d\n", u);
  }
}


x86 assembly (clang, -O0):
<RangedRandDemo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a2 <RangedRandDemo+0x82>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2sd %rax,%xmm0
mov    0x2e91(%rip),%rax
mov    (%rax),%rax
add    $0x1,%rax
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%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,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe71(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1138 <RangedRandDemo+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<RangedRandDemo>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %edx,%edx
jle    119e <RangedRandDemo+0x7e>
mov    %edx,%ebx
sub    %edi,%esi
cvtsi2sd %esi,%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %edi,%xmm0
movsd  %xmm0,(%rsp)
mov    0x2e9a(%rip),%r15
lea    0xeab(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    (%r15),%rax
add    $0x1,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  %xmm1,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
cvttsd2si %xmm0,%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffff,%ebx
jne    1160 <RangedRandDemo+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@RAND_MAX = global i64 0
@.str = [6 x i8] c"%10d\0A\00"
define void @RangedRandDemo(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %30, %3
%10 = load i32, i32* %7
%11 = load i32, i32* %6
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %33
13: ; preds = %9
%14 = call i64 (...) @rand()
%15 = sitofp i64 %14 to double
%16 = load i64, i64* @RAND_MAX
%17 = add nsw i64 %16, 1
%18 = sitofp i64 %17 to double
%19 = fdiv double %15, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %4
%22 = sub nsw i32 %20, %21
%23 = sitofp i32 %22 to double
%24 = load i32, i32* %4
%25 = sitofp i32 %24 to double
%26 = call double @llvm.fmuladd.f64(double %19, double %23, double %25)
%27 = fptosi double %26 to i32
store i32 %27, i32* %8
%28 = load i32, i32* %8
%29 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %13
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %9
33: ; preds = %9
ret void
}

LLVM IR (-O2):
@RAND_MAX = global i64 0
@.str = [6 x i8] c"%10d\0A\00"
define void @RangedRandDemo(i32 %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %22
5: ; preds = %3
%6 = sub nsw i32 %1, %0
%7 = sitofp i32 %6 to double
%8 = sitofp i32 %0 to double
br label %9
9: ; preds = %5, %9
%10 = phi i32 [ 0, %5 ], [ %20, %9 ]
%11 = tail call i64 (...) @rand()
%12 = sitofp i64 %11 to double
%13 = load i64, i64* @RAND_MAX
%14 = add nsw i64 %13, 1
%15 = sitofp i64 %14 to double
%16 = fdiv double %12, %15
%17 = tail call double @llvm.fmuladd.f64(double %16, double %7, double %8)
%18 = fptosi double %17 to i32
%19 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %18)
%20 = add nuw nsw i32 %10, 1
%21 = icmp eq i32 %20, %2
br i1 %21, label %22, label %9
22: ; preds = %9, %3
ret void
}