#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 const log(double const);
double entropy_xlogx(const double *x, const double *pr, const double eps,
                     const int nx, const int ny, const double flux) {
  register int i;
  double ent = 0;
  for (i = 0; i < nx * ny; ++i) {
    if (x[i] > 1e-10)
      ent += x[i] * log(x[i]) - x[i];
  }
  return ent;
}


x86 assembly (clang, -O0):
<entropy_xlogx>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    -0x1c(%rbp),%ecx
imul   -0x20(%rbp),%ecx
cmp    %ecx,%eax
jge    11e5 <entropy_xlogx+0xd5>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe9a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d2 <entropy_xlogx+0xc2>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    11d7 <entropy_xlogx+0xc7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    113f <entropy_xlogx+0x2f>
movsd  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<entropy_xlogx>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
imul   %ecx,%edx
test   %edx,%edx
jle    1192 <entropy_xlogx+0x82>
mov    %rdi,%r15
mov    %edx,%r14d
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
movsd  0xecd(%rip),%xmm1
jmp    1149 <entropy_xlogx+0x39>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,%r14
je     1195 <entropy_xlogx+0x85>
movsd  (%r15,%rbx,8),%xmm2
ucomisd %xmm1,%xmm2
jbe    1140 <entropy_xlogx+0x30>
movsd  %xmm0,(%rsp)
movapd %xmm2,%xmm0
movsd  %xmm2,0x8(%rsp)
call   1030 <log@plt>
mulsd  0x8(%rsp),%xmm0
subsd  (%r15,%rbx,8),%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0xe75(%rip),%xmm1
movsd  (%rsp),%xmm0
jmp    1140 <entropy_xlogx+0x30>
xorps  %xmm0,%xmm0
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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