#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 /*<<< orphan*/ isnan(double);
long double mean(int n, double *data, double *ysig) {
  int i;
  int num = 0;
  long double meanval = 0;
  for (i = 0; i < n; i++) {
    if (!isnan(data[i]) && !isnan(ysig[i])) {
      meanval += (long double)(data[i] / (ysig[i] * ysig[i]));
      num++;
    }
  }
  meanval /= (double)num;
  return meanval;
}


x86 assembly (clang, -O0):
<mean>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
fldz
fstpt  -0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11c2 <mean+0xb2>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%eax
jne    11af <mean+0x9f>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%eax
jne    11af <mean+0x9f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm1,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
fldl   -0x40(%rbp)
fldt   -0x30(%rbp)
faddp  %st,%st(1)
fstpt  -0x30(%rbp)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11b4 <mean+0xa4>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1136 <mean+0x26>
cvtsi2sdl -0x20(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
fldl   -0x38(%rbp)
fldt   -0x30(%rbp)
fdivp  %st,%st(1)
fstpt  -0x30(%rbp)
fldt   -0x30(%rbp)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mean>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
fldz
test   %edi,%edi
jle    1195 <mean+0x85>
mov    %rdx,%r14
mov    %rsi,%rbx
fstp   %st(0)
mov    %edi,%r15d
xor    %ebp,%ebp
fldz
xor    %r12d,%r12d
jmp    114d <mean+0x3d>
cs nopw 0x0(%rax,%rax,1)
fldt   0xc(%rsp)
add    $0x1,%rbp
cmp    %rbp,%r15
je     1198 <mean+0x88>
fstpt  0xc(%rsp)
movsd  (%rbx,%rbp,8),%xmm0
call   1030 <isnan@plt>
test   %eax,%eax
jne    1140 <mean+0x30>
movsd  (%r14,%rbp,8),%xmm0
call   1030 <isnan@plt>
test   %eax,%eax
jne    1140 <mean+0x30>
movsd  (%rbx,%rbp,8),%xmm0
movsd  (%r14,%rbp,8),%xmm1
mulsd  %xmm1,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,0x18(%rsp)
fldt   0xc(%rsp)
faddl  0x18(%rsp)
add    $0x1,%r12d
jmp    1144 <mean+0x34>
xor    %r12d,%r12d
mov    %r12d,0x8(%rsp)
fidivl 0x8(%rsp)
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define x86_fp80 @mean(i32 %0, double* %1, double* %2) {
%4 = alloca i32
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca x86_fp80
store i32 %0, i32* %4
store double* %1, double** %5
store double* %2, double** %6
store i32 0, i32* %8
store x86_fp80 0xK00000000000000000000, x86_fp80* %9
store i32 0, i32* %7
br label %10
10: ; preds = %54, %3
%11 = load i32, i32* %7
%12 = load i32, i32* %4
%13 = icmp slt i32 %11, %12
br i1 %13, label %14, label %57
14: ; preds = %10
%15 = load double*, double** %5
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = call i32 @isnan(double %19)
%21 = icmp ne i32 %20, 0
br i1 %21, label %53, label %22
22: ; preds = %14
%23 = load double*, double** %6
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = call i32 @isnan(double %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %53, label %30
30: ; preds = %22
%31 = load double*, double** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds double, double* %31, i64 %33
%35 = load double, double* %34
%36 = load double*, double** %6
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
%40 = load double, double* %39
%41 = load double*, double** %6
%42 = load i32, i32* %7
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds double, double* %41, i64 %43
%45 = load double, double* %44
%46 = fmul double %40, %45
%47 = fdiv double %35, %46
%48 = fpext double %47 to x86_fp80
%49 = load x86_fp80, x86_fp80* %9
%50 = fadd x86_fp80 %49, %48
store x86_fp80 %50, x86_fp80* %9
%51 = load i32, i32* %8
%52 = add nsw i32 %51, 1
store i32 %52, i32* %8
br label %53
53: ; preds = %30, %22, %14
br label %54
54: ; preds = %53
%55 = load i32, i32* %7
%56 = add nsw i32 %55, 1
store i32 %56, i32* %7
br label %10
57: ; preds = %10
%58 = load i32, i32* %8
%59 = sitofp i32 %58 to double
%60 = fpext double %59 to x86_fp80
%61 = load x86_fp80, x86_fp80* %9
%62 = fdiv x86_fp80 %61, %60
store x86_fp80 %62, x86_fp80* %9
%63 = load x86_fp80, x86_fp80* %9
ret x86_fp80 %63
}

LLVM IR (-O2):
define x86_fp80 @mean(i32 %0, double* nocapture %1, double* nocapture %2) {
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %33
5: ; preds = %3
%6 = zext i32 %0 to i64
br label %7
7: ; preds = %5, %28
%8 = phi i64 [ 0, %5 ], [ %31, %28 ]
%9 = phi x86_fp80 [ 0xK00000000000000000000, %5 ], [ %30, %28 ]
%10 = phi i32 [ 0, %5 ], [ %29, %28 ]
%11 = getelementptr inbounds double, double* %1, i64 %8
%12 = load double, double* %11
%13 = tail call i32 @isnan(double %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %28
15: ; preds = %7
%16 = getelementptr inbounds double, double* %2, i64 %8
%17 = load double, double* %16
%18 = tail call i32 @isnan(double %17)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %15
%21 = load double, double* %11
%22 = load double, double* %16
%23 = fmul double %22, %22
%24 = fdiv double %21, %23
%25 = fpext double %24 to x86_fp80
%26 = fadd x86_fp80 %9, %25
%27 = add nsw i32 %10, 1
br label %28
28: ; preds = %7, %15, %20
%29 = phi i32 [ %10, %7 ], [ %10, %15 ], [ %27, %20 ]
%30 = phi x86_fp80 [ %9, %7 ], [ %9, %15 ], [ %26, %20 ]
%31 = add nuw nsw i64 %8, 1
%32 = icmp eq i64 %31, %6
br i1 %32, label %33, label %7
33: ; preds = %28, %3
%34 = phi i32 [ 0, %3 ], [ %29, %28 ]
%35 = phi x86_fp80 [ 0xK00000000000000000000, %3 ], [ %30, %28 ]
%36 = sitofp i32 %34 to x86_fp80
%37 = fdiv x86_fp80 %35, %36
ret x86_fp80 %37
}