#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 _FDIV_(double, int /*<<< orphan*/, double, double);
int /*<<< orphan*/ _FSQRT_(double, double);
double correlation_s(const double *restrict in0, const double *restrict in1,
                     const double *restrict weight, double missval1,
                     double missval2, long gridsize) {
  long i;
  double sum0, sum1, sum00, sum01, sum11, wsum0;
  double out;
  sum0 = sum1 = sum00 = sum01 = sum11 = 0;
  wsum0 = 0;
  for (i = 0; i < gridsize; ++i) {
    if ((weight[i] < missval1 || missval1 < weight[i]) &&
        (in0[i] < missval1 || missval1 < in0[i]) &&
        (in1[i] < missval2 || missval2 < in1[i])) {
      sum0 += weight[i] * in0[i];
      sum1 += weight[i] * in1[i];
      sum00 += weight[i] * in0[i] * in0[i];
      sum01 += weight[i] * in0[i] * in1[i];
      sum11 += weight[i] * in1[i] * in1[i];
      wsum0 += weight[i];
    }
  }
  out = (wsum0 < 0 || 0 < wsum0)
            ? _FDIV_((sum01 * wsum0 - sum0 * sum1),
                     _FSQRT_((sum00 * wsum0 - sum0 * sum0) *
                                 (sum11 * wsum0 - sum1 * sum1),
                             missval1),
                     missval1, missval2)
            : missval1;
  return (out);
}


