#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 */
scalar_t__ calloc(int, int);
int /*<<< orphan*/ free(double *);
int /*<<< orphan*/ histU(double const *, double const *, int const *,
                         double const *, double const *, double *, double *,
                         double *, int, int, int);
double log2d(double);
double miundefined(const double *x, const double *y, const int *knots,
                   const double *wx, const double *wy, int numSamples,
                   int splineOrder, int numBins) {
  int curBin, curBinX, curBinY;
  double *h1 = (double *)calloc(numBins, sizeof(double));
  double *h2 = (double *)calloc(numBins, sizeof(double));
  double *h12 = (double *)calloc(numBins * numBins, sizeof(double));
  double e1 = 0;
  double e2 = 0;
  double e12 = 0;
  double p;
  histU(x, y, knots, wx, wy, h12, h1, h2, numSamples, splineOrder, numBins);
  for (curBin = 0; curBin < numBins; curBin++) {
    p = h1[curBin];
    if (p > 0)
      e1 -= p * log2d(p);
    p = h2[curBin];
    if (p > 0)
      e2 -= p * log2d(p);
  }
  for (curBinX = 0; curBinX < numBins; curBinX++)
    for (curBinY = 0; curBinY < numBins; curBinY++) {
      p = h12[curBinX * numBins + curBinY];
      if (p > 0)
        e12 -= p * log2d(p);
    }
  free(h12);
  free(h1);
  free(h2);
  return e1 + e2 - e12;
}


