#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 entropy(double *bpr, int N) {
  double e;
  int j;
  e = 0;
  for (j = 0; j < N; j++) {
    if (bpr[j] > 0 && bpr[j] < 1) {
      e -= bpr[j] * log(bpr[j]) + (1 - bpr[j]) * log(1 - bpr[j]);
    }
  }
  return e / log(2.0);
}


x86 assembly (clang, -O0):
<entropy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    120b <entropy+0xfb>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11f8 <entropy+0xe8>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  0xea4(%rip),%xmm0
ucomisd (%rax,%rcx,8),%xmm0
jbe    11f8 <entropy+0xe8>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <log@plt>
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  0xe60(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  0xe46(%rip),%xmm0
subsd  (%rax,%rcx,8),%xmm0
call   1030 <log@plt>
movsd  -0x38(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movaps %xmm0,%xmm3
movsd  -0x28(%rbp),%xmm0
mulsd  %xmm3,%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11fd <entropy+0xed>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    112e <entropy+0x1e>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xde3(%rip),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<entropy>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
test   %esi,%esi
jle    11bb <entropy+0xab>
mov    %rdi,%r15
mov    %esi,%r14d
xorpd  %xmm1,%xmm1
xor    %ebx,%ebx
movsd  0xecb(%rip),%xmm2
xorpd  %xmm0,%xmm0
jmp    1149 <entropy+0x39>
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbx
cmp    %rbx,%r14
je     11bf <entropy+0xaf>
movsd  (%r15,%rbx,8),%xmm3
ucomisd %xmm1,%xmm3
jbe    1140 <entropy+0x30>
ucomisd %xmm3,%xmm2
jbe    1140 <entropy+0x30>
movsd  %xmm0,0x18(%rsp)
movapd %xmm3,%xmm0
movsd  %xmm3,0x10(%rsp)
call   1030 <log@plt>
movsd  %xmm0,0x8(%rsp)
movsd  0xe82(%rip),%xmm0
subsd  (%r15,%rbx,8),%xmm0
movsd  %xmm0,(%rsp)
call   1030 <log@plt>
movsd  0xe6a(%rip),%xmm2
xorpd  %xmm1,%xmm1
mulsd  (%rsp),%xmm0
movsd  0x8(%rsp),%xmm3
mulsd  0x10(%rsp),%xmm3
addsd  %xmm0,%xmm3
movsd  0x18(%rsp),%xmm0
subsd  %xmm3,%xmm0
jmp    1140 <entropy+0x30>
xorpd  %xmm0,%xmm0
divsd  0xe41(%rip),%xmm0
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @entropy(double* %0, i32 %1) {
%3 = alloca double*
%4 = alloca i32
%5 = alloca double
%6 = alloca i32
store double* %0, double** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %5
store i32 0, i32* %6
br label %7
7: ; preds = %55, %2
%8 = load i32, i32* %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %58
11: ; preds = %7
%12 = load double*, double** %3
%13 = load i32, i32* %6
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds double, double* %12, i64 %14
%16 = load double, double* %15
%17 = fcmp ogt double %16, 0.000000e+00
br i1 %17, label %18, label %54
18: ; preds = %11
%19 = load double*, double** %3
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = fcmp olt double %23, 1.000000e+00
br i1 %24, label %25, label %54
25: ; preds = %18
%26 = load double*, double** %3
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds double, double* %26, i64 %28
%30 = load double, double* %29
%31 = load double*, double** %3
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = call double @log(double %35)
%37 = load double*, double** %3
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds double, double* %37, i64 %39
%41 = load double, double* %40
%42 = fsub double 1.000000e+00, %41
%43 = load double*, double** %3
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = fsub double 1.000000e+00, %47
%49 = call double @log(double %48)
%50 = fmul double %42, %49
%51 = call double @llvm.fmuladd.f64(double %30, double %36, double %50)
%52 = load double, double* %5
%53 = fsub double %52, %51
store double %53, double* %5
br label %54
54: ; preds = %25, %18, %11
br label %55
55: ; preds = %54
%56 = load i32, i32* %6
%57 = add nsw i32 %56, 1
store i32 %57, i32* %6
br label %7
58: ; preds = %7
%59 = load double, double* %5
%60 = call double @log(double 2.000000e+00)
%61 = fdiv double %59, %60
ret double %61
}

LLVM IR (-O2):
define double @entropy(double* nocapture %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %26
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %6
6: ; preds = %4, %22
%7 = phi i64 [ 0, %4 ], [ %24, %22 ]
%8 = phi double [ 0.000000e+00, %4 ], [ %23, %22 ]
%9 = getelementptr inbounds double, double* %0, i64 %7
%10 = load double, double* %9
%11 = fcmp ogt double %10, 0.000000e+00
%12 = fcmp olt double %10, 1.000000e+00
%13 = and i1 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %6
%15 = tail call double @log(double %10)
%16 = load double, double* %9
%17 = fsub double 1.000000e+00, %16
%18 = tail call double @log(double %17)
%19 = fmul double %17, %18
%20 = tail call double @llvm.fmuladd.f64(double %10, double %15, double %19)
%21 = fsub double %8, %20
br label %22
22: ; preds = %6, %14
%23 = phi double [ %21, %14 ], [ %8, %6 ]
%24 = add nuw nsw i64 %7, 1
%25 = icmp eq i64 %24, %5
br i1 %25, label %26, label %6
26: ; preds = %22, %2
%27 = phi double [ 0.000000e+00, %2 ], [ %23, %22 ]
%28 = fdiv double %27, 0x3FE62E42FEFA39EF
ret double %28
}