x86 assembly (clang, -O0):
<correlation_s>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movsd  %xmm0,-0x20(%rbp)
movsd  %xmm1,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x58(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x68(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
jge    1363 <correlation_s+0x243>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     11c3 <correlation_s+0xa3>
movsd  -0x20(%rbp),%xmm1
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    134d <correlation_s+0x22d>
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     11fb <correlation_s+0xdb>
movsd  -0x20(%rbp),%xmm1
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    134d <correlation_s+0x22d>
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x28(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     1233 <correlation_s+0x113>
movsd  -0x28(%rbp),%xmm1
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
ucomisd %xmm1,%xmm0
jbe    134d <correlation_s+0x22d>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x50(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x8(%rbp),%rax
mov    -0x38(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x58(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x60(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    1352 <correlation_s+0x232>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    117d <correlation_s+0x5d>
xorps  %xmm0,%xmm0
ucomisd -0x68(%rbp),%xmm0
ja     1383 <correlation_s+0x263>
movsd  -0x68(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    144f <correlation_s+0x32f>
movsd  -0x58(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x80(%rbp)
movsd  -0x50(%rbp),%xmm0
movsd  -0x68(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x60(%rbp),%xmm1
movsd  -0x68(%rbp),%xmm3
movsd  -0x48(%rbp),%xmm2
mulsd  -0x48(%rbp),%xmm2
movq   %xmm2,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm2
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
call   1030 <_FSQRT_@plt>
movsd  -0x80(%rbp),%xmm0
mov    %eax,%edi
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
call   1040 <_FDIV_@plt>
movsd  %xmm0,-0x78(%rbp)
jmp    1459 <correlation_s+0x339>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x78(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<correlation_s>:
sub    $0x28,%rsp
movapd %xmm0,%xmm7
test   %rcx,%rcx
jle    121d <correlation_s+0xfd>
movapd %xmm1,%xmm8
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
xor    %eax,%eax
xorpd  %xmm6,%xmm6
xorpd  %xmm2,%xmm2
jmp    1159 <correlation_s+0x39>
nopw   0x0(%rax,%rax,1)
add    $0x1,%rax
cmp    %rax,%rcx
je     11a1 <correlation_s+0x81>
movsd  (%rdx,%rax,8),%xmm3
ucomisd %xmm3,%xmm7
je     1150 <correlation_s+0x30>
movsd  (%rdi,%rax,8),%xmm4
ucomisd %xmm4,%xmm7
je     1150 <correlation_s+0x30>
movsd  (%rsi,%rax,8),%xmm5
ucomisd %xmm5,%xmm8
je     1150 <correlation_s+0x30>
addsd  %xmm3,%xmm0
unpcklpd %xmm3,%xmm3
unpcklpd %xmm5,%xmm4
mulpd  %xmm4,%xmm3
addpd  %xmm3,%xmm2
mulsd  %xmm3,%xmm5
addsd  %xmm5,%xmm6
mulpd  %xmm4,%xmm3
addpd  %xmm3,%xmm1
jmp    1150 <correlation_s+0x30>
xorpd  %xmm3,%xmm3
ucomisd %xmm3,%xmm0
je     121d <correlation_s+0xfd>
movapd 0xe4d(%rip),%xmm3
xorpd  %xmm2,%xmm3
movapd %xmm2,%xmm4
unpckhpd %xmm2,%xmm4
mulsd  %xmm3,%xmm4
mulsd  %xmm0,%xmm6
addsd  %xmm4,%xmm6
movapd %xmm6,0x10(%rsp)
mulpd  %xmm2,%xmm2
unpcklpd %xmm0,%xmm0
mulpd  %xmm0,%xmm1
subpd  %xmm2,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
mulsd  %xmm1,%xmm0
movapd %xmm7,%xmm1
movsd  %xmm8,0x8(%rsp)
movsd  %xmm7,(%rsp)
call   1030 <_FSQRT_@plt>
movaps 0x10(%rsp),%xmm0
mov    %eax,%edi
movsd  (%rsp),%xmm1
movsd  0x8(%rsp),%xmm2
add    $0x28,%rsp
jmp    1040 <_FDIV_@plt>
movapd %xmm7,%xmm0
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
define double @correlation_s(double* noalias nocapture %0, double* noalias nocapture %1, double* noalias nocapture %2, double %3, double %4, i64 %5) {
%7 = icmp sgt i64 %5, 0
br i1 %7, label %8, label %60
8: ; preds = %6, %36
%9 = phi i64 [ %41, %36 ], [ 0, %6 ]
%10 = phi double [ %38, %36 ], [ 0.000000e+00, %6 ]
%11 = phi double [ %37, %36 ], [ 0.000000e+00, %6 ]
%12 = phi <2 x double> [ %39, %36 ], [ zeroinitializer, %6 ]
%13 = phi <2 x double> [ %40, %36 ], [ zeroinitializer, %6 ]
%14 = getelementptr inbounds double, double* %2, i64 %9
%15 = load double, double* %14
%16 = fcmp ueq double %15, %3
br i1 %16, label %36, label %17
17: ; preds = %8
%18 = getelementptr inbounds double, double* %0, i64 %9
%19 = load double, double* %18
%20 = fcmp ueq double %19, %3
br i1 %20, label %36, label %21
21: ; preds = %17
%22 = getelementptr inbounds double, double* %1, i64 %9
%23 = load double, double* %22
%24 = fcmp ueq double %23, %4
br i1 %24, label %36, label %25
25: ; preds = %21
%26 = insertelement <2 x double> poison, double %15, i64 0
%27 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> zeroinitializer
%28 = insertelement <2 x double> poison, double %19, i64 0
%29 = insertelement <2 x double> %28, double %23, i64 1
%30 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %27, <2 x double> %29, <2 x double> %13)
%31 = fmul <2 x double> %27, %29
%32 = extractelement <2 x double> %31, i64 0
%33 = tail call double @llvm.fmuladd.f64(double %32, double %23, double %11)
%34 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %31, <2 x double> %29, <2 x double> %12)
%35 = fadd double %10, %15
br label %36
36: ; preds = %21, %17, %8, %25
%37 = phi double [ %33, %25 ], [ %11, %8 ], [ %11, %17 ], [ %11, %21 ]
%38 = phi double [ %35, %25 ], [ %10, %8 ], [ %10, %17 ], [ %10, %21 ]
%39 = phi <2 x double> [ %34, %25 ], [ %12, %8 ], [ %12, %17 ], [ %12, %21 ]
%40 = phi <2 x double> [ %30, %25 ], [ %13, %8 ], [ %13, %17 ], [ %13, %21 ]
%41 = add nuw nsw i64 %9, 1
%42 = icmp eq i64 %41, %5
br i1 %42, label %43, label %8
43: ; preds = %36
%44 = fcmp ueq double %38, 0.000000e+00
br i1 %44, label %60, label %45
45: ; preds = %43
%46 = fneg <2 x double> %40
%47 = shufflevector <2 x double> %40, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%48 = fmul <2 x double> %47, %46
%49 = extractelement <2 x double> %48, i64 0
%50 = tail call double @llvm.fmuladd.f64(double %37, double %38, double %49)
%51 = fmul <2 x double> %40, %46
%52 = insertelement <2 x double> poison, double %38, i64 0
%53 = shufflevector <2 x double> %52, <2 x double> poison, <2 x i32> zeroinitializer
%54 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %39, <2 x double> %53, <2 x double> %51)
%55 = shufflevector <2 x double> %54, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%56 = fmul <2 x double> %54, %55
%57 = extractelement <2 x double> %56, i64 0
%58 = tail call i32 @_FSQRT_(double %57, double %3)
%59 = tail call double @_FDIV_(double %50, i32 %58, double %3, double %4)
br label %60
60: ; preds = %6, %43, %45
%61 = phi double [ %59, %45 ], [ %3, %43 ], [ %3, %6 ]
ret double %61
}