#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__ isnan(double);
double sqrt(double);
void zero_trend_averages(int Njd, int Ntrends, double **trends, double clipping,
                         double *ave_stddev_out) {
  int i, j, n;
  double ave1, ave2, std;
  double ave_stddev = 0.0;
  int Nave = 0;
  long double val1, val2;
  for (j = 0; j < Ntrends; j++) {
    val1 = 0.;
    val2 = 0.;
    n = 0;
    for (i = 0; i < Njd; i++) {
      if (!isnan(trends[i][j])) {
        val1 += trends[i][j] * trends[i][j];
        val2 += trends[i][j];
        n++;
      }
    }
    if (n > 0) {
      ave1 = (double)(val2 / (long double)n);
      std = sqrt((double)((val1 / (long double)n) -
                          (val2 * val2 / (long double)(n * n))));
    } else {
      ave1 = 0.;
      std = 0.;
    }
    if (n > 0) {
      ave_stddev += std;
      Nave++;
    }
    val1 = 0.;
    val2 = 0.;
    n = 0;
    for (i = 0; i < Njd; i++) {
      if (!isnan(trends[i][j]))
        if (((trends[i][j] - ave1) > 0
                 ? (trends[i][j] - ave1)
                 : (-(trends[i][j] - ave1))) < clipping * std) {
          val1 += trends[i][j] * trends[i][j];
          val2 += trends[i][j];
          n++;
        }
    }
    if (n > 0)
      ave2 = (double)(val2 / (long double)n);
    else
      ave2 = 0.;
    for (i = 0; i < Njd; i++) {
      if (isnan(trends[i][j]) ||
          ((trends[i][j] - ave1) > 0
               ? (trends[i][j] - ave1)
               : (-(trends[i][j] - ave1))) >= clipping * std) {
        trends[i][j] = 0.;
      } else {
        trends[i][j] -= ave2;
      }
    }
  }
  if (Nave > 0) {
    ave_stddev = ave_stddev / (double)Nave;
  }
  *ave_stddev_out = ave_stddev;
}