x86 assembly (clang, -O0):
<miundefined>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
sub    $0xb0,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
mov    %r9d,-0x3c(%rbp)
mov    0x18(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x50(%rbp)
mov    0x18(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x58(%rbp)
mov    0x18(%rbp),%edi
imul   0x18(%rbp),%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x70(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x78(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x38(%rbp),%r8
mov    -0x60(%rbp),%r9
mov    -0x50(%rbp),%r14
mov    -0x58(%rbp),%rbx
mov    -0x3c(%rbp),%r11d
mov    0x10(%rbp),%r10d
mov    0x18(%rbp),%eax
mov    %r14,(%rsp)
mov    %rbx,0x8(%rsp)
mov    %r11d,0x10(%rsp)
mov    %r10d,0x18(%rsp)
mov    %eax,0x20(%rsp)
call   1060 <histU@plt>
movl   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%eax
cmp    0x18(%rbp),%eax
jge    1306 <miundefined+0x1c6>
mov    -0x50(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1284 <miundefined+0x144>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
call   1050 <log2d@plt>
movaps %xmm0,%xmm2
movsd  -0x88(%rbp),%xmm0
ff
movsd  -0x68(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x68(%rbp)
mov    -0x58(%rbp),%rax
movslq -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12f3 <miundefined+0x1b3>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x90(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
call   1050 <log2d@plt>
movaps %xmm0,%xmm2
movsd  -0x90(%rbp),%xmm0
ff
movsd  -0x70(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    12f8 <miundefined+0x1b8>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x40(%rbp)
jmp    1209 <miundefined+0xc9>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    0x18(%rbp),%eax
jge    13ca <miundefined+0x28a>
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    0x18(%rbp),%eax
jge    13b7 <miundefined+0x277>
mov    -0x60(%rbp),%rax
mov    -0x44(%rbp),%ecx
imul   0x18(%rbp),%ecx
add    -0x48(%rbp),%ecx
movslq %ecx,%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x80(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    13a4 <miundefined+0x264>
movsd  -0x80(%rbp),%xmm0
movsd  %xmm0,-0x98(%rbp)
ff
movsd  -0x80(%rbp),%xmm0
call   1050 <log2d@plt>
movaps %xmm0,%xmm2
movsd  -0x98(%rbp),%xmm0
ff
movsd  -0x78(%rbp),%xmm1
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x78(%rbp)
jmp    13a9 <miundefined+0x269>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1320 <miundefined+0x1e0>
jmp    13bc <miundefined+0x27c>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    130d <miundefined+0x1cd>
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
movsd  -0x68(%rbp),%xmm0
addsd  -0x70(%rbp),%xmm0
subsd  -0x78(%rbp),%xmm0
add    $0xb0,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

x86 assembly (clang, -O2):
<miundefined>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,0x20(%rsp)
mov    %rcx,0x8(%rsp)
mov    %rdx,%r12
mov    %rsi,%r13
mov    %rdi,%rbp
mov    0x78(%rsp),%ebx
mov    %ebx,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r14
mov    %ebx,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
mov    %ebx,%edi
imul   %ebx,%edi
mov    $0x8,%esi
call   1040 <calloc@plt>
sub    $0x8,%rsp
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %rbx,%r12
mov    0x10(%rsp),%rcx
mov    0x28(%rsp),%r8
mov    %rax,0x30(%rsp)
mov    %rax,%r9
push   %rbx
mov    0x80(%rsp),%eax
push   %rax
push   0x28(%rsp)
push   %r15
push   %r14
call   1060 <histU@plt>
add    $0x30,%rsp
test   %r12d,%r12d
jle    130f <miundefined+0x1cf>
mov    %r12d,%ebp
xorpd  %xmm2,%xmm2
xor    %ebx,%ebx
xorpd  %xmm4,%xmm4
xorpd  %xmm1,%xmm1
jmp    1222 <miundefined+0xe2>
nop
movsd  %xmm0,0x10(%rsp)
call   1050 <log2d@plt>
xorpd  %xmm2,%xmm2
mulsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm4
movsd  0x18(%rsp),%xmm1
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1273 <miundefined+0x133>
movsd  (%r14,%rbx,8),%xmm0
ucomisd %xmm2,%xmm0
movsd  %xmm4,0x8(%rsp)
jbe    1259 <miundefined+0x119>
movsd  %xmm1,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1050 <log2d@plt>
xorpd  %xmm2,%xmm2
movsd  0x18(%rsp),%xmm1
mulsd  0x10(%rsp),%xmm0
subsd  %xmm0,%xmm1
movsd  (%r15,%rbx,8),%xmm0
ucomisd %xmm2,%xmm0
movsd  %xmm1,0x18(%rsp)
ja     11f0 <miundefined+0xb0>
movsd  0x8(%rsp),%xmm4
jmp    1219 <miundefined+0xd9>
test   %r12d,%r12d
jle    1317 <miundefined+0x1d7>
mov    %r14,0x30(%rsp)
lea    0x0(,%rbp,8),%r12
xorpd  %xmm3,%xmm3
xor    %r13d,%r13d
mov    0x28(%rsp),%rbx
xorpd  %xmm2,%xmm2
jmp    12ac <miundefined+0x16c>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r13
add    %r12,%rbx
cmp    %rbp,%r13
je     1308 <miundefined+0x1c8>
xor    %r14d,%r14d
movsd  %xmm4,0x8(%rsp)
jmp    12c9 <miundefined+0x189>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %r14,%rbp
je     12a0 <miundefined+0x160>
movsd  (%rbx,%r14,8),%xmm0
ucomisd %xmm3,%xmm0
jbe    12c0 <miundefined+0x180>
movsd  %xmm0,0x20(%rsp)
movsd  %xmm2,0x10(%rsp)
call   1050 <log2d@plt>
xorpd  %xmm3,%xmm3
movsd  0x10(%rsp),%xmm2
movsd  0x18(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm0
subsd  %xmm0,%xmm2
movsd  0x8(%rsp),%xmm4
jmp    12c0 <miundefined+0x180>
mov    0x30(%rsp),%r14
jmp    131b <miundefined+0x1db>
xorpd  %xmm4,%xmm4
xorpd  %xmm1,%xmm1
xorpd  %xmm2,%xmm2
addsd  %xmm1,%xmm4
subsd  %xmm2,%xmm4
movsd  %xmm4,0x8(%rsp)
mov    0x28(%rsp),%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
movsd  0x8(%rsp),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define double @miundefined(double* %0, double* %1, i32* %2, double* %3, double* %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca double*
%10 = alloca double*
%11 = alloca i32*
%12 = alloca double*
%13 = alloca double*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca double*
%21 = alloca double*
%22 = alloca double*
%23 = alloca double
%24 = alloca double
%25 = alloca double
%26 = alloca double
store double* %0, double** %9
store double* %1, double** %10
store i32* %2, i32** %11
store double* %3, double** %12
store double* %4, double** %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%27 = load i32, i32* %16
%28 = call i64 @calloc(i32 %27, i32 8)
%29 = inttoptr i64 %28 to double*
store double* %29, double** %20
%30 = load i32, i32* %16
%31 = call i64 @calloc(i32 %30, i32 8)
%32 = inttoptr i64 %31 to double*
store double* %32, double** %21
%33 = load i32, i32* %16
%34 = load i32, i32* %16
%35 = mul nsw i32 %33, %34
%36 = call i64 @calloc(i32 %35, i32 8)
%37 = inttoptr i64 %36 to double*
store double* %37, double** %22
store double 0.000000e+00, double* %23
store double 0.000000e+00, double* %24
store double 0.000000e+00, double* %25
%38 = load double*, double** %9
%39 = load double*, double** %10
%40 = load i32*, i32** %11
%41 = load double*, double** %12
%42 = load double*, double** %13
%43 = load double*, double** %22
%44 = load double*, double** %20
%45 = load double*, double** %21
%46 = load i32, i32* %14
%47 = load i32, i32* %15
%48 = load i32, i32* %16
%49 = call i32 @histU(double* %38, double* %39, i32* %40, double* %41, double* %42, double* %43, double* %44, double* %45, i32 %46, i32 %47, i32 %48)
store i32 0, i32* %17
br label %50
50: ; preds = %85, %8
%51 = load i32, i32* %17
%52 = load i32, i32* %16
%53 = icmp slt i32 %51, %52
br i1 %53, label %54, label %88
54: ; preds = %50
%55 = load double*, double** %20
%56 = load i32, i32* %17
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double, double* %55, i64 %57
%59 = load double, double* %58
store double %59, double* %26
%60 = load double, double* %26
%61 = fcmp ogt double %60, 0.000000e+00
br i1 %61, label %62, label %69
62: ; preds = %54
%63 = load double, double* %26
%64 = load double, double* %26
%65 = call double @log2d(double %64)
%66 = load double, double* %23
%67 = fneg double %63
%68 = call double @llvm.fmuladd.f64(double %67, double %65, double %66)
store double %68, double* %23
br label %69
69: ; preds = %62, %54
%70 = load double*, double** %21
%71 = load i32, i32* %17
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
store double %74, double* %26
%75 = load double, double* %26
%76 = fcmp ogt double %75, 0.000000e+00
br i1 %76, label %77, label %84
77: ; preds = %69
%78 = load double, double* %26
%79 = load double, double* %26
%80 = call double @log2d(double %79)
%81 = load double, double* %24
%82 = fneg double %78
%83 = call double @llvm.fmuladd.f64(double %82, double %80, double %81)
store double %83, double* %24
br label %84
84: ; preds = %77, %69
br label %85
85: ; preds = %84
%86 = load i32, i32* %17
%87 = add nsw i32 %86, 1
store i32 %87, i32* %17
br label %50
88: ; preds = %50
store i32 0, i32* %18
br label %89
89: ; preds = %122, %88
%90 = load i32, i32* %18
%91 = load i32, i32* %16
%92 = icmp slt i32 %90, %91
br i1 %92, label %93, label %125
93: ; preds = %89
store i32 0, i32* %19
br label %94
94: ; preds = %118, %93
%95 = load i32, i32* %19
%96 = load i32, i32* %16
%97 = icmp slt i32 %95, %96
br i1 %97, label %98, label %121
98: ; preds = %94
%99 = load double*, double** %22
%100 = load i32, i32* %18
%101 = load i32, i32* %16
%102 = mul nsw i32 %100, %101
%103 = load i32, i32* %19
%104 = add nsw i32 %102, %103
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds double, double* %99, i64 %105
%107 = load double, double* %106
store double %107, double* %26
%108 = load double, double* %26
%109 = fcmp ogt double %108, 0.000000e+00
br i1 %109, label %110, label %117
110: ; preds = %98
%111 = load double, double* %26
%112 = load double, double* %26
%113 = call double @log2d(double %112)
%114 = load double, double* %25
%115 = fneg double %111
%116 = call double @llvm.fmuladd.f64(double %115, double %113, double %114)
store double %116, double* %25
br label %117
117: ; preds = %110, %98
br label %118
118: ; preds = %117
%119 = load i32, i32* %19
%120 = add nsw i32 %119, 1
store i32 %120, i32* %19
br label %94
121: ; preds = %94
br label %122
122: ; preds = %121
%123 = load i32, i32* %18
%124 = add nsw i32 %123, 1
store i32 %124, i32* %18
br label %89
125: ; preds = %89
%126 = load double*, double** %22
%127 = call i32 @free(double* %126)
%128 = load double*, double** %20
%129 = call i32 @free(double* %128)
%130 = load double*, double** %21
%131 = call i32 @free(double* %130)
%132 = load double, double* %23
%133 = load double, double* %24
%134 = fadd double %132, %133
%135 = load double, double* %25
%136 = fsub double %134, %135
ret double %136
}

LLVM IR (-O2):
define double @miundefined(double* %0, double* %1, i32* %2, double* %3, double* %4, i32 %5, i32 %6, i32 %7) {
%9 = tail call i64 @calloc(i32 %7, i32 8)
%10 = inttoptr i64 %9 to double*
%11 = tail call i64 @calloc(i32 %7, i32 8)
%12 = inttoptr i64 %11 to double*
%13 = mul nsw i32 %7, %7
%14 = tail call i64 @calloc(i32 %13, i32 8)
%15 = inttoptr i64 %14 to double*
%16 = tail call i32 @histU(double* %0, double* %1, i32* %2, double* %3, double* %4, double* %15, double* %10, double* %12, i32 %5, i32 %6, i32 %7)
%17 = icmp sgt i32 %7, 0
br i1 %17, label %18, label %70
18: ; preds = %8
%19 = zext i32 %7 to i64
br label %24
20: ; preds = %44
br i1 %17, label %21, label %70
21: ; preds = %20
%22 = zext i32 %7 to i64
%23 = zext i32 %7 to i64
br label %48
24: ; preds = %18, %44
%25 = phi i64 [ 0, %18 ], [ %46, %44 ]
%26 = phi double [ 0.000000e+00, %18 ], [ %45, %44 ]
%27 = phi double [ 0.000000e+00, %18 ], [ %36, %44 ]
%28 = getelementptr inbounds double, double* %10, i64 %25
%29 = load double, double* %28
%30 = fcmp ogt double %29, 0.000000e+00
br i1 %30, label %31, label %35
31: ; preds = %24
%32 = tail call double @log2d(double %29)
%33 = fneg double %29
%34 = tail call double @llvm.fmuladd.f64(double %33, double %32, double %27)
br label %35
35: ; preds = %31, %24
%36 = phi double [ %34, %31 ], [ %27, %24 ]
%37 = getelementptr inbounds double, double* %12, i64 %25
%38 = load double, double* %37
%39 = fcmp ogt double %38, 0.000000e+00
br i1 %39, label %40, label %44
40: ; preds = %35
%41 = tail call double @log2d(double %38)
%42 = fneg double %38
%43 = tail call double @llvm.fmuladd.f64(double %42, double %41, double %26)
br label %44
44: ; preds = %35, %40
%45 = phi double [ %43, %40 ], [ %26, %35 ]
%46 = add nuw nsw i64 %25, 1
%47 = icmp eq i64 %46, %19
br i1 %47, label %20, label %24
48: ; preds = %67, %21
%49 = phi i64 [ 0, %21 ], [ %68, %67 ]
%50 = phi double [ 0.000000e+00, %21 ], [ %64, %67 ]
%51 = mul nsw i64 %49, %22
br label %52
52: ; preds = %48, %63
%53 = phi i64 [ 0, %48 ], [ %65, %63 ]
%54 = phi double [ %50, %48 ], [ %64, %63 ]
%55 = add nuw nsw i64 %53, %51
%56 = getelementptr inbounds double, double* %15, i64 %55
%57 = load double, double* %56
%58 = fcmp ogt double %57, 0.000000e+00
br i1 %58, label %59, label %63
59: ; preds = %52
%60 = tail call double @log2d(double %57)
%61 = fneg double %57
%62 = tail call double @llvm.fmuladd.f64(double %61, double %60, double %54)
br label %63
63: ; preds = %52, %59
%64 = phi double [ %62, %59 ], [ %54, %52 ]
%65 = add nuw nsw i64 %53, 1
%66 = icmp eq i64 %65, %23
br i1 %66, label %67, label %52
67: ; preds = %63
%68 = add nuw nsw i64 %49, 1
%69 = icmp eq i64 %68, %23
br i1 %69, label %70, label %48
70: ; preds = %67, %8, %20
%71 = phi double [ %45, %20 ], [ 0.000000e+00, %8 ], [ %45, %67 ]
%72 = phi double [ %36, %20 ], [ 0.000000e+00, %8 ], [ %36, %67 ]
%73 = phi double [ 0.000000e+00, %20 ], [ 0.000000e+00, %8 ], [ %64, %67 ]
%74 = tail call i32 @free(double* %15)
%75 = tail call i32 @free(double* %10)
%76 = tail call i32 @free(double* %12)
%77 = fadd double %72, %71
%78 = fsub double %77, %73
ret double %78
}