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


x86 assembly (clang, -O0):
<create_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movslq -0x4(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1183 <create_vector+0x63>
mov    $0x0,%al
call   1040 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2e84(%rip),%rax
divss  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1145 <create_vector+0x25>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_vector>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edi,%r14d
lea    0x0(,%r14,4),%edi
call   1030 <malloc@plt>
mov    %rax,%r15
test   %r14d,%r14d
jle    1173 <create_vector+0x53>
mov    %r14d,%r12d
mov    0x2e9e(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1040 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
divss  (%r14),%xmm0
movss  %xmm0,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <create_vector+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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