x86 assembly (clang, -O0):
<zero_trend_averages>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    157e <zero_trend_averages+0x45e>
fldz
fld    %st(0)
fstpt  -0x70(%rbp)
fstpt  -0x80(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    120e <zero_trend_averages+0xee>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
jne    11fb <zero_trend_averages+0xdb>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,-0xb8(%rbp)
ff
fldl   -0xb8(%rbp)
fldt   -0x70(%rbp)
faddp  %st,%st(1)
fstpt  -0x70(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
fldl   (%rax,%rcx,8)
fldt   -0x80(%rbp)
faddp  %st,%st(1)
fstpt  -0x80(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1200 <zero_trend_averages+0xe0>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1178 <zero_trend_averages+0x58>
cmpl   $0x0,-0x2c(%rbp)
jle    1278 <zero_trend_averages+0x158>
fldt   -0x80(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
fildl  -0x8c(%rbp)
fdivrp %st,%st(1)
fstpl  -0x38(%rbp)
fldt   -0x70(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x88(%rbp)
fildl  -0x88(%rbp)
fdivrp %st,%st(1)
fldt   -0x80(%rbp)
fmul   %st,%st(0)
imul   %eax,%eax
mov    %eax,-0x84(%rbp)
fildl  -0x84(%rbp)
fdivrp %st,%st(1)
fsubrp %st,%st(1)
fstpl  -0x98(%rbp)
movsd  -0x98(%rbp),%xmm0
ff
call   1040 <sqrt@plt>
movsd  %xmm0,-0x48(%rbp)
jmp    1288 <zero_trend_averages+0x168>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jle    12aa <zero_trend_averages+0x18a>
movsd  -0x48(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
fldz
fld    %st(0)
fstpt  -0x70(%rbp)
fstpt  -0x80(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1400 <zero_trend_averages+0x2e0>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
jne    13ed <zero_trend_averages+0x2cd>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1340 <zero_trend_averages+0x220>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0xc0(%rbp)
ff
jmp    1379 <zero_trend_averages+0x259>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0xc0(%rbp)
ff
movsd  -0xc0(%rbp),%xmm1
ff
movsd  -0x18(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    13e8 <zero_trend_averages+0x2c8>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,-0xb0(%rbp)
ff
fldl   -0xb0(%rbp)
fldt   -0x70(%rbp)
faddp  %st,%st(1)
fstpt  -0x70(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
fldl   (%rax,%rcx,8)
fldt   -0x80(%rbp)
faddp  %st,%st(1)
fstpt  -0x80(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    13ed <zero_trend_averages+0x2cd>
jmp    13f2 <zero_trend_averages+0x2d2>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    12c2 <zero_trend_averages+0x1a2>
cmpl   $0x0,-0x2c(%rbp)
jle    1436 <zero_trend_averages+0x316>
fldt   -0x80(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x9c(%rbp)
fildl  -0x9c(%rbp)
fdivrp %st,%st(1)
fstpl  -0xa8(%rbp)
movsd  -0xa8(%rbp),%xmm0
ff
movsd  %xmm0,-0x40(%rbp)
jmp    143e <zero_trend_averages+0x31e>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    156b <zero_trend_averages+0x44b>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
jne    1518 <zero_trend_averages+0x3f8>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x38(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    14c3 <zero_trend_averages+0x3a3>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0xc8(%rbp)
ff
jmp    14fc <zero_trend_averages+0x3dc>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0xc8(%rbp)
ff
movsd  -0xc8(%rbp),%xmm0
ff
movsd  -0x18(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     1535 <zero_trend_averages+0x415>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    1558 <zero_trend_averages+0x438>
movsd  -0x40(%rbp),%xmm1
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movslq -0x28(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,(%rax,%rcx,8)
jmp    155d <zero_trend_averages+0x43d>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1445 <zero_trend_averages+0x325>
jmp    1570 <zero_trend_averages+0x450>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1154 <zero_trend_averages+0x34>
cmpl   $0x0,-0x54(%rbp)
jle    159b <zero_trend_averages+0x47b>
movsd  -0x50(%rbp),%xmm0
cvtsi2sdl -0x54(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zero_trend_averages>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
movsd  %xmm0,0x58(%rsp)
test   %esi,%esi
jle    1459 <zero_trend_averages+0x339>
mov    %rdx,%r14
mov    %edi,%r12d
mov    %rcx,0x50(%rsp)
mov    %esi,%eax
mov    %rax,0x60(%rsp)
mov    %edi,%r13d
xor    %ebp,%ebp
fldz
fstpt  0x9c(%rsp)
movl   $0x0,0x34(%rsp)
xorpd  %xmm0,%xmm0
jmp    117f <zero_trend_averages+0x5f>
nopl   (%rax)
add    $0x1,%rbp
cmp    0x60(%rsp),%rbp
je     1437 <zero_trend_averages+0x317>
test   %r12d,%r12d
jle    1170 <zero_trend_averages+0x50>
movsd  %xmm0,0x28(%rsp)
xor    %ebx,%ebx
fldt   0x9c(%rsp)
fld    %st(0)
fstpt  0x18(%rsp)
fstpt  0x8(%rsp)
xor    %r15d,%r15d
jmp    11b9 <zero_trend_averages+0x99>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%rbx
cmp    %rbx,%r13
je     1220 <zero_trend_averages+0x100>
mov    (%r14,%rbx,8),%rax
movsd  (%rax,%rbp,8),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
jne    11b0 <zero_trend_averages+0x90>
mov    (%r14,%rbx,8),%rax
movsd  (%rax,%rbp,8),%xmm0
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x88(%rsp)
fldt   0x8(%rsp)
faddl  0x88(%rsp)
fstpt  0x8(%rsp)
movsd  %xmm0,0x90(%rsp)
fldt   0x18(%rsp)
faddl  0x90(%rsp)
fstpt  0x18(%rsp)
add    $0x1,%r15d
jmp    11b0 <zero_trend_averages+0x90>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %r15d,%r15d
jle    1280 <zero_trend_averages+0x160>
mov    %r15d,0x48(%rsp)
fildl  0x48(%rsp)
fldt   0x18(%rsp)
fld    %st(0)
fdiv   %st(2),%st
fstpl  0x80(%rsp)
movsd  0x80(%rsp),%xmm0
movsd  %xmm0,0x38(%rsp)
fldt   0x8(%rsp)
fdivp  %st,%st(2)
fmul   %st,%st(0)
mov    %r15d,%eax
imul   %r15d,%eax
mov    %eax,0x4c(%rsp)
fidivl 0x4c(%rsp)
fsubrp %st,%st(1)
fstpl  0x78(%rsp)
movsd  0x78(%rsp),%xmm0
ucomisd 0xd91(%rip),%xmm0
jb     129e <zero_trend_averages+0x17e>
sqrtsd %xmm0,%xmm0
jmp    12a3 <zero_trend_averages+0x183>
nop
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x38(%rsp)
movsd  0xd6e(%rip),%xmm0
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x18(%rsp)
jmp    12a9 <zero_trend_averages+0x189>
call   1040 <sqrt@plt>
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
test   %r15d,%r15d
setg   %al
add    %eax,0x34(%rsp)
movsd  0x28(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
test   %r12d,%r12d
jle    1170 <zero_trend_averages+0x50>
movsd  0x18(%rsp),%xmm1
mulsd  0x58(%rsp),%xmm1
movsd  %xmm1,0x18(%rsp)
xor    %ebx,%ebx
fldz
fstpt  0x8(%rsp)
xor    %r15d,%r15d
movsd  %xmm0,0x28(%rsp)
jmp    130f <zero_trend_averages+0x1ef>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsd  0x28(%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r13
je     1380 <zero_trend_averages+0x260>
mov    (%r14,%rbx,8),%rax
movsd  (%rax,%rbp,8),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
jne    1300 <zero_trend_averages+0x1e0>
mov    (%r14,%rbx,8),%rax
movsd  (%rax,%rbp,8),%xmm0
movapd %xmm0,%xmm1
subsd  0x38(%rsp),%xmm1
movapd %xmm1,%xmm2
xorpd  0xccf(%rip),%xmm2
xorpd  %xmm3,%xmm3
cmpltsd %xmm1,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm2,%xmm3
orpd   %xmm1,%xmm3
movsd  0x18(%rsp),%xmm1
ucomisd %xmm3,%xmm1
jbe    1300 <zero_trend_averages+0x1e0>
movsd  %xmm0,0x70(%rsp)
fldt   0x8(%rsp)
faddl  0x70(%rsp)
fstpt  0x8(%rsp)
add    $0x1,%r15d
jmp    1300 <zero_trend_averages+0x1e0>
nopw   0x0(%rax,%rax,1)
test   %r15d,%r15d
jle    139e <zero_trend_averages+0x27e>
mov    %r15d,0x44(%rsp)
fldt   0x8(%rsp)
fidivl 0x44(%rsp)
fstpl  0x68(%rsp)
movsd  0x68(%rsp),%xmm1
jmp    13a2 <zero_trend_averages+0x282>
xorpd  %xmm1,%xmm1
movsd  %xmm1,0x8(%rsp)
test   %r12d,%r12d
jle    1170 <zero_trend_averages+0x50>
xor    %ebx,%ebx
jmp    13db <zero_trend_averages+0x2bb>
cs nopw 0x0(%rax,%rax,1)
nop
movq   $0x0,(%rcx,%rbp,8)
movsd  0x28(%rsp),%xmm0
add    $0x1,%rbx
cmp    %rbx,%r13
je     1170 <zero_trend_averages+0x50>
mov    (%r14,%rbx,8),%rax
movsd  (%rax,%rbp,8),%xmm0
call   1030 <isnan@plt>
mov    (%r14,%rbx,8),%rcx
test   %rax,%rax
jne    13c0 <zero_trend_averages+0x2a0>
movsd  (%rcx,%rbp,8),%xmm0
movapd %xmm0,%xmm1
subsd  0x38(%rsp),%xmm1
movapd %xmm1,%xmm2
xorpd  0xc03(%rip),%xmm2
xorpd  %xmm3,%xmm3
cmpltsd %xmm1,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm2,%xmm3
orpd   %xmm1,%xmm3
ucomisd 0x18(%rsp),%xmm3
jae    13c0 <zero_trend_averages+0x2a0>
subsd  0x8(%rsp),%xmm0
movsd  %xmm0,(%rcx,%rbp,8)
jmp    13c8 <zero_trend_averages+0x2a8>
mov    0x34(%rsp),%eax
test   %eax,%eax
je     1452 <zero_trend_averages+0x332>
movapd %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
mov    0x50(%rsp),%rcx
jmp    145d <zero_trend_averages+0x33d>
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rcx)
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @zero_trend_averages(i32 %0, i32 %1, double** %2, double %3, double* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca double**
%9 = alloca double
%10 = alloca double*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca i32
%19 = alloca x86_fp80
%20 = alloca x86_fp80
store i32 %0, i32* %6
store i32 %1, i32* %7
store double** %2, double*** %8
store double %3, double* %9
store double* %4, double** %10
store double 0.000000e+00, double* %17
store i32 0, i32* %18
store i32 0, i32* %12
br label %21
21: ; preds = %317, %5
%22 = load i32, i32* %12
%23 = load i32, i32* %7
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %320
25: ; preds = %21
store x86_fp80 0xK00000000000000000000, x86_fp80* %19
store x86_fp80 0xK00000000000000000000, x86_fp80* %20
store i32 0, i32* %13
store i32 0, i32* %11
br label %26
26: ; preds = %80, %25
%27 = load i32, i32* %11
%28 = load i32, i32* %6
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %83
30: ; preds = %26
%31 = load double**, double*** %8
%32 = load i32, i32* %11
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double*, double** %31, i64 %33
%35 = load double*, double** %34
%36 = load i32, i32* %12
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds double, double* %35, i64 %37
%39 = load double, double* %38
%40 = call i64 @isnan(double %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %79, label %42
42: ; preds = %30
%43 = load double**, double*** %8
%44 = load i32, i32* %11
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double*, double** %43, i64 %45
%47 = load double*, double** %46
%48 = load i32, i32* %12
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds double, double* %47, i64 %49
%51 = load double, double* %50
%52 = load double**, double*** %8
%53 = load i32, i32* %11
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds double*, double** %52, i64 %54
%56 = load double*, double** %55
%57 = load i32, i32* %12
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds double, double* %56, i64 %58
%60 = load double, double* %59
%61 = fmul double %51, %60
%62 = fpext double %61 to x86_fp80
%63 = load x86_fp80, x86_fp80* %19
%64 = fadd x86_fp80 %63, %62
store x86_fp80 %64, x86_fp80* %19
%65 = load double**, double*** %8
%66 = load i32, i32* %11
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double*, double** %65, i64 %67
%69 = load double*, double** %68
%70 = load i32, i32* %12
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds double, double* %69, i64 %71
%73 = load double, double* %72
%74 = fpext double %73 to x86_fp80
%75 = load x86_fp80, x86_fp80* %20
%76 = fadd x86_fp80 %75, %74
store x86_fp80 %76, x86_fp80* %20
%77 = load i32, i32* %13
%78 = add nsw i32 %77, 1
store i32 %78, i32* %13
br label %79
79: ; preds = %42, %30
br label %80
80: ; preds = %79
%81 = load i32, i32* %11
%82 = add nsw i32 %81, 1
store i32 %82, i32* %11
br label %26
83: ; preds = %26
%84 = load i32, i32* %13
%85 = icmp sgt i32 %84, 0
br i1 %85, label %86, label %107
86: ; preds = %83
%87 = load x86_fp80, x86_fp80* %20
%88 = load i32, i32* %13
%89 = sitofp i32 %88 to x86_fp80
%90 = fdiv x86_fp80 %87, %89
%91 = fptrunc x86_fp80 %90 to double
store double %91, double* %14
%92 = load x86_fp80, x86_fp80* %19
%93 = load i32, i32* %13
%94 = sitofp i32 %93 to x86_fp80
%95 = fdiv x86_fp80 %92, %94
%96 = load x86_fp80, x86_fp80* %20
%97 = load x86_fp80, x86_fp80* %20
%98 = fmul x86_fp80 %96, %97
%99 = load i32, i32* %13
%100 = load i32, i32* %13
%101 = mul nsw i32 %99, %100
%102 = sitofp i32 %101 to x86_fp80
%103 = fdiv x86_fp80 %98, %102
%104 = fsub x86_fp80 %95, %103
%105 = fptrunc x86_fp80 %104 to double
%106 = call double @sqrt(double %105)
store double %106, double* %16
br label %108
107: ; preds = %83
store double 0.000000e+00, double* %14
store double 0.000000e+00, double* %16
br label %108
108: ; preds = %107, %86
%109 = load i32, i32* %13
%110 = icmp sgt i32 %109, 0
br i1 %110, label %111, label %117
111: ; preds = %108
%112 = load double, double* %16
%113 = load double, double* %17
%114 = fadd double %113, %112
store double %114, double* %17
%115 = load i32, i32* %18
%116 = add nsw i32 %115, 1
store i32 %116, i32* %18
br label %117
117: ; preds = %111, %108
store x86_fp80 0xK00000000000000000000, x86_fp80* %19
store x86_fp80 0xK00000000000000000000, x86_fp80* %20
store i32 0, i32* %13
store i32 0, i32* %11
br label %118
118: ; preds = %217, %117
%119 = load i32, i32* %11
%120 = load i32, i32* %6
%121 = icmp slt i32 %119, %120
br i1 %121, label %122, label %220
122: ; preds = %118
%123 = load double**, double*** %8
%124 = load i32, i32* %11
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds double*, double** %123, i64 %125
%127 = load double*, double** %126
%128 = load i32, i32* %12
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds double, double* %127, i64 %129
%131 = load double, double* %130
%132 = call i64 @isnan(double %131)
%133 = icmp ne i64 %132, 0
br i1 %133, label %216, label %134
134: ; preds = %122
%135 = load double**, double*** %8
%136 = load i32, i32* %11
%137 = sext i32 %136 to i64
%138 = getelementptr inbounds double*, double** %135, i64 %137
%139 = load double*, double** %138
%140 = load i32, i32* %12
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds double, double* %139, i64 %141
%143 = load double, double* %142
%144 = load double, double* %14
%145 = fsub double %143, %144
%146 = fcmp ogt double %145, 0.000000e+00
br i1 %146, label %147, label %159
147: ; preds = %134
%148 = load double**, double*** %8
%149 = load i32, i32* %11
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds double*, double** %148, i64 %150
%152 = load double*, double** %151
%153 = load i32, i32* %12
%154 = sext i32 %153 to i64
%155 = getelementptr inbounds double, double* %152, i64 %154
%156 = load double, double* %155
%157 = load double, double* %14
%158 = fsub double %156, %157
br label %172
159: ; preds = %134
%160 = load double**, double*** %8
%161 = load i32, i32* %11
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds double*, double** %160, i64 %162
%164 = load double*, double** %163
%165 = load i32, i32* %12
%166 = sext i32 %165 to i64
%167 = getelementptr inbounds double, double* %164, i64 %166
%168 = load double, double* %167
%169 = load double, double* %14
%170 = fsub double %168, %169
%171 = fneg double %170
br label %172
172: ; preds = %159, %147
%173 = phi double [ %158, %147 ], [ %171, %159 ]
%174 = load double, double* %9
%175 = load double, double* %16
%176 = fmul double %174, %175
%177 = fcmp olt double %173, %176
br i1 %177, label %178, label %215
178: ; preds = %172
%179 = load double**, double*** %8
%180 = load i32, i32* %11
%181 = sext i32 %180 to i64
%182 = getelementptr inbounds double*, double** %179, i64 %181
%183 = load double*, double** %182
%184 = load i32, i32* %12
%185 = sext i32 %184 to i64
%186 = getelementptr inbounds double, double* %183, i64 %185
%187 = load double, double* %186
%188 = load double**, double*** %8
%189 = load i32, i32* %11
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds double*, double** %188, i64 %190
%192 = load double*, double** %191
%193 = load i32, i32* %12
%194 = sext i32 %193 to i64
%195 = getelementptr inbounds double, double* %192, i64 %194
%196 = load double, double* %195
%197 = fmul double %187, %196
%198 = fpext double %197 to x86_fp80
%199 = load x86_fp80, x86_fp80* %19
%200 = fadd x86_fp80 %199, %198
store x86_fp80 %200, x86_fp80* %19
%201 = load double**, double*** %8
%202 = load i32, i32* %11
%203 = sext i32 %202 to i64
%204 = getelementptr inbounds double*, double** %201, i64 %203
%205 = load double*, double** %204
%206 = load i32, i32* %12
%207 = sext i32 %206 to i64
%208 = getelementptr inbounds double, double* %205, i64 %207
%209 = load double, double* %208
%210 = fpext double %209 to x86_fp80
%211 = load x86_fp80, x86_fp80* %20
%212 = fadd x86_fp80 %211, %210
store x86_fp80 %212, x86_fp80* %20
%213 = load i32, i32* %13
%214 = add nsw i32 %213, 1
store i32 %214, i32* %13
br label %215
215: ; preds = %178, %172
br label %216
216: ; preds = %215, %122
br label %217
217: ; preds = %216
%218 = load i32, i32* %11
%219 = add nsw i32 %218, 1
store i32 %219, i32* %11
br label %118
220: ; preds = %118
%221 = load i32, i32* %13
%222 = icmp sgt i32 %221, 0
br i1 %222, label %223, label %229
223: ; preds = %220
%224 = load x86_fp80, x86_fp80* %20
%225 = load i32, i32* %13
%226 = sitofp i32 %225 to x86_fp80
%227 = fdiv x86_fp80 %224, %226
%228 = fptrunc x86_fp80 %227 to double
store double %228, double* %15
br label %230
229: ; preds = %220
store double 0.000000e+00, double* %15
br label %230
230: ; preds = %229, %223
store i32 0, i32* %11
br label %231
231: ; preds = %313, %230
%232 = load i32, i32* %11
%233 = load i32, i32* %6
%234 = icmp slt i32 %232, %233
br i1 %234, label %235, label %316
235: ; preds = %231
%236 = load double**, double*** %8
%237 = load i32, i32* %11
%238 = sext i32 %237 to i64
%239 = getelementptr inbounds double*, double** %236, i64 %238
%240 = load double*, double** %239
%241 = load i32, i32* %12
%242 = sext i32 %241 to i64
%243 = getelementptr inbounds double, double* %240, i64 %242
%244 = load double, double* %243
%245 = call i64 @isnan(double %244)
%246 = icmp ne i64 %245, 0
br i1 %246, label %291, label %247
247: ; preds = %235
%248 = load double**, double*** %8
%249 = load i32, i32* %11
%250 = sext i32 %249 to i64
%251 = getelementptr inbounds double*, double** %248, i64 %250
%252 = load double*, double** %251
%253 = load i32, i32* %12
%254 = sext i32 %253 to i64
%255 = getelementptr inbounds double, double* %252, i64 %254
%256 = load double, double* %255
%257 = load double, double* %14
%258 = fsub double %256, %257
%259 = fcmp ogt double %258, 0.000000e+00
br i1 %259, label %260, label %272
260: ; preds = %247
%261 = load double**, double*** %8
%262 = load i32, i32* %11
%263 = sext i32 %262 to i64
%264 = getelementptr inbounds double*, double** %261, i64 %263
%265 = load double*, double** %264
%266 = load i32, i32* %12
%267 = sext i32 %266 to i64
%268 = getelementptr inbounds double, double* %265, i64 %267
%269 = load double, double* %268
%270 = load double, double* %14
%271 = fsub double %269, %270
br label %285
272: ; preds = %247
%273 = load double**, double*** %8
%274 = load i32, i32* %11
%275 = sext i32 %274 to i64
%276 = getelementptr inbounds double*, double** %273, i64 %275
%277 = load double*, double** %276
%278 = load i32, i32* %12
%279 = sext i32 %278 to i64
%280 = getelementptr inbounds double, double* %277, i64 %279
%281 = load double, double* %280
%282 = load double, double* %14
%283 = fsub double %281, %282
%284 = fneg double %283
br label %285
285: ; preds = %272, %260
%286 = phi double [ %271, %260 ], [ %284, %272 ]
%287 = load double, double* %9
%288 = load double, double* %16
%289 = fmul double %287, %288
%290 = fcmp oge double %286, %289
br i1 %290, label %291, label %300
291: ; preds = %285, %235
%292 = load double**, double*** %8
%293 = load i32, i32* %11
%294 = sext i32 %293 to i64
%295 = getelementptr inbounds double*, double** %292, i64 %294
%296 = load double*, double** %295
%297 = load i32, i32* %12
%298 = sext i32 %297 to i64
%299 = getelementptr inbounds double, double* %296, i64 %298
store double 0.000000e+00, double* %299
br label %312
300: ; preds = %285
%301 = load double, double* %15
%302 = load double**, double*** %8
%303 = load i32, i32* %11
%304 = sext i32 %303 to i64
%305 = getelementptr inbounds double*, double** %302, i64 %304
%306 = load double*, double** %305
%307 = load i32, i32* %12
%308 = sext i32 %307 to i64
%309 = getelementptr inbounds double, double* %306, i64 %308
%310 = load double, double* %309
%311 = fsub double %310, %301
store double %311, double* %309
br label %312
312: ; preds = %300, %291
br label %313
313: ; preds = %312
%314 = load i32, i32* %11
%315 = add nsw i32 %314, 1
store i32 %315, i32* %11
br label %231
316: ; preds = %231
br label %317
317: ; preds = %316
%318 = load i32, i32* %12
%319 = add nsw i32 %318, 1
store i32 %319, i32* %12
br label %21
320: ; preds = %21
%321 = load i32, i32* %18
%322 = icmp sgt i32 %321, 0
br i1 %322, label %323, label %328
323: ; preds = %320
%324 = load double, double* %17
%325 = load i32, i32* %18
%326 = sitofp i32 %325 to double
%327 = fdiv double %324, %326
store double %327, double* %17
br label %328
328: ; preds = %323, %320
%329 = load double, double* %17
%330 = load double*, double** %10
store double %329, double* %330
ret void
}

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