#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__ malloc(int);
int rand();
int /*<<< orphan*/ srand(int);
float *create_rands(int num_elements, int max, int seed) {
  srand(seed);
  float *rands = (float *)malloc(sizeof(float) * num_elements);
  for (int i = 0; i < num_elements; i++) {
    rands[i] = rand() % max;
  }
  return rands;
}


x86 assembly (clang, -O0):
<create_rands>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <srand@plt>
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1199 <create_rands+0x69>
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0x8(%rbp)
cvtsi2ss %edx,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1163 <create_rands+0x33>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_rands>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %edi,%r14d
mov    %edx,%edi
call   1030 <srand@plt>
lea    0x0(,%r14,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r12
test   %r14d,%r14d
jle    1181 <create_rands+0x51>
mov    %r14d,%ebp
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1050 <rand@plt>
cltd
idiv   %r15d
xorps  %xmm0,%xmm0
cvtsi2ss %edx,%xmm0
movss  %xmm0,(%r12,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1160 <create_rands+0x30>
mov    %r12,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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