#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 */
struct timespec {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC_RAW;
double RAND_MAX;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ elapsed_time_hr(struct timespec, struct timespec, char *);
int /*<<< orphan*/ free(float *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ rand();
int /*<<< orphan*/ rapl_deinit();
int /*<<< orphan*/ rapl_end();
int /*<<< orphan*/ rapl_init();
int /*<<< orphan*/ rapl_start();
int /*<<< orphan*/ srand(int);
scalar_t__ time(int /*<<< orphan*/ *);
int float_scalar_mult(unsigned int size) {
  int i;
  float *v = (float *)malloc(size * sizeof(float));
  float a = 0.0;
  if (v == NULL) {
    printf("Out Of Memory: could not allocate space for the array.\n");
    return 0;
  }
  srand((int)time(NULL));
  struct timespec start, end;
  for (i = 0; i < size; i++) {
    v[i] = (float)rand() / (float)(RAND_MAX / 10.0);
  }
  a = (float)rand() / (float)(RAND_MAX / 10.0);
  rapl_init();
  rapl_start();
  clock_gettime(CLOCK_MONOTONIC_RAW, &start);
  for (i = 0; i < size; i++) {
    v[i] = a * v[i];
  }
  clock_gettime(CLOCK_MONOTONIC_RAW, &end);
  rapl_end();
  rapl_deinit();
  printf("Scalar product result: %f\n", v[0]);
  elapsed_time_hr(start, end, "Float scalar multiplication.");
  free(v);
  return 0;
}


x86 assembly (clang, -O0):
<float_scalar_mult>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
shl    $0x2,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
xorps  %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    120a <float_scalar_mult+0x4a>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    135f <float_scalar_mult+0x19f>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <time@plt>
mov    %eax,%edi
call   1080 <srand@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1273 <float_scalar_mult+0xb3>
mov    $0x0,%al
call   10e0 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2da8(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xdb4(%rip),%xmm2
divsd  %xmm2,%xmm1
cvtsd2ss %xmm1,%xmm1
divss  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1221 <float_scalar_mult+0x61>
mov    $0x0,%al
call   10e0 <rand@plt>
cvtsi2ss %rax,%xmm0
mov    0x2d62(%rip),%rax
movsd  (%rax),%xmm1
movsd  0xd6e(%rip),%xmm2
divsd  %xmm2,%xmm1
cvtsd2ss %xmm1,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    $0x0,%al
call   10c0 <rapl_init@plt>
mov    $0x0,%al
call   1070 <rapl_start@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1050 <clock_gettime@plt>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jae    1303 <float_scalar_mult+0x143>
movss  -0x1c(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mulss  (%rax,%rcx,4),%xmm0
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
movss  %xmm0,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    12ca <float_scalar_mult+0x10a>
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
lea    -0x28(%rbp),%rsi
call   1050 <clock_gettime@plt>
mov    $0x0,%al
call   10b0 <rapl_end@plt>
mov    $0x0,%al
call   10d0 <rapl_deinit@plt>
mov    -0x18(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xd0a(%rip),%rdi
mov    $0x1,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%edi
mov    -0x28(%rbp),%esi
lea    0xd11(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float_scalar_mult>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %edi,%r14d
lea    0x0(,%r14,4),%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     12c5 <float_scalar_mult+0xf5>
mov    %rax,%rbp
xor    %edi,%edi
call   10a0 <time@plt>
mov    %eax,%edi
call   1090 <srand@plt>
mov    %r14d,%r12d
test   %r14d,%r14d
je     1253 <float_scalar_mult+0x83>
mov    0x2dd1(%rip),%r15
xor    %ebx,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   10f0 <rand@plt>
xorps  %xmm0,%xmm0
cvtsi2ss %rax,%xmm0
movsd  (%r15),%xmm1
divsd  0xdc4(%rip),%xmm1
cvtsd2ss %xmm1,%xmm1
divss  %xmm1,%xmm0
movss  %xmm0,0x0(%rbp,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1220 <float_scalar_mult+0x50>
xor    %eax,%eax
call   10f0 <rand@plt>
mov    %rax,%r15
mov    0x2d84(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,0x10(%rsp)
xor    %eax,%eax
call   10d0 <rapl_init@plt>
xor    %eax,%eax
call   1080 <rapl_start@plt>
mov    0x2d5d(%rip),%r13
mov    0x0(%r13),%edi
lea    0x8(%rsp),%rsi
call   1060 <clock_gettime@plt>
test   %r14d,%r14d
je     1399 <float_scalar_mult+0x1c9>
xorps  %xmm0,%xmm0
cvtsi2ss %r15,%xmm0
movsd  0x10(%rsp),%xmm1
divsd  0xd50(%rip),%xmm1
cvtsd2ss %xmm1,%xmm1
divss  %xmm1,%xmm0
cmp    $0x8,%r14d
jae    12d6 <float_scalar_mult+0x106>
xor    %eax,%eax
jmp    1380 <float_scalar_mult+0x1b0>
lea    0xd74(%rip),%rdi
call   1050 <puts@plt>
jmp    13e5 <float_scalar_mult+0x215>
mov    %r12d,%eax
and    $0xfffffff8,%eax
movaps %xmm0,%xmm1
shufps $0x0,%xmm0,%xmm1
lea    -0x8(%rax),%rcx
mov    %rcx,%rdx
shr    $0x3,%rdx
add    $0x1,%rdx
test   %rcx,%rcx
je     13f6 <float_scalar_mult+0x226>
mov    %rdx,%rsi
and    $0xfffffffffffffffe,%rsi
xor    %ecx,%ecx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movups 0x0(%rbp,%rcx,4),%xmm2
movups 0x10(%rbp,%rcx,4),%xmm3
movups 0x20(%rbp,%rcx,4),%xmm4
movups 0x30(%rbp,%rcx,4),%xmm5
mulps  %xmm1,%xmm2
mulps  %xmm1,%xmm3
movups %xmm2,0x0(%rbp,%rcx,4)
movups %xmm3,0x10(%rbp,%rcx,4)
mulps  %xmm1,%xmm4
mulps  %xmm1,%xmm5
movups %xmm4,0x20(%rbp,%rcx,4)
movups %xmm5,0x30(%rbp,%rcx,4)
add    $0x10,%rcx
add    $0xfffffffffffffffe,%rsi
jne    1310 <float_scalar_mult+0x140>
test   $0x1,%dl
je     136d <float_scalar_mult+0x19d>
movups 0x0(%rbp,%rcx,4),%xmm2
movups 0x10(%rbp,%rcx,4),%xmm3
mulps  %xmm1,%xmm2
mulps  %xmm1,%xmm3
movups %xmm2,0x0(%rbp,%rcx,4)
movups %xmm3,0x10(%rbp,%rcx,4)
cmp    %r12,%rax
je     1399 <float_scalar_mult+0x1c9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movss  0x0(%rbp,%rax,4),%xmm1
mulss  %xmm0,%xmm1
movss  %xmm1,0x0(%rbp,%rax,4)
add    $0x1,%rax
cmp    %rax,%r12
jne    1380 <float_scalar_mult+0x1b0>
mov    0x0(%r13),%edi
mov    %rsp,%rsi
call   1060 <clock_gettime@plt>
xor    %eax,%eax
call   10c0 <rapl_end@plt>
xor    %eax,%eax
call   10e0 <rapl_deinit@plt>
movss  0x0(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xc45(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    0x8(%rsp),%edi
mov    (%rsp),%esi
lea    0xc4b(%rip),%rdx
call   1030 <elapsed_time_hr@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ecx,%ecx
test   $0x1,%dl
jne    1353 <float_scalar_mult+0x183>
jmp    136d <float_scalar_mult+0x19d>

LLVM IR (-O0):
%struct.timespec = type { i32 }
@.str = [56 x i8] c"Out Of Memory: could not allocate space for the array.\0A\00"
@RAND_MAX = global double 0.000000e+00
@CLOCK_MONOTONIC_RAW = global i32 0
@.str.1 = [27 x i8] c"Scalar product result: %f\0A\00"
@.str.2 = [29 x i8] c"Float scalar multiplication.\00"
define i32 @float_scalar_mult(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca float*
%6 = alloca float
%7 = alloca %struct.timespec
%8 = alloca %struct.timespec
store i32 %0, i32* %3
%9 = load i32, i32* %3
%10 = zext i32 %9 to i64
%11 = mul i64 %10, 4
%12 = trunc i64 %11 to i32
%13 = call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to float*
store float* %14, float** %5
store float 0.000000e+00, float* %6
%15 = load float*, float** %5
%16 = icmp eq float* %15, null
br i1 %16, label %17, label %19
17: ; preds = %1
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %88
19: ; preds = %1
%20 = call i64 @time(i32* null)
%21 = trunc i64 %20 to i32
%22 = call i32 @srand(i32 %21)
store i32 0, i32* %4
br label %23
23: ; preds = %38, %19
%24 = load i32, i32* %4
%25 = load i32, i32* %3
%26 = icmp ult i32 %24, %25
br i1 %26, label %27, label %41
27: ; preds = %23
%28 = call i64 (...) @rand()
%29 = sitofp i64 %28 to float
%30 = load double, double* @RAND_MAX
%31 = fdiv double %30, 1.000000e+01
%32 = fptrunc double %31 to float
%33 = fdiv float %29, %32
%34 = load float*, float** %5
%35 = load i32, i32* %4
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds float, float* %34, i64 %36
store float %33, float* %37
br label %38
38: ; preds = %27
%39 = load i32, i32* %4
%40 = add nsw i32 %39, 1
store i32 %40, i32* %4
br label %23
41: ; preds = %23
%42 = call i64 (...) @rand()
%43 = sitofp i64 %42 to float
%44 = load double, double* @RAND_MAX
%45 = fdiv double %44, 1.000000e+01
%46 = fptrunc double %45 to float
%47 = fdiv float %43, %46
store float %47, float* %6
%48 = call i32 (...) @rapl_init()
%49 = call i32 (...) @rapl_start()
%50 = load i32, i32* @CLOCK_MONOTONIC_RAW
%51 = call i32 @clock_gettime(i32 %50, %struct.timespec* %7)
store i32 0, i32* %4
br label %52
52: ; preds = %68, %41
%53 = load i32, i32* %4
%54 = load i32, i32* %3
%55 = icmp ult i32 %53, %54
br i1 %55, label %56, label %71
56: ; preds = %52
%57 = load float, float* %6
%58 = load float*, float** %5
%59 = load i32, i32* %4
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds float, float* %58, i64 %60
%62 = load float, float* %61
%63 = fmul float %57, %62
%64 = load float*, float** %5
%65 = load i32, i32* %4
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds float, float* %64, i64 %66
store float %63, float* %67
br label %68
68: ; preds = %56
%69 = load i32, i32* %4
%70 = add nsw i32 %69, 1
store i32 %70, i32* %4
br label %52
71: ; preds = %52
%72 = load i32, i32* @CLOCK_MONOTONIC_RAW
%73 = call i32 @clock_gettime(i32 %72, %struct.timespec* %8)
%74 = call i32 (...) @rapl_end()
%75 = call i32 (...) @rapl_deinit()
%76 = load float*, float** %5
%77 = getelementptr inbounds float, float* %76, i64 0
%78 = load float, float* %77
%79 = fpext float %78 to double
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %79)
%81 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%82 = load i32, i32* %81
%83 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%84 = load i32, i32* %83
%85 = call i32 @elapsed_time_hr(i32 %82, i32 %84, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%86 = load float*, float** %5
%87 = call i32 @free(float* %86)
store i32 0, i32* %2
br label %88
88: ; preds = %71, %17
%89 = load i32, i32* %2
ret i32 %89
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
@RAND_MAX = global double 0.000000e+00
@CLOCK_MONOTONIC_RAW = global i32 0
@.str.1 = [27 x i8] c"Scalar product result: %f\0A\00"
@.str.2 = [29 x i8] c"Float scalar multiplication.\00"
@str = [55 x i8] c"Out Of Memory: could not allocate space for the array.\00"
define i32 @float_scalar_mult(i32 %0) {
%2 = alloca %struct.timespec
%3 = alloca %struct.timespec
%4 = shl i32 %0, 2
%5 = tail call i64 @malloc(i32 %4)
%6 = inttoptr i64 %5 to float*
%7 = icmp eq i64 %5, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
br label %123
10: ; preds = %1
%11 = tail call i64 @time(i32* null)
%12 = trunc i64 %11 to i32
%13 = tail call i32 @srand(i32 %12)
%14 = bitcast %struct.timespec* %2 to i8*
%15 = bitcast %struct.timespec* %3 to i8*
%16 = icmp eq i32 %0, 0
br i1 %16, label %30, label %17
17: ; preds = %10
%18 = zext i32 %0 to i64
br label %19
19: ; preds = %17, %19
%20 = phi i64 [ 0, %17 ], [ %28, %19 ]
%21 = tail call i64 (...) @rand()
%22 = sitofp i64 %21 to float
%23 = load double, double* @RAND_MAX
%24 = fdiv double %23, 1.000000e+01
%25 = fptrunc double %24 to float
%26 = fdiv float %22, %25
%27 = getelementptr inbounds float, float* %6, i64 %20
store float %26, float* %27
%28 = add nuw nsw i64 %20, 1
%29 = icmp eq i64 %28, %18
br i1 %29, label %30, label %19
30: ; preds = %19, %10
%31 = tail call i64 (...) @rand()
%32 = sitofp i64 %31 to float
%33 = load double, double* @RAND_MAX
%34 = fdiv double %33, 1.000000e+01
%35 = fptrunc double %34 to float
%36 = fdiv float %32, %35
%37 = tail call i32 (...) @rapl_init()
%38 = tail call i32 (...) @rapl_start()
%39 = load i32, i32* @CLOCK_MONOTONIC_RAW
%40 = call i32 @clock_gettime(i32 %39, %struct.timespec* %2)
br i1 %16, label %109, label %41
41: ; preds = %30
%42 = zext i32 %0 to i64
%43 = icmp ult i32 %0, 8
br i1 %43, label %100, label %44
44: ; preds = %41
%45 = and i64 %42, 4294967288
%46 = insertelement <4 x float> poison, float %36, i64 0
%47 = shufflevector <4 x float> %46, <4 x float> poison, <4 x i32> zeroinitializer
%48 = insertelement <4 x float> poison, float %36, i64 0
%49 = shufflevector <4 x float> %48, <4 x float> poison, <4 x i32> zeroinitializer
%50 = add nsw i64 %45, -8
%51 = lshr exact i64 %50, 3
%52 = add nuw nsw i64 %51, 1
%53 = and i64 %52, 1
%54 = icmp eq i64 %50, 0
br i1 %54, label %84, label %55
55: ; preds = %44
%56 = and i64 %52, 4611686018427387902
br label %57
57: ; preds = %57, %55
%58 = phi i64 [ 0, %55 ], [ %81, %57 ]
%59 = phi i64 [ 0, %55 ], [ %82, %57 ]
%60 = getelementptr inbounds float, float* %6, i64 %58
%61 = bitcast float* %60 to <4 x float>*
%62 = load <4 x float>, <4 x float>* %61
%63 = getelementptr inbounds float, float* %60, i64 4
%64 = bitcast float* %63 to <4 x float>*
%65 = load <4 x float>, <4 x float>* %64
%66 = fmul <4 x float> %47, %62
%67 = fmul <4 x float> %49, %65
%68 = bitcast float* %60 to <4 x float>*
store <4 x float> %66, <4 x float>* %68
%69 = bitcast float* %63 to <4 x float>*
store <4 x float> %67, <4 x float>* %69
%70 = or i64 %58, 8
%71 = getelementptr inbounds float, float* %6, i64 %70
%72 = bitcast float* %71 to <4 x float>*
%73 = load <4 x float>, <4 x float>* %72
%74 = getelementptr inbounds float, float* %71, i64 4
%75 = bitcast float* %74 to <4 x float>*
%76 = load <4 x float>, <4 x float>* %75
%77 = fmul <4 x float> %47, %73
%78 = fmul <4 x float> %49, %76
%79 = bitcast float* %71 to <4 x float>*
store <4 x float> %77, <4 x float>* %79
%80 = bitcast float* %74 to <4 x float>*
store <4 x float> %78, <4 x float>* %80
%81 = add nuw i64 %58, 16
%82 = add i64 %59, 2
%83 = icmp eq i64 %82, %56
br i1 %83, label %84, label %57
84: ; preds = %57, %44
%85 = phi i64 [ 0, %44 ], [ %81, %57 ]
%86 = icmp eq i64 %53, 0
br i1 %86, label %98, label %87
87: ; preds = %84
%88 = getelementptr inbounds float, float* %6, i64 %85
%89 = bitcast float* %88 to <4 x float>*
%90 = load <4 x float>, <4 x float>* %89
%91 = getelementptr inbounds float, float* %88, i64 4
%92 = bitcast float* %91 to <4 x float>*
%93 = load <4 x float>, <4 x float>* %92
%94 = fmul <4 x float> %47, %90
%95 = fmul <4 x float> %49, %93
%96 = bitcast float* %88 to <4 x float>*
store <4 x float> %94, <4 x float>* %96
%97 = bitcast float* %91 to <4 x float>*
store <4 x float> %95, <4 x float>* %97
br label %98
98: ; preds = %84, %87
%99 = icmp eq i64 %45, %42
br i1 %99, label %109, label %100
100: ; preds = %41, %98
%101 = phi i64 [ 0, %41 ], [ %45, %98 ]
br label %102
102: ; preds = %100, %102
%103 = phi i64 [ %107, %102 ], [ %101, %100 ]
%104 = getelementptr inbounds float, float* %6, i64 %103
%105 = load float, float* %104
%106 = fmul float %36, %105
store float %106, float* %104
%107 = add nuw nsw i64 %103, 1
%108 = icmp eq i64 %107, %42
br i1 %108, label %109, label %102
109: ; preds = %102, %98, %30
%110 = load i32, i32* @CLOCK_MONOTONIC_RAW
%111 = call i32 @clock_gettime(i32 %110, %struct.timespec* %3)
%112 = call i32 (...) @rapl_end()
%113 = call i32 (...) @rapl_deinit()
%114 = load float, float* %6
%115 = fpext float %114 to double
%116 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %115)
%117 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%118 = load i32, i32* %117
%119 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%120 = load i32, i32* %119
%121 = call i32 @elapsed_time_hr(i32 %118, i32 %120, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%122 = call i32 @free(float* %6)
br label %123
123: ; preds = %109, %8
ret i32 0
}