#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 */
double log(double);
double StatEntropyFloat(float a[], int n, int s) {
  int i;
  float *p = a;
  double val;
  double entropy = 0;
  for (i = 0; i < n; i++) {
    val = (double)*p;
    entropy += val * log(val);
    p += s;
  }
  return entropy;
}


x86 assembly (clang, -O0):
<StatEntropyFloat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a7 <StatEntropyFloat+0x97>
mov    -0x20(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
shl    $0x2,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <StatEntropyFloat+0x29>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StatEntropyFloat>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    116b <StatEntropyFloat+0x5b>
mov    %esi,%ebp
mov    %rdi,%rbx
movslq %edx,%r14
shl    $0x2,%r14
xorps  %xmm0,%xmm0
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movss  (%rbx),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
call   1030 <log@plt>
mulsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  (%rsp),%xmm0
add    %r14,%rbx
add    $0xffffffff,%ebp
jne    1130 <StatEntropyFloat+0x20>
jmp    116e <StatEntropyFloat+0x5e>
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define double @StatEntropyFloat(float* %0, i32 %1, i32 %2) {
%4 = alloca float*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca float*
%9 = alloca double
%10 = alloca double
store float* %0, float** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load float*, float** %4
store float* %11, float** %8
store double 0.000000e+00, double* %10
store i32 0, i32* %7
br label %12
12: ; preds = %29, %3
%13 = load i32, i32* %7
%14 = load i32, i32* %5
%15 = icmp slt i32 %13, %14
br i1 %15, label %16, label %32
16: ; preds = %12
%17 = load float*, float** %8
%18 = load float, float* %17
%19 = fpext float %18 to double
store double %19, double* %9
%20 = load double, double* %9
%21 = load double, double* %9
%22 = call double @log(double %21)
%23 = load double, double* %10
%24 = call double @llvm.fmuladd.f64(double %20, double %22, double %23)
store double %24, double* %10
%25 = load i32, i32* %6
%26 = load float*, float** %8
%27 = sext i32 %25 to i64
%28 = getelementptr inbounds float, float* %26, i64 %27
store float* %28, float** %8
br label %29
29: ; preds = %16
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %12
32: ; preds = %12
%33 = load double, double* %10
ret double %33
}

LLVM IR (-O2):
define double @StatEntropyFloat(float* nocapture %0, i32 %1, i32 %2) {
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %18
5: ; preds = %3
%6 = sext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi double [ 0.000000e+00, %5 ], [ %14, %7 ]
%9 = phi i32 [ 0, %5 ], [ %16, %7 ]
%10 = phi float* [ %0, %5 ], [ %15, %7 ]
%11 = load float, float* %10
%12 = fpext float %11 to double
%13 = tail call double @log(double %12)
%14 = tail call double @llvm.fmuladd.f64(double %12, double %13, double %8)
%15 = getelementptr inbounds float, float* %10, i64 %6
%16 = add nuw nsw i32 %9, 1
%17 = icmp eq i32 %16, %1
br i1 %17, label %18, label %7
18: ; preds = %7, %3
%19 = phi double [ 0.000000e+00, %3 ], [ %14, %7 ]
ret double %19
}