#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 fabs(double);
void gsw_add_mean(double *data_in, double lon, double lat, double *data_out) {
  int k, nmean;
  double data_mean;
  nmean = 0;
  data_mean = 0.0;
  for (k = 0; k < 4; k++) {
    if (fabs(data_in[k]) <= 100.0) {
      nmean++;
      data_mean = data_mean + data_in[k];
    }
  }
  if (nmean == 0)
    data_mean = 0.0;
  else
    data_mean = data_mean / nmean;
  for (k = 0; k < 4; k++) {
    if (fabs(data_in[k]) >= 100.0)
      data_out[k] = data_mean;
    else
      data_out[k] = data_in[k];
  }
  return;
}


x86 assembly (clang, -O0):
<gsw_add_mean>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movl   $0x0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    1193 <gsw_add_mean+0x93>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm1
movaps 0xec6(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xeaa(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1180 <gsw_add_mean+0x80>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
addsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    1185 <gsw_add_mean+0x85>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112c <gsw_add_mean+0x2c>
cmpl   $0x0,-0x28(%rbp)
jne    11aa <gsw_add_mean+0xaa>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11bd <gsw_add_mean+0xbd>
movsd  -0x30(%rbp),%xmm0
cvtsi2sdl -0x28(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0x4,-0x24(%rbp)
jge    123c <gsw_add_mean+0x13c>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movaps 0xe2e(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  0xe12(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     120f <gsw_add_mean+0x10f>
movsd  -0x30(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    1229 <gsw_add_mean+0x129>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
jmp    122e <gsw_add_mean+0x12e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11c4 <gsw_add_mean+0xc4>
pop    %rbp
ret

x86 assembly (clang, -O2):
<gsw_add_mean>:
movupd (%rdi),%xmm0
movupd 0x10(%rdi),%xmm3
movapd 0xeef(%rip),%xmm1
movapd %xmm0,%xmm2
andpd  %xmm1,%xmm2
andpd  %xmm3,%xmm1
movapd 0xeeb(%rip),%xmm4
movapd %xmm1,%xmm5
cmplepd %xmm4,%xmm5
movapd %xmm2,%xmm6
cmplepd %xmm4,%xmm6
packssdw %xmm5,%xmm6
movmskps %xmm6,%eax
test   %eax,%eax
je     11d5 <gsw_add_mean+0xd5>
movapd %xmm2,%xmm5
cmpnlepd %xmm4,%xmm5
cmpnlepd %xmm4,%xmm1
packssdw %xmm1,%xmm5
movmskps %xmm5,%ecx
mov    %eax,%edx
shr    %dl
and    $0x5,%dl
sub    %dl,%al
mov    %eax,%edx
and    $0x33,%dl
shr    $0x2,%al
and    $0x33,%al
add    %dl,%al
xorpd  %xmm1,%xmm1
test   $0x1,%cl
jne    117d <gsw_add_mean+0x7d>
addsd  %xmm0,%xmm1
mov    %eax,%edx
shr    $0x4,%dl
movsd  0xe96(%rip),%xmm4
movapd %xmm4,%xmm5
test   $0x2,%cl
jne    119b <gsw_add_mean+0x9b>
movapd %xmm0,%xmm5
unpckhpd %xmm0,%xmm5
addsd  %xmm5,%xmm1
add    %dl,%al
movapd %xmm4,%xmm5
test   $0x4,%cl
jne    11ae <gsw_add_mean+0xae>
movapd %xmm3,%xmm5
addsd  %xmm5,%xmm1
and    $0xf,%al
test   $0x8,%cl
jne    11c1 <gsw_add_mean+0xc1>
unpckhpd %xmm3,%xmm3
movapd %xmm3,%xmm4
addsd  %xmm4,%xmm1
movzbl %al,%eax
xorps  %xmm3,%xmm3
cvtsi2sd %eax,%xmm3
divsd  %xmm3,%xmm1
jmp    11d9 <gsw_add_mean+0xd9>
xorpd  %xmm1,%xmm1
movsd  0xe47(%rip),%xmm3
movapd %xmm3,%xmm4
cmpnlesd %xmm2,%xmm4
andpd  %xmm4,%xmm0
andnpd %xmm1,%xmm4
orpd   %xmm0,%xmm4
movlpd %xmm4,(%rsi)
movsd  0x8(%rdi),%xmm0
movapd 0xdf9(%rip),%xmm2
movapd %xmm0,%xmm4
andpd  %xmm2,%xmm4
movapd %xmm3,%xmm5
cmpnlesd %xmm4,%xmm5
andpd  %xmm5,%xmm0
andnpd %xmm1,%xmm5
orpd   %xmm0,%xmm5
movlpd %xmm5,0x8(%rsi)
movsd  0x10(%rdi),%xmm0
movapd %xmm0,%xmm4
andpd  %xmm2,%xmm4
movapd %xmm3,%xmm5
cmpnlesd %xmm4,%xmm5
andpd  %xmm5,%xmm0
andnpd %xmm1,%xmm5
orpd   %xmm0,%xmm5
movlpd %xmm5,0x10(%rsi)
movsd  0x18(%rdi),%xmm0
andpd  %xmm0,%xmm2
cmpnlesd %xmm2,%xmm3
andpd  %xmm3,%xmm0
andnpd %xmm1,%xmm3
orpd   %xmm0,%xmm3
movlpd %xmm3,0x18(%rsi)
ret

LLVM IR (-O0):
define void @gsw_add_mean(double* %0, double %1, double %2, double* %3) {
%5 = alloca double*
%6 = alloca double
%7 = alloca double
%8 = alloca double*
%9 = alloca i32
%10 = alloca i32
%11 = alloca double
store double* %0, double** %5
store double %1, double* %6
store double %2, double* %7
store double* %3, double** %8
store i32 0, i32* %10
store double 0.000000e+00, double* %11
store i32 0, i32* %9
br label %12
12: ; preds = %34, %4
%13 = load i32, i32* %9
%14 = icmp slt i32 %13, 4
br i1 %14, label %15, label %37
15: ; preds = %12
%16 = load double*, double** %5
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds double, double* %16, i64 %18
%20 = load double, double* %19
%21 = call double @llvm.fabs.f64(double %20)
%22 = fcmp ole double %21, 1.000000e+02
br i1 %22, label %23, label %33
23: ; preds = %15
%24 = load i32, i32* %10
%25 = add nsw i32 %24, 1
store i32 %25, i32* %10
%26 = load double, double* %11
%27 = load double*, double** %5
%28 = load i32, i32* %9
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds double, double* %27, i64 %29
%31 = load double, double* %30
%32 = fadd double %26, %31
store double %32, double* %11
br label %33
33: ; preds = %23, %15
br label %34
34: ; preds = %33
%35 = load i32, i32* %9
%36 = add nsw i32 %35, 1
store i32 %36, i32* %9
br label %12
37: ; preds = %12
%38 = load i32, i32* %10
%39 = icmp eq i32 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %37
store double 0.000000e+00, double* %11
br label %46
41: ; preds = %37
%42 = load double, double* %11
%43 = load i32, i32* %10
%44 = sitofp i32 %43 to double
%45 = fdiv double %42, %44
store double %45, double* %11
br label %46
46: ; preds = %41, %40
store i32 0, i32* %9
br label %47
47: ; preds = %75, %46
%48 = load i32, i32* %9
%49 = icmp slt i32 %48, 4
br i1 %49, label %50, label %78
50: ; preds = %47
%51 = load double*, double** %5
%52 = load i32, i32* %9
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds double, double* %51, i64 %53
%55 = load double, double* %54
%56 = call double @llvm.fabs.f64(double %55)
%57 = fcmp oge double %56, 1.000000e+02
br i1 %57, label %58, label %64
58: ; preds = %50
%59 = load double, double* %11
%60 = load double*, double** %8
%61 = load i32, i32* %9
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds double, double* %60, i64 %62
store double %59, double* %63
br label %74
64: ; preds = %50
%65 = load double*, double** %5
%66 = load i32, i32* %9
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
%69 = load double, double* %68
%70 = load double*, double** %8
%71 = load i32, i32* %9
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
store double %69, double* %73
br label %74
74: ; preds = %64, %58
br label %75
75: ; preds = %74
%76 = load i32, i32* %9
%77 = add nsw i32 %76, 1
store i32 %77, i32* %9
br label %47
78: ; preds = %47
ret void
}

LLVM IR (-O2):
define void @gsw_add_mean(double* nocapture %0, double %1, double %2, double* nocapture writeonly %3) {
%5 = bitcast double* %0 to <4 x double>*
%6 = load <4 x double>, <4 x double>* %5
%7 = call <4 x double> @llvm.fabs.v4f64(<4 x double> %6)
%8 = fcmp ugt <4 x double> %7, <double 1.000000e+02, double 1.000000e+02, double 1.000000e+02, double 1.000000e+02>
%9 = xor <4 x i1> %8, <i1 true, i1 true, i1 true, i1 true>
%10 = bitcast <4 x i1> %9 to i4
%11 = icmp eq i4 %10, 0
br i1 %11, label %32, label %12
12: ; preds = %4
%13 = call i4 @llvm.ctpop.i4(i4 %10)
%14 = extractelement <4 x double> %6, i64 0
%15 = fadd double %14, 0.000000e+00
%16 = extractelement <4 x i1> %8, i64 0
%17 = select i1 %16, double 0.000000e+00, double %15
%18 = extractelement <4 x i1> %8, i64 1
%19 = extractelement <4 x double> %6, i64 1
%20 = select i1 %18, double -0.000000e+00, double %19
%21 = fadd double %17, %20
%22 = extractelement <4 x i1> %8, i64 2
%23 = extractelement <4 x double> %6, i64 2
%24 = select i1 %22, double -0.000000e+00, double %23
%25 = fadd double %21, %24
%26 = extractelement <4 x i1> %8, i64 3
%27 = extractelement <4 x double> %6, i64 3
%28 = select i1 %26, double -0.000000e+00, double %27
%29 = fadd double %25, %28
%30 = uitofp i4 %13 to double
%31 = fdiv double %29, %30
br label %32
32: ; preds = %4, %12
%33 = phi double [ %31, %12 ], [ 0.000000e+00, %4 ]
%34 = getelementptr inbounds double, double* %0, i64 3
%35 = getelementptr inbounds double, double* %0, i64 2
%36 = getelementptr inbounds double, double* %0, i64 1
%37 = extractelement <4 x double> %7, i64 0
%38 = fcmp ult double %37, 1.000000e+02
%39 = extractelement <4 x double> %6, i64 0
%40 = select i1 %38, double %39, double %33
store double %40, double* %3
%41 = load double, double* %36
%42 = tail call double @llvm.fabs.f64(double %41)
%43 = fcmp ult double %42, 1.000000e+02
%44 = select i1 %43, double %41, double %33
%45 = getelementptr inbounds double, double* %3, i64 1
store double %44, double* %45
%46 = load double, double* %35
%47 = tail call double @llvm.fabs.f64(double %46)
%48 = fcmp ult double %47, 1.000000e+02
%49 = select i1 %48, double %46, double %33
%50 = getelementptr inbounds double, double* %3, i64 2
store double %49, double* %50
%51 = load double, double* %34
%52 = tail call double @llvm.fabs.f64(double %51)
%53 = fcmp ult double %52, 1.000000e+02
%54 = select i1 %53, double %51, double %33
%55 = getelementptr inbounds double, double* %3, i64 3
store double %54, double* %55
ret void
}