#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);
double pow(double, double);
double sqrt(double);
void w_ave(int ngood, double *data, double *sig, double *ws, double *ave) {
  int j;
  double weight = 0.0, a = 2.0, b = 2.0, delta, dumval;
  *ave = 0.0;
  for (j = 0; j < ngood; j++) {
    if (!isnan(data[j]) && !isnan(ws[j]) && !isnan(sig[j])) {
      *ave += ws[j] * data[j] / (sig[j] * sig[j]);
      weight += ws[j] / (sig[j] * sig[j]);
    }
  }
  *ave /= weight;
  dumval = sqrt((double)ngood / (double)(ngood - 1));
  for (j = 0; j < ngood; j++) {
    if (!isnan(data[j]) && !isnan(sig[j])) {
      delta = dumval * (data[j] - *ave) / sig[j];
      ws[j] = 1.0 / (1.0 + pow(((delta) > 0 ? (delta) : -(delta)) / a, b));
    }
  }
}


x86 assembly (clang, -O0):
<w_ave>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xea5(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe98(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x28(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1268 <w_ave+0x138>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%eax
jne    1255 <w_ave+0x125>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%eax
jne    1255 <w_ave+0x125>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%eax
jne    1255 <w_ave+0x125>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
divsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
jmp    125a <w_ave+0x12a>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    117f <w_ave+0x4f>
movsd  -0x38(%rbp),%xmm1
mov    -0x28(%rbp),%rax
movsd  (%rax),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,(%rax)
cvtsi2sdl -0x4(%rbp),%xmm0
mov    -0x4(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,-0x58(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    13a1 <w_ave+0x271>
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%eax
jne    138e <w_ave+0x25e>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%eax
jne    138e <w_ave+0x25e>
movsd  -0x58(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
mov    -0x28(%rbp),%rax
subsd  (%rax),%xmm1
mulsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
divsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1334 <w_ave+0x204>
movsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    1355 <w_ave+0x225>
movsd  -0x50(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
call   1040 <pow@plt>
movsd  0xc97(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0xc8b(%rip),%xmm0
divsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1393 <w_ave+0x263>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12a1 <w_ave+0x171>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<w_ave>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8,%r14
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %edi,%ebp
movq   $0x0,(%r8)
mov    %edi,%r13d
test   %edi,%edi
jle    1208 <w_ave+0xe8>
mov    %r14,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %r14d,%r14d
jmp    1179 <w_ave+0x59>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r14
cmp    %r14,%r13
je     11f6 <w_ave+0xd6>
movsd  (%rbx,%r14,8),%xmm0
call   1030 <isnan@plt>
test   %eax,%eax
jne    1170 <w_ave+0x50>
movsd  (%r15,%r14,8),%xmm0
call   1030 <isnan@plt>
test   %eax,%eax
jne    1170 <w_ave+0x50>
movsd  (%r12,%r14,8),%xmm0
call   1030 <isnan@plt>
test   %eax,%eax
jne    1170 <w_ave+0x50>
movsd  (%r15,%r14,8),%xmm0
mulsd  (%rbx,%r14,8),%xmm0
movsd  (%r12,%r14,8),%xmm1
mulsd  %xmm1,%xmm1
divsd  %xmm1,%xmm0
mov    0x10(%rsp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
movsd  (%r15,%r14,8),%xmm0
movsd  (%r12,%r14,8),%xmm1
mulsd  %xmm1,%xmm1
divsd  %xmm1,%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
jmp    1170 <w_ave+0x50>
mov    0x10(%rsp),%r14
movsd  (%r14),%xmm1
divsd  0x8(%rsp),%xmm1
jmp    1210 <w_ave+0xf0>
movsd  0xdf0(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebp,%xmm0
movsd  %xmm1,(%r14)
lea    -0x1(%rbp),%eax
xorps  %xmm1,%xmm1
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     123a <w_ave+0x11a>
sqrtsd %xmm0,%xmm0
jmp    123f <w_ave+0x11f>
call   1040 <sqrt@plt>
movsd  %xmm0,0x8(%rsp)
test   %ebp,%ebp
jle    12e4 <w_ave+0x1c4>
xor    %ebp,%ebp
jmp    1269 <w_ave+0x149>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%rbp
cmp    %rbp,%r13
je     12e4 <w_ave+0x1c4>
movsd  (%rbx,%rbp,8),%xmm0
call   1030 <isnan@plt>
test   %eax,%eax
jne    1260 <w_ave+0x140>
movsd  (%r12,%rbp,8),%xmm0
call   1030 <isnan@plt>
test   %eax,%eax
jne    1260 <w_ave+0x140>
movsd  (%rbx,%rbp,8),%xmm0
subsd  (%r14),%xmm0
mulsd  0x8(%rsp),%xmm0
divsd  (%r12,%rbp,8),%xmm0
movapd %xmm0,%xmm1
xorpd  0xd78(%rip),%xmm1
xorpd  %xmm2,%xmm2
cmpltsd %xmm0,%xmm2
andpd  %xmm2,%xmm0
andnpd %xmm1,%xmm2
orpd   %xmm0,%xmm2
mulsd  0xd43(%rip),%xmm2
mulsd  %xmm2,%xmm2
movsd  0xd3f(%rip),%xmm0
addsd  %xmm0,%xmm2
divsd  %xmm2,%xmm0
movsd  %xmm0,(%r15,%rbp,8)
jmp    1260 <w_ave+0x140>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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