#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 ((int *)0);
  int *result = (int *)malloc(n * sizeof(int));
  (void)rand();
  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    11df <vrandi+0xbf>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d7 <vrandi+0xb7>
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  0xe62(%rip),%xmm1
mov    0x2e43(%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    1169 <vrandi+0x49>
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
xor    %eax,%eax
call   1040 <rand@plt>
sub    %r15d,%ebp
add    $0x1,%ebp
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  %xmm0,0x8(%rsp)
xorps  %xmm0,%xmm0
cvtsi2sd %r15d,%xmm0
movsd  %xmm0,(%rsp)
mov    %r14d,%ebp
mov    0x2e6b(%rip),%r14
xor    %ebx,%ebx
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 %48
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
%20 = call double (...) @rand()
store i32 0, i32* %9
br label %21
21: ; preds = %43, %13
%22 = load i32, i32* %9
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %46
25: ; preds = %21
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = sub nsw i32 %26, %27
%29 = add nsw i32 %28, 1
%30 = sitofp i32 %29 to double
%31 = call double (...) @rand()
%32 = load double, double* @RAND_MAX
%33 = fadd double %32, 1.000000e+00
%34 = fdiv double %31, %33
%35 = load i32, i32* %5
%36 = sitofp i32 %35 to double
%37 = call double @llvm.fmuladd.f64(double %30, double %34, double %36)
%38 = fptosi double %37 to i32
%39 = load i32*, i32** %8
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
store i32 %38, i32* %42
br label %43
43: ; preds = %25
%44 = load i32, i32* %9
%45 = add nsw i32 %44, 1
store i32 %45, i32* %9
br label %21
46: ; preds = %21
%47 = load i32*, i32** %8
store i32* %47, i32** %4
br label %48
48: ; preds = %46, %12
%49 = load i32*, i32** %4
ret i32* %49
}

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