#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 */
int nearestElement(double, double *, int, double *);
double pow(double, double);
void computeTWMError(double **peakMTX1, int nCols1, double **peakMTX2,
                     int nCols2, int maxnpeaks, double *pmag, double *f0Error,
                     int nF0Cands, int PMorMP) {
  int ii, jj, min_ind;
  double Ponddif, FreqDistance, MagFactor;
  if (PMorMP) {
    for (ii = 0; ii < nF0Cands; ii++) {
      for (jj = 0; jj < maxnpeaks; jj++) {
        min_ind = nearestElement(peakMTX1[ii][jj], peakMTX2[ii], nCols2,
                                 &FreqDistance);
        Ponddif = FreqDistance * pow(peakMTX1[ii][jj], -0.5);
        MagFactor = pmag[min_ind];
        f0Error[ii] = f0Error[ii] + Ponddif + MagFactor * (1.4 * Ponddif - 0.5);
      }
    }
  } else {
    for (ii = 0; ii < nF0Cands; ii++) {
      for (jj = 0; jj < maxnpeaks; jj++) {
        min_ind = nearestElement(peakMTX1[ii][jj], peakMTX2[ii], nCols2,
                                 &FreqDistance);
        Ponddif = FreqDistance * pow(peakMTX1[ii][jj], -0.5);
        MagFactor = pmag[jj];
        f0Error[ii] = f0Error[ii] +
                      MagFactor * (Ponddif + MagFactor * (1.4 * Ponddif - 0.5));
      }
    }
  }
}


