#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 */
size_t abs(int);
double *allocate_vector(int /*<<< orphan*/, int);
int /*<<< orphan*/ free(double *);
double log10(double);
double f11_dentropy(double **P, int Ng) {
  int i, j;
  double sum = 0;
  double *Pxpy = allocate_vector(0, 2 * Ng);
  for (i = 0; i <= 2 * Ng; ++i)
    Pxpy[i] = 0;
  for (i = 0; i < Ng; ++i)
    for (j = 0; j < Ng; ++j)
      Pxpy[abs(i - j)] += P[i][j];
  for (i = 0; i < Ng; ++i)
    sum += Pxpy[i] * log10(Pxpy[i] + 0.000000001) / log10(2.0);
  free(Pxpy);
  return -sum;
}


x86 assembly (clang, -O0):
<f11_dentropy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0xc(%rbp),%esi
shl    $0x1,%esi
xor    %edi,%edi
call   1050 <allocate_vector@plt>
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0xc(%rbp),%ecx
shl    $0x1,%ecx
cmp    %ecx,%eax
jg     119e <f11_dentropy+0x5e>
mov    -0x28(%rbp),%rax
movslq -0x10(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116f <f11_dentropy+0x2f>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1228 <f11_dentropy+0xe8>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1215 <f11_dentropy+0xd5>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%edi
sub    -0x14(%rbp),%edi
call   1040 <abs@plt>
movsd  -0x38(%rbp),%xmm0
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b8 <f11_dentropy+0x78>
jmp    121a <f11_dentropy+0xda>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11a5 <f11_dentropy+0x65>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12a9 <f11_dentropy+0x169>
mov    -0x28(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsd  0xdab(%rip),%xmm0
addsd  (%rax,%rcx,8),%xmm0
call   1060 <log10@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xd80(%rip),%xmm0
call   1060 <log10@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    122f <f11_dentropy+0xef>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f11_dentropy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %esi,%ebx
mov    %rdi,%r15
lea    (%rbx,%rbx,1),%ebp
xor    %r14d,%r14d
xor    %edi,%edi
mov    %ebp,%esi
call   1060 <allocate_vector@plt>
mov    %rax,%r12
test   %ebx,%ebx
js     12a0 <f11_dentropy+0x150>
test   %ebp,%ebp
cmovle %r14d,%ebp
shl    $0x3,%rbp
or     $0x8,%rbp
mov    %r12,%rdi
xor    %esi,%esi
mov    %rbp,%rdx
call   1050 <memset@plt>
test   %ebx,%ebx
je     12a0 <f11_dentropy+0x150>
mov    %ebx,%ecx
mov    %ecx,%ebp
and    $0xfffffffe,%ebp
mov    $0xffffffff,%eax
xor    %r13d,%r13d
mov    %rcx,0x20(%rsp)
mov    %rbx,0x18(%rsp)
jmp    11d9 <f11_dentropy+0x89>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
mov    0x10(%rsp),%eax
add    $0x1,%eax
cmp    %rcx,%r13
mov    0x18(%rsp),%rbx
je     12a6 <f11_dentropy+0x156>
cmp    $0x1,%ebx
mov    %eax,0x10(%rsp)
jne    11f0 <f11_dentropy+0xa0>
xor    %r14d,%r14d
jmp    125c <f11_dentropy+0x10c>
nopw   0x0(%rax,%rax,1)
mov    %eax,%ebx
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15,%r13,8),%rax
movsd  (%rax,%r14,8),%xmm0
movsd  %xmm0,(%rsp)
lea    0x1(%rbx),%edi
call   1040 <abs@plt>
movsd  (%rsp),%xmm0
addsd  (%r12,%rax,8),%xmm0
movsd  %xmm0,(%r12,%rax,8)
mov    (%r15,%r13,8),%rax
movsd  0x8(%rax,%r14,8),%xmm0
movsd  %xmm0,(%rsp)
mov    %ebx,%edi
call   1040 <abs@plt>
movsd  (%rsp),%xmm0
addsd  (%r12,%rax,8),%xmm0
movsd  %xmm0,(%r12,%rax,8)
add    $0x2,%r14
add    $0xfffffffe,%ebx
cmp    %r14,%rbp
jne    1200 <f11_dentropy+0xb0>
mov    0x20(%rsp),%rcx
test   $0x1,%cl
je     11c0 <f11_dentropy+0x70>
mov    (%r15,%r13,8),%rax
movsd  (%rax,%r14,8),%xmm0
movsd  %xmm0,(%rsp)
mov    %r13d,%edi
sub    %r14d,%edi
mov    %rcx,%rbx
call   1040 <abs@plt>
mov    %rbx,%rcx
movsd  (%rsp),%xmm0
addsd  (%r12,%rax,8),%xmm0
movsd  %xmm0,(%r12,%rax,8)
jmp    11c0 <f11_dentropy+0x70>
xorpd  %xmm0,%xmm0
jmp    1308 <f11_dentropy+0x1b8>
test   %ebx,%ebx
xorpd  %xmm0,%xmm0
je     1308 <f11_dentropy+0x1b8>
mov    %rcx,%rbp
xorpd  %xmm0,%xmm0
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
movapd %xmm0,(%rsp)
movsd  (%r12,%rbx,8),%xmm0
movsd  %xmm0,0x10(%rsp)
addsd  0xd27(%rip),%xmm0
call   1070 <log10@plt>
mulsd  0x10(%rsp),%xmm0
divsd  0xd1c(%rip),%xmm0
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movapd (%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    12c0 <f11_dentropy+0x170>
movapd %xmm0,(%rsp)
mov    %r12,%rdi
call   1030 <free@plt>
movaps (%rsp),%xmm0
xorps  0xcf0(%rip),%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @f11_dentropy(double** %0, i32 %1) {
%3 = alloca double**
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca double
%8 = alloca double*
store double** %0, double*** %3
store i32 %1, i32* %4
store double 0.000000e+00, double* %7
%9 = load i32, i32* %4
%10 = mul nsw i32 2, %9
%11 = call double* @allocate_vector(i32 0, i32 %10)
store double* %11, double** %8
store i32 0, i32* %5
br label %12
12: ; preds = %22, %2
%13 = load i32, i32* %5
%14 = load i32, i32* %4
%15 = mul nsw i32 2, %14
%16 = icmp sle i32 %13, %15
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = load double*, double** %8
%19 = load i32, i32* %5
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds double, double* %18, i64 %20
store double 0.000000e+00, double* %21
br label %22
22: ; preds = %17
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %12
25: ; preds = %12
store i32 0, i32* %5
br label %26
26: ; preds = %57, %25
%27 = load i32, i32* %5
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %60
30: ; preds = %26
store i32 0, i32* %6
br label %31
31: ; preds = %53, %30
%32 = load i32, i32* %6
%33 = load i32, i32* %4
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %56
35: ; preds = %31
%36 = load double**, double*** %3
%37 = load i32, i32* %5
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double*, double** %36, i64 %38
%40 = load double*, double** %39
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds double, double* %40, i64 %42
%44 = load double, double* %43
%45 = load double*, double** %8
%46 = load i32, i32* %5
%47 = load i32, i32* %6
%48 = sub nsw i32 %46, %47
%49 = call i64 @abs(i32 %48)
%50 = getelementptr inbounds double, double* %45, i64 %49
%51 = load double, double* %50
%52 = fadd double %51, %44
store double %52, double* %50
br label %53
53: ; preds = %35
%54 = load i32, i32* %6
%55 = add nsw i32 %54, 1
store i32 %55, i32* %6
br label %31
56: ; preds = %31
br label %57
57: ; preds = %56
%58 = load i32, i32* %5
%59 = add nsw i32 %58, 1
store i32 %59, i32* %5
br label %26
60: ; preds = %26
store i32 0, i32* %5
br label %61
61: ; preds = %83, %60
%62 = load i32, i32* %5
%63 = load i32, i32* %4
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %86
65: ; preds = %61
%66 = load double*, double** %8
%67 = load i32, i32* %5
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %66, i64 %68
%70 = load double, double* %69
%71 = load double*, double** %8
%72 = load i32, i32* %5
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %71, i64 %73
%75 = load double, double* %74
%76 = fadd double %75, 1.000000e-09
%77 = call double @log10(double %76)
%78 = fmul double %70, %77
%79 = call double @log10(double 2.000000e+00)
%80 = fdiv double %78, %79
%81 = load double, double* %7
%82 = fadd double %81, %80
store double %82, double* %7
br label %83
83: ; preds = %65
%84 = load i32, i32* %5
%85 = add nsw i32 %84, 1
store i32 %85, i32* %5
br label %61
86: ; preds = %61
%87 = load double*, double** %8
%88 = call i32 @free(double* %87)
%89 = load double, double* %7
%90 = fneg double %89
ret double %90
}

LLVM IR (-O2):
define double @f11_dentropy(double** nocapture %0, i32 %1) {
%3 = shl nsw i32 %1, 1
%4 = tail call double* @allocate_vector(i32 0, i32 %3)
%5 = icmp slt i32 %1, 0
br i1 %5, label %77, label %6
6: ; preds = %2
%7 = bitcast double* %4 to i8*
%8 = call i32 @llvm.smax.i32(i32 %3, i32 0)
%9 = zext i32 %8 to i64
%10 = shl nuw nsw i64 %9, 3
%11 = or i64 %10, 8
%12 = icmp eq i32 %1, 0
br i1 %12, label %77, label %13
13: ; preds = %6
%14 = zext i32 %1 to i64
%15 = and i64 %14, 1
%16 = icmp eq i32 %1, 1
%17 = and i64 %14, 4294967294
%18 = icmp eq i64 %15, 0
br label %19
19: ; preds = %62, %13
%20 = phi i64 [ 0, %13 ], [ %63, %62 ]
%21 = getelementptr inbounds double*, double** %0, i64 %20
br i1 %16, label %50, label %25
22: ; preds = %62
br i1 %12, label %77, label %23
23: ; preds = %22
%24 = zext i32 %1 to i64
br label %65
25: ; preds = %19, %25
%26 = phi i64 [ %47, %25 ], [ 0, %19 ]
%27 = phi i64 [ %48, %25 ], [ 0, %19 ]
%28 = load double*, double** %21
%29 = getelementptr inbounds double, double* %28, i64 %26
%30 = load double, double* %29
%31 = sub nsw i64 %20, %26
%32 = trunc i64 %31 to i32
%33 = tail call i64 @abs(i32 %32)
%34 = getelementptr inbounds double, double* %4, i64 %33
%35 = load double, double* %34
%36 = fadd double %30, %35
store double %36, double* %34
%37 = or i64 %26, 1
%38 = load double*, double** %21
%39 = getelementptr inbounds double, double* %38, i64 %37
%40 = load double, double* %39
%41 = sub nsw i64 %20, %37
%42 = trunc i64 %41 to i32
%43 = tail call i64 @abs(i32 %42)
%44 = getelementptr inbounds double, double* %4, i64 %43
%45 = load double, double* %44
%46 = fadd double %40, %45
store double %46, double* %44
%47 = add nuw nsw i64 %26, 2
%48 = add i64 %27, 2
%49 = icmp eq i64 %48, %17
br i1 %49, label %50, label %25
50: ; preds = %25, %19
%51 = phi i64 [ 0, %19 ], [ %47, %25 ]
br i1 %18, label %62, label %52
52: ; preds = %50
%53 = load double*, double** %21
%54 = getelementptr inbounds double, double* %53, i64 %51
%55 = load double, double* %54
%56 = sub nsw i64 %20, %51
%57 = trunc i64 %56 to i32
%58 = tail call i64 @abs(i32 %57)
%59 = getelementptr inbounds double, double* %4, i64 %58
%60 = load double, double* %59
%61 = fadd double %55, %60
store double %61, double* %59
br label %62
62: ; preds = %50, %52
%63 = add nuw nsw i64 %20, 1
%64 = icmp eq i64 %63, %14
br i1 %64, label %22, label %19
65: ; preds = %23, %65
%66 = phi i64 [ 0, %23 ], [ %75, %65 ]
%67 = phi double [ 0.000000e+00, %23 ], [ %74, %65 ]
%68 = getelementptr inbounds double, double* %4, i64 %66
%69 = load double, double* %68
%70 = fadd double %69, 1.000000e-09
%71 = tail call double @log10(double %70)
%72 = fmul double %69, %71
%73 = fdiv double %72, 0x3FD34413509F79FF
%74 = fadd double %67, %73
%75 = add nuw nsw i64 %66, 1
%76 = icmp eq i64 %75, %24
br i1 %76, label %77, label %65
77: ; preds = %65, %6, %2, %22
%78 = phi double [ 0.000000e+00, %22 ], [ 0.000000e+00, %2 ], [ 0.000000e+00, %6 ], [ %74, %65 ]
%79 = tail call i32 @free(double* %4)
%80 = fneg double %78
ret double %80
}