#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 log10(double);
double f9_entropy(double **P, int Ng) {
  int i, j;
  double entropy = 0;
  for (i = 0; i < Ng; ++i)
    for (j = 0; j < Ng; ++j)
      entropy += P[i][j] * log10(P[i][j] + 0.000000001) / log10(2.0);
  return -entropy;
}


x86 assembly (clang, -O0):
<f9_entropy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11de <f9_entropy+0xce>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11cb <f9_entropy+0xbb>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
movsd  0xe89(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
call   1030 <log10@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe5e(%rip),%xmm0
call   1030 <log10@plt>
movaps %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1141 <f9_entropy+0x31>
jmp    11d0 <f9_entropy+0xc0>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    112e <f9_entropy+0x1e>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f9_entropy>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %esi,%esi
jle    11ac <f9_entropy+0x9c>
mov    %rdi,%r14
mov    %esi,%r15d
xorps  %xmm0,%xmm0
xor    %r12d,%r12d
movsd  0xec9(%rip),%xmm1
nopw   0x0(%rax,%rax,1)
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movaps %xmm0,(%rsp)
mov    (%r14,%r12,8),%rax
movsd  (%rax,%rbx,8),%xmm0
movsd  %xmm0,0x10(%rsp)
addsd  %xmm1,%xmm0
call   1030 <log10@plt>
movsd  0xe94(%rip),%xmm1
mulsd  0x10(%rsp),%xmm0
divsd  %xmm1,%xmm0
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movsd  0xe6c(%rip),%xmm1
movaps (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <f9_entropy+0x40>
add    $0x1,%r12
cmp    %r15,%r12
jne    1140 <f9_entropy+0x30>
jmp    11af <f9_entropy+0x9f>
xorps  %xmm0,%xmm0
xorps  0xe5a(%rip),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @f9_entropy(double** %0, i32 %1) {
%3 = alloca double**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
store double** %0, double*** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %7
store i32 0, i32* %5
br label %8
8: ; preds = %47, %2
%9 = load i32, i32* %5
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %50
12: ; preds = %8
store i32 0, i32* %6
br label %13
13: ; preds = %43, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %46
17: ; preds = %13
%18 = load double**, double*** %3
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double*, double** %18, i64 %20
%22 = load double*, double** %21
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds double, double* %22, i64 %24
%26 = load double, double* %25
%27 = load double**, double*** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double*, double** %27, i64 %29
%31 = load double*, double** %30
%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 = fadd double %35, 1.000000e-09
%37 = call double @log10(double %36)
%38 = fmul double %26, %37
%39 = call double @log10(double 2.000000e+00)
%40 = fdiv double %38, %39
%41 = load double, double* %7
%42 = fadd double %41, %40
store double %42, double* %7
br label %43
43: ; preds = %17
%44 = load i32, i32* %6
%45 = add nsw i32 %44, 1
store i32 %45, i32* %6
br label %13
46: ; preds = %13
br label %47
47: ; preds = %46
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
store i32 %49, i32* %5
br label %8
50: ; preds = %8
%51 = load double, double* %7
%52 = fneg double %51
ret double %52
}

LLVM IR (-O2):
define double @f9_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 = %23, %4
%7 = phi i64 [ 0, %4 ], [ %24, %23 ]
%8 = phi double [ 0.000000e+00, %4 ], [ %20, %23 ]
%9 = getelementptr inbounds double*, double** %0, i64 %7
br label %10
10: ; preds = %6, %10
%11 = phi i64 [ 0, %6 ], [ %21, %10 ]
%12 = phi double [ %8, %6 ], [ %20, %10 ]
%13 = load double*, double** %9
%14 = getelementptr inbounds double, double* %13, i64 %11
%15 = load double, double* %14
%16 = fadd double %15, 1.000000e-09
%17 = tail call double @log10(double %16)
%18 = fmul double %15, %17
%19 = fdiv double %18, 0x3FD34413509F79FF
%20 = fadd double %12, %19
%21 = add nuw nsw i64 %11, 1
%22 = icmp eq i64 %21, %5
br i1 %22, label %23, label %10
23: ; preds = %10
%24 = add nuw nsw i64 %7, 1
%25 = icmp eq i64 %24, %5
br i1 %25, label %26, label %6
26: ; preds = %23, %2
%27 = phi double [ 0.000000e+00, %2 ], [ %20, %23 ]
%28 = fneg double %27
ret double %28
}