#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 StatEntropyDouble(double a[], int n, int s) {
  int i;
  double *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):
<StatEntropyDouble>:
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    11a3 <StatEntropyDouble+0x93>
mov    -0x20(%rbp),%rax
movsd  (%rax),%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    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1139 <StatEntropyDouble+0x29>
movsd  -0x30(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StatEntropyDouble>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %esi,%esi
jle    1167 <StatEntropyDouble+0x57>
mov    %esi,%ebp
mov    %rdi,%rbx
movslq %edx,%r14
shl    $0x3,%r14
xorps  %xmm0,%xmm0
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  (%rbx),%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 <StatEntropyDouble+0x20>
jmp    116a <StatEntropyDouble+0x5a>
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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