#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, double, double, double);
double _FMUL_(double, double, double, double);
double _FSUB_(double, double, double, double);
int covariance_t(long gridsize, double missval1, double missval2, int *nofvals,
                 double *work0, double *work1, double *work2) {
  long i;
  int nvals, nmiss = 0;
  double temp;
  double dnvals;
  double covar;
  for (i = 0; i < gridsize; i++) {
    nvals = nofvals[i];
    dnvals = nvals;
    if (nvals > 0) {
      temp = _FDIV_(_FMUL_(work0[i], work1[i], missval1, missval2),
                    dnvals * dnvals, missval1, missval2);
      covar = _FSUB_(_FDIV_(work2[i], dnvals, missval1, missval2), temp,
                     missval1, missval2);
      if ((((covar) != (covar)) || ((missval1) != (missval1))
               ? (((covar) != (covar)) && ((missval1) != (missval1)) ? 1 : 0)
               : !(covar < missval1 || missval1 < covar)))
        nmiss++;
    } else {
      nmiss++;
      covar = missval1;
    }
    work0[i] = covar;
  }
  return nmiss;
}


x86 assembly (clang, -O0):
<covariance_t>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
mov    %rcx,-0x30(%rbp)
mov    %r8,-0x38(%rbp)
movl   $0x0,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x8(%rbp),%rax
jge    1307 <covariance_t+0x1d7>
mov    -0x20(%rbp),%rax
mov    -0x40(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x44(%rbp)
cvtsi2sdl -0x44(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
cmpl   $0x0,-0x44(%rbp)
jle    12d1 <covariance_t+0x1a1>
mov    -0x28(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x30(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm3
call   1030 <_FMUL_@plt>
movsd  -0x58(%rbp),%xmm1
mulsd  -0x58(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm3
call   1050 <_FDIV_@plt>
movsd  %xmm0,-0x50(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  -0x58(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm3
call   1050 <_FDIV_@plt>
movsd  -0x50(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm3
call   1040 <_FSUB_@plt>
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
ucomisd -0x60(%rbp),%xmm0
jne    1247 <covariance_t+0x117>
jp     1247 <covariance_t+0x117>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    1247 <covariance_t+0x117>
jp     1247 <covariance_t+0x117>
jmp    129b <covariance_t+0x16b>
movsd  -0x60(%rbp),%xmm0
ucomisd -0x60(%rbp),%xmm0
jne    1262 <covariance_t+0x132>
jp     1262 <covariance_t+0x132>
jmp    128c <covariance_t+0x15c>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jne    127d <covariance_t+0x14d>
jp     127d <covariance_t+0x14d>
jmp    128c <covariance_t+0x15c>
mov    $0x1,%al
test   $0x1,%al
jne    12c3 <covariance_t+0x193>
jmp    12cc <covariance_t+0x19c>
xor    %eax,%eax
test   $0x1,%al
jne    12c3 <covariance_t+0x193>
jmp    12cc <covariance_t+0x19c>
movsd  -0x60(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     12cc <covariance_t+0x19c>
movsd  -0x10(%rbp),%xmm1
movsd  -0x60(%rbp),%xmm0
ucomisd %xmm1,%xmm0
ja     12cc <covariance_t+0x19c>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    12e4 <covariance_t+0x1b4>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
mov    -0x28(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    1165 <covariance_t+0x35>
mov    -0x48(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<covariance_t>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,0x18(%rsp)
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
test   %rdi,%rdi
jle    1242 <covariance_t+0x112>
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %rsi,%r12
mov    %rdi,%r13
xor    %r14d,%r14d
xor    %ebp,%ebp
jmp    118b <covariance_t+0x5b>
nopw   0x0(%rax,%rax,1)
add    $0x1,%ebp
movsd  (%rsp),%xmm0
movsd  %xmm0,(%rbx,%r14,8)
add    $0x1,%r14
cmp    %r14,%r13
je     1244 <covariance_t+0x114>
mov    (%r12,%r14,4),%eax
test   %eax,%eax
jle    1170 <covariance_t+0x40>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x10(%rsp)
movsd  (%rbx,%r14,8),%xmm0
movsd  (%r15,%r14,8),%xmm1
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm3
call   1030 <_FMUL_@plt>
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm1
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm3
call   1050 <_FDIV_@plt>
movsd  %xmm0,0x20(%rsp)
mov    0x18(%rsp),%rax
movsd  (%rax,%r14,8),%xmm0
movsd  0x10(%rsp),%xmm1
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm3
call   1050 <_FDIV_@plt>
movsd  0x20(%rsp),%xmm1
movsd  (%rsp),%xmm2
movsd  0x8(%rsp),%xmm3
call   1040 <_FSUB_@plt>
ucomisd (%rsp),%xmm0
jp     1228 <covariance_t+0xf8>
jne    1178 <covariance_t+0x48>
add    $0x1,%ebp
jmp    1178 <covariance_t+0x48>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm1
jnp    1178 <covariance_t+0x48>
ucomisd %xmm0,%xmm0
jp     1220 <covariance_t+0xf0>
jmp    1178 <covariance_t+0x48>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @covariance_t(i64 %0, double %1, double %2, i32* %3, double* %4, double* %5, double* %6) {
%8 = alloca i64
%9 = alloca double
%10 = alloca double
%11 = alloca i32*
%12 = alloca double*
%13 = alloca double*
%14 = alloca double*
%15 = alloca i64
%16 = alloca i32
%17 = alloca i32
%18 = alloca double
%19 = alloca double
%20 = alloca double
store i64 %0, i64* %8
store double %1, double* %9
store double %2, double* %10
store i32* %3, i32** %11
store double* %4, double** %12
store double* %5, double** %13
store double* %6, double** %14
store i32 0, i32* %17
store i64 0, i64* %15
br label %21
21: ; preds = %102, %7
%22 = load i64, i64* %15
%23 = load i64, i64* %8
%24 = icmp slt i64 %22, %23
br i1 %24, label %25, label %105
25: ; preds = %21
%26 = load i32*, i32** %11
%27 = load i64, i64* %15
%28 = getelementptr inbounds i32, i32* %26, i64 %27
%29 = load i32, i32* %28
store i32 %29, i32* %16
%30 = load i32, i32* %16
%31 = sitofp i32 %30 to double
store double %31, double* %19
%32 = load i32, i32* %16
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %93
34: ; preds = %25
%35 = load double*, double** %12
%36 = load i64, i64* %15
%37 = getelementptr inbounds double, double* %35, i64 %36
%38 = load double, double* %37
%39 = load double*, double** %13
%40 = load i64, i64* %15
%41 = getelementptr inbounds double, double* %39, i64 %40
%42 = load double, double* %41
%43 = load double, double* %9
%44 = load double, double* %10
%45 = call double @_FMUL_(double %38, double %42, double %43, double %44)
%46 = load double, double* %19
%47 = load double, double* %19
%48 = fmul double %46, %47
%49 = load double, double* %9
%50 = load double, double* %10
%51 = call double @_FDIV_(double %45, double %48, double %49, double %50)
store double %51, double* %18
%52 = load double*, double** %14
%53 = load i64, i64* %15
%54 = getelementptr inbounds double, double* %52, i64 %53
%55 = load double, double* %54
%56 = load double, double* %19
%57 = load double, double* %9
%58 = load double, double* %10
%59 = call double @_FDIV_(double %55, double %56, double %57, double %58)
%60 = load double, double* %18
%61 = load double, double* %9
%62 = load double, double* %10
%63 = call double @_FSUB_(double %59, double %60, double %61, double %62)
store double %63, double* %20
%64 = load double, double* %20
%65 = load double, double* %20
%66 = fcmp une double %64, %65
br i1 %66, label %71, label %67
67: ; preds = %34
%68 = load double, double* %9
%69 = load double, double* %9
%70 = fcmp une double %68, %69
br i1 %70, label %71, label %81
71: ; preds = %67, %34
%72 = load double, double* %20
%73 = load double, double* %20
%74 = fcmp une double %72, %73
br i1 %74, label %75, label %80
75: ; preds = %71
%76 = load double, double* %9
%77 = load double, double* %9
%78 = fcmp une double %76, %77
br i1 %78, label %79, label %80
79: ; preds = %75
br i1 true, label %89, label %92
80: ; preds = %75, %71
br i1 false, label %89, label %92
81: ; preds = %67
%82 = load double, double* %20
%83 = load double, double* %9
%84 = fcmp olt double %82, %83
br i1 %84, label %92, label %85
85: ; preds = %81
%86 = load double, double* %9
%87 = load double, double* %20
%88 = fcmp olt double %86, %87
br i1 %88, label %92, label %89
89: ; preds = %85, %80, %79
%90 = load i32, i32* %17
%91 = add nsw i32 %90, 1
store i32 %91, i32* %17
br label %92
92: ; preds = %89, %85, %81, %80, %79
br label %97
93: ; preds = %25
%94 = load i32, i32* %17
%95 = add nsw i32 %94, 1
store i32 %95, i32* %17
%96 = load double, double* %9
store double %96, double* %20
br label %97
97: ; preds = %93, %92
%98 = load double, double* %20
%99 = load double*, double** %12
%100 = load i64, i64* %15
%101 = getelementptr inbounds double, double* %99, i64 %100
store double %98, double* %101
br label %102
102: ; preds = %97
%103 = load i64, i64* %15
%104 = add nsw i64 %103, 1
store i64 %104, i64* %15
br label %21
105: ; preds = %21
%106 = load i32, i32* %17
ret i32 %106
}

LLVM IR (-O2):
define i32 @covariance_t(i64 %0, double %1, double %2, i32* nocapture %3, double* nocapture %4, double* nocapture %5, double* nocapture %6) {
%8 = icmp sgt i64 %0, 0
br i1 %8, label %9, label %46
9: ; preds = %7
%10 = fcmp uno double %1, 0.000000e+00
br label %11
11: ; preds = %9, %40
%12 = phi i64 [ 0, %9 ], [ %44, %40 ]
%13 = phi i32 [ 0, %9 ], [ %41, %40 ]
%14 = getelementptr inbounds i32, i32* %3, i64 %12
%15 = load i32, i32* %14
%16 = sitofp i32 %15 to double
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %38
18: ; preds = %11
%19 = getelementptr inbounds double, double* %4, i64 %12
%20 = load double, double* %19
%21 = getelementptr inbounds double, double* %5, i64 %12
%22 = load double, double* %21
%23 = tail call double @_FMUL_(double %20, double %22, double %1, double %2)
%24 = fmul double %16, %16
%25 = tail call double @_FDIV_(double %23, double %24, double %1, double %2)
%26 = getelementptr inbounds double, double* %6, i64 %12
%27 = load double, double* %26
%28 = tail call double @_FDIV_(double %27, double %16, double %1, double %2)
%29 = tail call double @_FSUB_(double %28, double %25, double %1, double %2)
%30 = fcmp uno double %29, %1
br i1 %30, label %31, label %34
31: ; preds = %18
%32 = fcmp uno double %29, 0.000000e+00
%33 = and i1 %10, %32
br i1 %33, label %36, label %40
34: ; preds = %18
%35 = fcmp ueq double %29, %1
br i1 %35, label %36, label %40
36: ; preds = %34, %31
%37 = add nsw i32 %13, 1
br label %40
38: ; preds = %11
%39 = add nsw i32 %13, 1
br label %40
40: ; preds = %34, %36, %31, %38
%41 = phi i32 [ %37, %36 ], [ %13, %31 ], [ %13, %34 ], [ %39, %38 ]
%42 = phi double [ %29, %36 ], [ %29, %31 ], [ %29, %34 ], [ %1, %38 ]
%43 = getelementptr inbounds double, double* %4, i64 %12
store double %42, double* %43
%44 = add nuw nsw i64 %12, 1
%45 = icmp eq i64 %44, %0
br i1 %45, label %46, label %11
46: ; preds = %40, %7
%47 = phi i32 [ 0, %7 ], [ %41, %40 ]
ret i32 %47
}