#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 sqrt(double);
double getrms(int N, double *t, double *mag, double *sig, double *aveval,
              double *rmsthy, int *ngood) {
  double avesum1, avesum2, avesum3, ave, rmsval, n;
  int i;
  *aveval = -1.;
  if (N > 0) {
    avesum1 = 0.;
    avesum2 = 0.;
    avesum3 = 0.;
    n = 0;
    for (i = 0; i < N; i++) {
      if (!isnan(mag[i]) && sig[i] > 0.) {
        avesum1 += mag[i];
        avesum2 += mag[i] * mag[i];
        avesum3 += sig[i] * sig[i];
        n++;
      }
    }
    if (n > 0.) {
      ave = (avesum1 / (double)n);
      *aveval = ave;
      *ngood = n;
      *rmsthy = sqrt(avesum3 / (double)n);
      rmsval = sqrt((avesum2 / (double)n) - (ave * ave));
    } else {
      *ngood = 0;
      *rmsthy = -1.;
      rmsval = -1.;
    }
  } else {
    *ngood = 0;
    *rmsthy = -1.;
    rmsval = -1.;
  }
  return (rmsval);
}


x86 assembly (clang, -O0):
<getrms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movsd  0xeb1(%rip),%xmm0
movsd  %xmm0,(%rax)
cmpl   $0x0,-0x4(%rbp)
jle    1317 <getrms+0x1f7>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x60(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    1259 <getrms+0x139>
mov    -0x18(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%eax
jne    1246 <getrms+0x126>
mov    -0x20(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1246 <getrms+0x126>
mov    -0x18(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mov    -0x20(%rbp),%rax
movslq -0x64(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xdcc(%rip),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
jmp    124b <getrms+0x12b>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1184 <getrms+0x64>
movsd  -0x60(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    12eb <getrms+0x1cb>
movsd  -0x38(%rbp),%xmm0
divsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
mov    -0x28(%rbp),%rax
movsd  %xmm0,(%rax)
cvttsd2si -0x60(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
movsd  -0x48(%rbp),%xmm0
divsd  -0x60(%rbp),%xmm0
call   1040 <sqrt@plt>
mov    -0x30(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x40(%rbp),%xmm1
divsd  -0x60(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1040 <sqrt@plt>
movsd  %xmm0,-0x58(%rbp)
jmp    1312 <getrms+0x1f2>
mov    0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movsd  0xcff(%rip),%xmm0
movsd  %xmm0,(%rax)
movsd  0xcf3(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    133e <getrms+0x21e>
mov    0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x30(%rbp),%rax
movsd  0xcd3(%rip),%xmm0
movsd  %xmm0,(%rax)
movsd  0xcc7(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x58(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getrms>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    0x70(%rsp),%r13
movabs $0xbff0000000000000,%rax
mov    %rax,(%r8)
test   %edi,%edi
jle    123c <getrms+0x11c>
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%rbx
mov    %r9,0x18(%rsp)
mov    %edi,%ebp
xorpd  %xmm0,%xmm0
movapd %xmm0,0x20(%rsp)
xor    %r14d,%r14d
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x8(%rsp)
jmp    1189 <getrms+0x69>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r14
cmp    %r14,%rbp
je     11ec <getrms+0xcc>
movsd  (%rbx,%r14,8),%xmm0
call   1030 <isnan@plt>
test   %eax,%eax
jne    1180 <getrms+0x60>
movsd  (%r12,%r14,8),%xmm0
ucomisd 0xe6a(%rip),%xmm0
jbe    1180 <getrms+0x60>
movsd  (%rbx,%r14,8),%xmm1
movsd  0x8(%rsp),%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
unpcklpd %xmm0,%xmm1
mulpd  %xmm1,%xmm1
movapd 0x20(%rsp),%xmm0
addpd  %xmm1,%xmm0
movapd %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
addsd  0xe24(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
jmp    1180 <getrms+0x60>
xorpd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1249 <getrms+0x129>
movapd %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
divsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  %xmm0,(%r15)
cvttsd2si %xmm2,%eax
mov    %eax,0x0(%r13)
movapd 0x20(%rsp),%xmm0
unpckhpd %xmm0,%xmm0
divsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
mov    0x18(%rsp),%rbx
jb     127a <getrms+0x15a>
sqrtsd %xmm0,%xmm0
jmp    127f <getrms+0x15f>
movl   $0x0,0x0(%r13)
mov    %rax,(%r9)
jmp    1263 <getrms+0x143>
movl   $0x0,0x0(%r13)
mov    0x18(%rsp),%rax
movabs $0xbff0000000000000,%rcx
mov    %rcx,(%rax)
movsd  0xd95(%rip),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
call   1040 <sqrt@plt>
movsd  %xmm0,(%rbx)
movapd 0x20(%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     12ad <getrms+0x18d>
sqrtsd %xmm0,%xmm0
jmp    126b <getrms+0x14b>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <sqrt@plt>

LLVM IR (-O0):
define double @getrms(i32 %0, double* %1, double* %2, double* %3, double* %4, double* %5, i32* %6) {
%8 = alloca i32
%9 = alloca double*
%10 = alloca double*
%11 = alloca double*
%12 = alloca double*
%13 = alloca double*
%14 = alloca i32*
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
%21 = alloca i32
store i32 %0, i32* %8
store double* %1, double** %9
store double* %2, double** %10
store double* %3, double** %11
store double* %4, double** %12
store double* %5, double** %13
store i32* %6, i32** %14
%22 = load double*, double** %12
store double -1.000000e+00, double* %22
%23 = load i32, i32* %8
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %112
25: ; preds = %7
store double 0.000000e+00, double* %15
store double 0.000000e+00, double* %16
store double 0.000000e+00, double* %17
store double 0.000000e+00, double* %20
store i32 0, i32* %21
br label %26
26: ; preds = %80, %25
%27 = load i32, i32* %21
%28 = load i32, i32* %8
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %83
30: ; preds = %26
%31 = load double*, double** %10
%32 = load i32, i32* %21
%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 %79, label %38
38: ; preds = %30
%39 = load double*, double** %11
%40 = load i32, i32* %21
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds double, double* %39, i64 %41
%43 = load double, double* %42
%44 = fcmp ogt double %43, 0.000000e+00
br i1 %44, label %45, label %79
45: ; preds = %38
%46 = load double*, double** %10
%47 = load i32, i32* %21
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds double, double* %46, i64 %48
%50 = load double, double* %49
%51 = load double, double* %15
%52 = fadd double %51, %50
store double %52, double* %15
%53 = load double*, double** %10
%54 = load i32, i32* %21
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds double, double* %53, i64 %55
%57 = load double, double* %56
%58 = load double*, double** %10
%59 = load i32, i32* %21
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds double, double* %58, i64 %60
%62 = load double, double* %61
%63 = load double, double* %16
%64 = call double @llvm.fmuladd.f64(double %57, double %62, double %63)
store double %64, double* %16
%65 = load double*, double** %11
%66 = load i32, i32* %21
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds double, double* %65, i64 %67
%69 = load double, double* %68
%70 = load double*, double** %11
%71 = load i32, i32* %21
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds double, double* %70, i64 %72
%74 = load double, double* %73
%75 = load double, double* %17
%76 = call double @llvm.fmuladd.f64(double %69, double %74, double %75)
store double %76, double* %17
%77 = load double, double* %20
%78 = fadd double %77, 1.000000e+00
store double %78, double* %20
br label %79
79: ; preds = %45, %38, %30
br label %80
80: ; preds = %79
%81 = load i32, i32* %21
%82 = add nsw i32 %81, 1
store i32 %82, i32* %21
br label %26
83: ; preds = %26
%84 = load double, double* %20
%85 = fcmp ogt double %84, 0.000000e+00
br i1 %85, label %86, label %108
86: ; preds = %83
%87 = load double, double* %15
%88 = load double, double* %20
%89 = fdiv double %87, %88
store double %89, double* %18
%90 = load double, double* %18
%91 = load double*, double** %12
store double %90, double* %91
%92 = load double, double* %20
%93 = fptosi double %92 to i32
%94 = load i32*, i32** %14
store i32 %93, i32* %94
%95 = load double, double* %17
%96 = load double, double* %20
%97 = fdiv double %95, %96
%98 = call double @sqrt(double %97)
%99 = load double*, double** %13
store double %98, double* %99
%100 = load double, double* %16
%101 = load double, double* %20
%102 = fdiv double %100, %101
%103 = load double, double* %18
%104 = load double, double* %18
%105 = fneg double %103
%106 = call double @llvm.fmuladd.f64(double %105, double %104, double %102)
%107 = call double @sqrt(double %106)
store double %107, double* %19
br label %111
108: ; preds = %83
%109 = load i32*, i32** %14
store i32 0, i32* %109
%110 = load double*, double** %13
store double -1.000000e+00, double* %110
store double -1.000000e+00, double* %19
br label %111
111: ; preds = %108, %86
br label %115
112: ; preds = %7
%113 = load i32*, i32** %14
store i32 0, i32* %113
%114 = load double*, double** %13
store double -1.000000e+00, double* %114
store double -1.000000e+00, double* %19
br label %115
115: ; preds = %112, %111
%116 = load double, double* %19
ret double %116
}

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