#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;
scalar_t__ malloc(int const);
double rand();
int *vrandi(const int low, const int high, const int n) {
  if (n < 1)
    return (0);
  int *result = (int *)malloc(n * sizeof(int));
  for (int i = 0; i < n; ++i)
    result[i] = (high - low + 1) * (rand() / (RAND_MAX + 1.0)) + low;
  return (result);
}


x86 assembly (clang, -O0):
<vrandi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    1148 <vrandi+0x28>
movq   $0x0,-0x8(%rbp)
jmp    11d8 <vrandi+0xb8>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d0 <vrandi+0xb0>
mov    -0x10(%rbp),%eax
sub    -0xc(%rbp),%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
movaps %xmm0,%xmm2
movsd  -0x30(%rbp),%xmm0
movsd  0xe69(%rip),%xmm1
mov    0x2e4a(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%xmm2
cvtsi2sdl -0xc(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1162 <vrandi+0x42>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<vrandi>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
test   %edx,%edx
jle    11b6 <vrandi+0x96>
mov    %edx,%r14d
mov    %esi,%ebp
mov    %edi,%r15d
lea    0x0(,%r14,4),%edi
call   1030 <malloc@plt>
mov    %rax,%r12
sub    %r15d,%ebp
add    $0x1,%ebp
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
movsd  %xmm0,(%rsp)
mov    %r14d,%ebp
mov    0x2e75(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <rand@plt>
movsd  (%r14),%xmm1
addsd  0xe6c(%rip),%xmm1
divsd  %xmm1,%xmm0
mulsd  0x8(%rsp),%xmm0
addsd  (%rsp),%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1180 <vrandi+0x60>
jmp    11b9 <vrandi+0x99>
xor    %r12d,%r12d
mov    %r12,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global double 0.000000e+00
define i32* @vrandi(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %3
store i32* null, i32** %4
br label %47
13: ; preds = %3
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = mul i64 %15, 4
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i32*
store i32* %19, i32** %8
store i32 0, i32* %9
br label %20
20: ; preds = %42, %13
%21 = load i32, i32* %9
%22 = load i32, i32* %7
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %45
24: ; preds = %20
%25 = load i32, i32* %6
%26 = load i32, i32* %5
%27 = sub nsw i32 %25, %26
%28 = add nsw i32 %27, 1
%29 = sitofp i32 %28 to double
%30 = call double (...) @rand()
%31 = load double, double* @RAND_MAX
%32 = fadd double %31, 1.000000e+00
%33 = fdiv double %30, %32
%34 = load i32, i32* %5
%35 = sitofp i32 %34 to double
%36 = call double @llvm.fmuladd.f64(double %29, double %33, double %35)
%37 = fptosi double %36 to i32
%38 = load i32*, i32** %8
%39 = load i32, i32* %9
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %37, i32* %41
br label %42
42: ; preds = %24
%43 = load i32, i32* %9
%44 = add nsw i32 %43, 1
store i32 %44, i32* %9
br label %20
45: ; preds = %20
%46 = load i32*, i32** %8
store i32* %46, i32** %4
br label %47
47: ; preds = %45, %12
%48 = load i32*, i32** %4
ret i32* %48
}

LLVM IR (-O2):
@RAND_MAX = global double 0.000000e+00
define i32* @vrandi(i32 %0, i32 %1, i32 %2) {
%4 = icmp slt i32 %2, 1
br i1 %4, label %25, label %5
5: ; preds = %3
%6 = shl i32 %2, 2
%7 = tail call i64 @malloc(i32 %6)
%8 = inttoptr i64 %7 to i32*
%9 = sub i32 1, %0
%10 = add i32 %9, %1
%11 = sitofp i32 %10 to double
%12 = sitofp i32 %0 to double
%13 = zext i32 %2 to i64
br label %14
14: ; preds = %5, %14
%15 = phi i64 [ 0, %5 ], [ %23, %14 ]
%16 = tail call double (...) @rand()
%17 = load double, double* @RAND_MAX
%18 = fadd double %17, 1.000000e+00
%19 = fdiv double %16, %18
%20 = tail call double @llvm.fmuladd.f64(double %11, double %19, double %12)
%21 = fptosi double %20 to i32
%22 = getelementptr inbounds i32, i32* %8, i64 %15
store i32 %21, i32* %22
%23 = add nuw nsw i64 %15, 1
%24 = icmp eq i64 %23, %13
br i1 %24, label %25, label %14
25: ; preds = %14, %3
%26 = phi i32* [ null, %3 ], [ %8, %14 ]
ret i32* %26
}