#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(long);
double omp_get_wtime();
int /*<<< orphan*/ printf(char *, double);
float rand();
int main(void) {
  float *data;
  long int n = 1000000;
  data = (float *)malloc(n * sizeof(float));
  double start = omp_get_wtime();
  int i;
  for (i = 0; i < n; ++i) {
    data[i] = rand() / 1000.0f;
  }
  printf("\tTempo Total  : %f \n", omp_get_wtime() - start);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0xf4240,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
shl    $0x2,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    11b7 <main+0x77>
mov    $0x0,%al
call   1060 <rand@plt>
movss  0xe68(%rip),%xmm1
divss  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117b <main+0x3b>
mov    $0x0,%al
call   1030 <omp_get_wtime@plt>
subsd  -0x20(%rbp),%xmm0
lea    0xe3a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x3d0900,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
movsd  %xmm0,(%rsp)
xor    %ebx,%ebx
nop
xor    %eax,%eax
call   1060 <rand@plt>
divss  0xe91(%rip),%xmm0
movss  %xmm0,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    $0xf4240,%rbx
jne    1160 <main+0x20>
xor    %eax,%eax
call   1030 <omp_get_wtime@plt>
subsd  (%rsp),%xmm0
lea    0xe6f(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [21 x i8] c"\09Tempo Total : %f \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca float*
%3 = alloca i64
%4 = alloca double
%5 = alloca i32
store i32 0, i32* %1
store i64 1000000, i64* %3
%6 = load i64, i64* %3
%7 = mul i64 %6, 4
%8 = call i64 @malloc(i64 %7)
%9 = inttoptr i64 %8 to float*
store float* %9, float** %2
%10 = call double (...) @omp_get_wtime()
store double %10, double* %4
store i32 0, i32* %5
br label %11
11: ; preds = %23, %0
%12 = load i32, i32* %5
%13 = sext i32 %12 to i64
%14 = load i64, i64* %3
%15 = icmp slt i64 %13, %14
br i1 %15, label %16, label %26
16: ; preds = %11
%17 = call float (...) @rand()
%18 = fdiv float %17, 1.000000e+03
%19 = load float*, float** %2
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds float, float* %19, i64 %21
store float %18, float* %22
br label %23
23: ; preds = %16
%24 = load i32, i32* %5
%25 = add nsw i32 %24, 1
store i32 %25, i32* %5
br label %11
26: ; preds = %11
%27 = call double (...) @omp_get_wtime()
%28 = load double, double* %4
%29 = fsub double %27, %28
%30 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %29)
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"\09Tempo Total : %f \0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i64 4000000)
%2 = inttoptr i64 %1 to float*
%3 = tail call double (...) @omp_get_wtime()
br label %4
4: ; preds = %0, %4
%5 = phi i64 [ 0, %0 ], [ %9, %4 ]
%6 = tail call float (...) @rand()
%7 = fdiv float %6, 1.000000e+03
%8 = getelementptr inbounds float, float* %2, i64 %5
store float %7, float* %8
%9 = add nuw nsw i64 %5, 1
%10 = icmp eq i64 %9, 1000000
br i1 %10, label %11, label %4
11: ; preds = %4
%12 = tail call double (...) @omp_get_wtime()
%13 = fsub double %12, %3
%14 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), double %13)
ret i32 0
}