x86 assembly (clang, -O0):
<computeTWMError>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%eax
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
cmpl   $0x0,0x20(%rbp)
je     1266 <computeTWMError+0x146>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    0x18(%rbp),%eax
jge    1261 <computeTWMError+0x141>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    124e <computeTWMError+0x12e>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x48(%rbp),%rdx
call   1040 <nearestElement@plt>
mov    %eax,-0x34(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xe39(%rip),%xmm1
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x34(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
addsd  -0x40(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  0xde5(%rip),%xmm3
mulsd  %xmm3,%xmm2
movsd  0xde1(%rip),%xmm3
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    116c <computeTWMError+0x4c>
jmp    1253 <computeTWMError+0x133>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1159 <computeTWMError+0x39>
jmp    1387 <computeTWMError+0x267>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    0x18(%rbp),%eax
jge    1382 <computeTWMError+0x262>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    136f <computeTWMError+0x24f>
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x1c(%rbp),%esi
lea    -0x48(%rbp),%rdx
call   1040 <nearestElement@plt>
mov    %eax,-0x34(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  0xd25(%rip),%xmm1
call   1030 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x60(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm3
movsd  -0x50(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm4
movsd  0xccc(%rip),%xmm5
mulsd  %xmm5,%xmm4
movsd  0xcc8(%rip),%xmm5
addsd  %xmm5,%xmm4
mulsd  %xmm4,%xmm2
addsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    1280 <computeTWMError+0x160>
jmp    1374 <computeTWMError+0x254>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    126d <computeTWMError+0x14d>
jmp    1387 <computeTWMError+0x267>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<computeTWMError>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r8d,0x8(%rsp)
mov    %ecx,0xc(%rsp)
mov    %rdi,0x28(%rsp)
mov    0x78(%rsp),%eax
cmpl   $0x0,0x80(%rsp)
mov    %rdx,0x30(%rsp)
je     1242 <computeTWMError+0x122>
test   %eax,%eax
jle    1327 <computeTWMError+0x207>
mov    %eax,%eax
mov    %rax,0x18(%rsp)
mov    0x8(%rsp),%r13d
xor    %r12d,%r12d
lea    0x10(%rsp),%rcx
mov    0x28(%rsp),%rbp
jmp    118f <computeTWMError+0x6f>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%r12
cmp    0x18(%rsp),%r12
je     1327 <computeTWMError+0x207>
cmpl   $0x0,0x8(%rsp)
jle    1180 <computeTWMError+0x60>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp,%r12,8),%rax
movsd  (%rax,%rbx,8),%xmm0
mov    (%rdx,%r12,8),%rdi
mov    0xc(%rsp),%esi
mov    %rcx,%rdx
mov    %r9,%r15
call   1040 <nearestElement@plt>
mov    %eax,%r14d
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
mov    0x0(%rbp,%r12,8),%rax
movsd  (%rax,%rbx,8),%xmm0
movsd  0xe22(%rip),%xmm1
call   1030 <pow@plt>
movsd  0xe1d(%rip),%xmm3
movsd  0xe0d(%rip),%xmm2
mov    %r15,%r9
mov    0x70(%rsp),%rcx
mov    0x30(%rsp),%rdx
mulsd  0x20(%rsp),%xmm0
movslq %r14d,%rax
movsd  (%rcx,%r12,8),%xmm1
addsd  %xmm0,%xmm1
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
mulsd  (%r15,%rax,8),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%rcx,%r12,8)
lea    0x10(%rsp),%rcx
add    $0x1,%rbx
cmp    %rbx,%r13
jne    11a0 <computeTWMError+0x80>
jmp    1180 <computeTWMError+0x60>
test   %eax,%eax
jle    1327 <computeTWMError+0x207>
mov    %eax,%eax
mov    %rax,0x18(%rsp)
mov    0x8(%rsp),%r15d
xor    %ebx,%ebx
lea    0x10(%rsp),%r14
mov    0x28(%rsp),%r13
jmp    1282 <computeTWMError+0x162>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
cmp    0x18(%rsp),%rbx
mov    %r12,%r9
je     1327 <computeTWMError+0x207>
cmpl   $0x0,0x8(%rsp)
mov    %r9,%r12
jle    1270 <computeTWMError+0x150>
xor    %ebp,%ebp
xchg   %ax,%ax
mov    0x0(%r13,%rbx,8),%rax
movsd  (%rax,%rbp,8),%xmm0
mov    (%rdx,%rbx,8),%rdi
mov    0xc(%rsp),%esi
mov    %r14,%rdx
call   1040 <nearestElement@plt>
movsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x20(%rsp)
mov    0x0(%r13,%rbx,8),%rax
movsd  (%rax,%rbp,8),%xmm0
movsd  0xd38(%rip),%xmm1
call   1030 <pow@plt>
movsd  0xd33(%rip),%xmm4
movsd  0xd23(%rip),%xmm3
mov    0x70(%rsp),%rax
mov    0x30(%rsp),%rdx
mulsd  0x20(%rsp),%xmm0
movsd  (%r12,%rbp,8),%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm4,%xmm2
addsd  %xmm3,%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
mulsd  %xmm1,%xmm2
addsd  (%rax,%rbx,8),%xmm2
movsd  %xmm2,(%rax,%rbx,8)
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1290 <computeTWMError+0x170>
jmp    1270 <computeTWMError+0x150>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @computeTWMError(double** %0, i32 %1, double** %2, i32 %3, i32 %4, double* %5, double* %6, i32 %7, i32 %8) {
%10 = alloca double**
%11 = alloca i32
%12 = alloca double**
%13 = alloca i32
%14 = alloca i32
%15 = alloca double*
%16 = alloca double*
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca double
%23 = alloca double
%24 = alloca double
store double** %0, double*** %10
store i32 %1, i32* %11
store double** %2, double*** %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store double* %5, double** %15
store double* %6, double** %16
store i32 %7, i32* %17
store i32 %8, i32* %18
%25 = load i32, i32* %18
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %94
27: ; preds = %9
store i32 0, i32* %19
br label %28
28: ; preds = %90, %27
%29 = load i32, i32* %19
%30 = load i32, i32* %17
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %93
32: ; preds = %28
store i32 0, i32* %20
br label %33
33: ; preds = %86, %32
%34 = load i32, i32* %20
%35 = load i32, i32* %14
%36 = icmp slt i32 %34, %35
br i1 %36, label %37, label %89
37: ; preds = %33
%38 = load double**, double*** %10
%39 = load i32, i32* %19
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds double*, double** %38, i64 %40
%42 = load double*, double** %41
%43 = load i32, i32* %20
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds double, double* %42, i64 %44
%46 = load double, double* %45
%47 = load double**, double*** %12
%48 = load i32, i32* %19
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double*, double** %47, i64 %49
%51 = load double*, double** %50
%52 = load i32, i32* %13
%53 = call i32 @nearestElement(double %46, double* %51, i32 %52, double* %23)
store i32 %53, i32* %21
%54 = load double, double* %23
%55 = load double**, double*** %10
%56 = load i32, i32* %19
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds double*, double** %55, i64 %57
%59 = load double*, double** %58
%60 = load i32, i32* %20
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds double, double* %59, i64 %61
%63 = load double, double* %62
%64 = call double @pow(double %63, double -5.000000e-01)
%65 = fmul double %54, %64
store double %65, double* %22
%66 = load double*, double** %15
%67 = load i32, i32* %21
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds double, double* %66, i64 %68
%70 = load double, double* %69
store double %70, double* %24
%71 = load double*, double** %16
%72 = load i32, i32* %19
%73 = sext i32 %72 to i64
%74 = getelementptr inbounds double, double* %71, i64 %73
%75 = load double, double* %74
%76 = load double, double* %22
%77 = fadd double %75, %76
%78 = load double, double* %24
%79 = load double, double* %22
%80 = call double @llvm.fmuladd.f64(double 1.400000e+00, double %79, double -5.000000e-01)
%81 = call double @llvm.fmuladd.f64(double %78, double %80, double %77)
%82 = load double*, double** %16
%83 = load i32, i32* %19
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds double, double* %82, i64 %84
store double %81, double* %85
br label %86
86: ; preds = %37
%87 = load i32, i32* %20
%88 = add nsw i32 %87, 1
store i32 %88, i32* %20
br label %33
89: ; preds = %33
br label %90
90: ; preds = %89
%91 = load i32, i32* %19
%92 = add nsw i32 %91, 1
store i32 %92, i32* %19
br label %28
93: ; preds = %28
br label %162
94: ; preds = %9
store i32 0, i32* %19
br label %95
95: ; preds = %158, %94
%96 = load i32, i32* %19
%97 = load i32, i32* %17
%98 = icmp slt i32 %96, %97
br i1 %98, label %99, label %161
99: ; preds = %95
store i32 0, i32* %20
br label %100
100: ; preds = %154, %99
%101 = load i32, i32* %20
%102 = load i32, i32* %14
%103 = icmp slt i32 %101, %102
br i1 %103, label %104, label %157
104: ; preds = %100
%105 = load double**, double*** %10
%106 = load i32, i32* %19
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds double*, double** %105, i64 %107
%109 = load double*, double** %108
%110 = load i32, i32* %20
%111 = sext i32 %110 to i64
%112 = getelementptr inbounds double, double* %109, i64 %111
%113 = load double, double* %112
%114 = load double**, double*** %12
%115 = load i32, i32* %19
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds double*, double** %114, i64 %116
%118 = load double*, double** %117
%119 = load i32, i32* %13
%120 = call i32 @nearestElement(double %113, double* %118, i32 %119, double* %23)
store i32 %120, i32* %21
%121 = load double, double* %23
%122 = load double**, double*** %10
%123 = load i32, i32* %19
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds double*, double** %122, i64 %124
%126 = load double*, double** %125
%127 = load i32, i32* %20
%128 = sext i32 %127 to i64
%129 = getelementptr inbounds double, double* %126, i64 %128
%130 = load double, double* %129
%131 = call double @pow(double %130, double -5.000000e-01)
%132 = fmul double %121, %131
store double %132, double* %22
%133 = load double*, double** %15
%134 = load i32, i32* %20
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds double, double* %133, i64 %135
%137 = load double, double* %136
store double %137, double* %24
%138 = load double*, double** %16
%139 = load i32, i32* %19
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds double, double* %138, i64 %140
%142 = load double, double* %141
%143 = load double, double* %24
%144 = load double, double* %22
%145 = load double, double* %24
%146 = load double, double* %22
%147 = call double @llvm.fmuladd.f64(double 1.400000e+00, double %146, double -5.000000e-01)
%148 = call double @llvm.fmuladd.f64(double %145, double %147, double %144)
%149 = call double @llvm.fmuladd.f64(double %143, double %148, double %142)
%150 = load double*, double** %16
%151 = load i32, i32* %19
%152 = sext i32 %151 to i64
%153 = getelementptr inbounds double, double* %150, i64 %152
store double %149, double* %153
br label %154
154: ; preds = %104
%155 = load i32, i32* %20
%156 = add nsw i32 %155, 1
store i32 %156, i32* %20
br label %100
157: ; preds = %100
br label %158
158: ; preds = %157
%159 = load i32, i32* %19
%160 = add nsw i32 %159, 1
store i32 %160, i32* %19
br label %95
161: ; preds = %95
br label %162
162: ; preds = %161, %93
ret void
}

LLVM IR (-O2):
define void @computeTWMError(double** nocapture %0, i32 %1, double** nocapture %2, i32 %3, i32 %4, double* nocapture %5, double* nocapture %6, i32 %7, i32 %8) {
%10 = alloca double
%11 = bitcast double* %10 to i8*
%12 = icmp eq i32 %8, 0
%13 = icmp sgt i32 %7, 0
br i1 %12, label %19, label %14
14: ; preds = %9
br i1 %13, label %15, label %85
15: ; preds = %14
%16 = icmp sgt i32 %4, 0
%17 = zext i32 %7 to i64
%18 = zext i32 %4 to i64
br label %24
19: ; preds = %9
br i1 %13, label %20, label %85
20: ; preds = %19
%21 = icmp sgt i32 %4, 0
%22 = zext i32 %7 to i64
%23 = zext i32 %4 to i64
br label %55
24: ; preds = %15, %52
%25 = phi i64 [ 0, %15 ], [ %53, %52 ]
br i1 %16, label %26, label %52
26: ; preds = %24
%27 = getelementptr inbounds double*, double** %0, i64 %25
%28 = getelementptr inbounds double*, double** %2, i64 %25
%29 = getelementptr inbounds double, double* %6, i64 %25
br label %30
30: ; preds = %26, %30
%31 = phi i64 [ 0, %26 ], [ %50, %30 ]
%32 = load double*, double** %27
%33 = getelementptr inbounds double, double* %32, i64 %31
%34 = load double, double* %33
%35 = load double*, double** %28
%36 = call i32 @nearestElement(double %34, double* %35, i32 %3, double* %10)
%37 = load double, double* %10
%38 = load double*, double** %27
%39 = getelementptr inbounds double, double* %38, i64 %31
%40 = load double, double* %39
%41 = call double @pow(double %40, double -5.000000e-01)
%42 = fmul double %37, %41
%43 = sext i32 %36 to i64
%44 = getelementptr inbounds double, double* %5, i64 %43
%45 = load double, double* %44
%46 = load double, double* %29
%47 = fadd double %42, %46
%48 = call double @llvm.fmuladd.f64(double %42, double 1.400000e+00, double -5.000000e-01)
%49 = call double @llvm.fmuladd.f64(double %45, double %48, double %47)
store double %49, double* %29
%50 = add nuw nsw i64 %31, 1
%51 = icmp eq i64 %50, %18
br i1 %51, label %52, label %30
52: ; preds = %30, %24
%53 = add nuw nsw i64 %25, 1
%54 = icmp eq i64 %53, %17
br i1 %54, label %85, label %24
55: ; preds = %20, %82
%56 = phi i64 [ 0, %20 ], [ %83, %82 ]
br i1 %21, label %57, label %82
57: ; preds = %55
%58 = getelementptr inbounds double*, double** %0, i64 %56
%59 = getelementptr inbounds double*, double** %2, i64 %56
%60 = getelementptr inbounds double, double* %6, i64 %56
br label %61
61: ; preds = %57, %61
%62 = phi i64 [ 0, %57 ], [ %80, %61 ]
%63 = load double*, double** %58
%64 = getelementptr inbounds double, double* %63, i64 %62
%65 = load double, double* %64
%66 = load double*, double** %59
%67 = call i32 @nearestElement(double %65, double* %66, i32 %3, double* %10)
%68 = load double, double* %10
%69 = load double*, double** %58
%70 = getelementptr inbounds double, double* %69, i64 %62
%71 = load double, double* %70
%72 = call double @pow(double %71, double -5.000000e-01)
%73 = fmul double %68, %72
%74 = getelementptr inbounds double, double* %5, i64 %62
%75 = load double, double* %74
%76 = load double, double* %60
%77 = call double @llvm.fmuladd.f64(double %73, double 1.400000e+00, double -5.000000e-01)
%78 = call double @llvm.fmuladd.f64(double %75, double %77, double %73)
%79 = call double @llvm.fmuladd.f64(double %75, double %78, double %76)
store double %79, double* %60
%80 = add nuw nsw i64 %62, 1
%81 = icmp eq i64 %80, %23
br i1 %81, label %82, label %61
82: ; preds = %61, %55
%83 = add nuw nsw i64 %56, 1
%84 = icmp eq i64 %83, %22
br i1 %84, label %85, label %55
85: ; preds = %52, %82, %14, %19
ret void
}