#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 */
int RAND_MAX;
int *malloc(int);
scalar_t__ rand();
int *rendrv(int maxisz, int vsz) {
  int i, *v = malloc(vsz * sizeof(int));
  for (i = 0; i < vsz; ++i)
    v[i] = (int)(maxisz * (float)rand() / RAND_MAX);
  return v;
}


x86 assembly (clang, -O0):
<rendrv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    119f <rendrv+0x7f>
cvtsi2ssl -0x4(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    $0x0,%al
call   1040 <rand@plt>
movss  -0x1c(%rbp),%xmm0
cvtsi2ss %rax,%xmm1
mulss  %xmm1,%xmm0
mov    0x2e6e(%rip),%rax
cvtsi2ssl (%rax),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%edx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1148 <rendrv+0x28>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rendrv>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x0(,%r14,4),%edi
call   1030 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    1192 <rendrv+0x72>
cvtsi2ss %ebp,%xmm0
movss  %xmm0,0x4(%rsp)
mov    %r14d,%ebp
mov    0x2e93(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
xorps  %xmm1,%xmm1
cvtsi2ssl (%r14),%xmm1
mulss  0x4(%rsp),%xmm0
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <rendrv+0x40>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@RAND_MAX = global i32 0
define i32* @rendrv(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
store i32 %0, i32* %3
store i32 %1, i32* %4
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = mul i64 %8, 4
%10 = trunc i64 %9 to i32
%11 = call i32* @malloc(i32 %10)
store i32* %11, i32** %6
store i32 0, i32* %5
br label %12
12: ; preds = %30, %2
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %33
16: ; preds = %12
%17 = load i32, i32* %3
%18 = sitofp i32 %17 to float
%19 = call i64 (...) @rand()
%20 = sitofp i64 %19 to float
%21 = fmul float %18, %20
%22 = load i32, i32* @RAND_MAX
%23 = sitofp i32 %22 to float
%24 = fdiv float %21, %23
%25 = fptosi float %24 to i32
%26 = load i32*, i32** %6
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
store i32 %25, i32* %29
br label %30
30: ; preds = %16
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %12
33: ; preds = %12
%34 = load i32*, i32** %6
ret i32* %34
}

LLVM IR (-O2):
@RAND_MAX = global i32 0
define noalias i32* @rendrv(i32 %0, i32 %1) {
%3 = shl i32 %1, 2
%4 = tail call i32* @malloc(i32 %3)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = sitofp i32 %0 to float
%8 = zext i32 %1 to i64
br label %9
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %19, %9 ]
%11 = tail call i64 (...) @rand()
%12 = sitofp i64 %11 to float
%13 = fmul float %7, %12
%14 = load i32, i32* @RAND_MAX
%15 = sitofp i32 %14 to float
%16 = fdiv float %13, %15
%17 = fptosi float %16 to i32
%18 = getelementptr inbounds i32, i32* %4, i64 %10
store i32 %17, i32* %18
%19 = add nuw nsw i64 %10, 1
%20 = icmp eq i64 %19, %8
br i1 %20, label %21, label %9
21: ; preds = %9, %2
ret i32* %4
}