#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 */
typedef scalar_t__ int64_t;

/* Variables and functions */
scalar_t__ fabs(double);
scalar_t__ stdlib_base_is_nan(double const);
double stdlib_strided_dnannsumkbn2(const int64_t N, const double *X,
                                   const int64_t stride, int64_t *n) {
  double sum;
  double ccs;
  int64_t ix;
  int64_t i;
  double cs;
  double cc;
  double v;
  double t;
  double c;
  sum = 0.0;
  *n = 0;
  if (N <= 0) {
    return sum;
  }
  if (N == 1 || stride == 0) {
    if (stdlib_base_is_nan(X[0])) {
      return sum;
    }
    *n += 1;
    return X[0];
  }
  if (stride < 0) {
    ix = (1 - N) * stride;
  } else {
    ix = 0;
  }
  ccs = 0.0;
  cs = 0.0;
  for (i = 0; i < N; i++) {
    v = X[ix];
    if (!stdlib_base_is_nan(v)) {
      t = sum + v;
      if (fabs(sum) >= fabs(v)) {
        c = (sum - t) + v;
      } else {
        c = (v - t) + sum;
      }
      sum = t;
      t = cs + c;
      if (fabs(cs) >= fabs(c)) {
        cc = (cs - t) + c;
      } else {
        cc = (c - t) + cs;
      }
      cs = t;
      ccs += cc;
      *n += 1;
    }
    ix += stride;
  }
  return sum + cs + ccs;
}


x86 assembly (clang, -O0):
<stdlib_strided_dnannsumkbn2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x10(%rbp)
jg     1168 <stdlib_strided_dnannsumkbn2+0x48>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1364 <stdlib_strided_dnannsumkbn2+0x244>
cmpq   $0x1,-0x10(%rbp)
je     117e <stdlib_strided_dnannsumkbn2+0x5e>
cmpq   $0x0,-0x20(%rbp)
jne    11c4 <stdlib_strided_dnannsumkbn2+0xa4>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
call   1040 <stdlib_base_is_nan@plt>
cmp    $0x0,%rax
je     11a4 <stdlib_strided_dnannsumkbn2+0x84>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1364 <stdlib_strided_dnannsumkbn2+0x244>
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1364 <stdlib_strided_dnannsumkbn2+0x244>
cmpq   $0x0,-0x20(%rbp)
jge    11e6 <stdlib_strided_dnannsumkbn2+0xc6>
mov    $0x1,%eax
sub    -0x10(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
jmp    11ee <stdlib_strided_dnannsumkbn2+0xce>
movq   $0x0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1350 <stdlib_strided_dnannsumkbn2+0x230>
mov    -0x18(%rbp),%rax
mov    -0x40(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x60(%rbp),%xmm0
call   1040 <stdlib_base_is_nan@plt>
cmp    $0x0,%rax
jne    1333 <stdlib_strided_dnannsumkbn2+0x213>
movsd  -0x30(%rbp),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x78(%rbp)
movsd  -0x60(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
cmp    %rcx,%rax
jl     128a <stdlib_strided_dnannsumkbn2+0x16a>
movsd  -0x30(%rbp),%xmm0
subsd  -0x68(%rbp),%xmm0
addsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    129e <stdlib_strided_dnannsumkbn2+0x17e>
movsd  -0x60(%rbp),%xmm0
subsd  -0x68(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x50(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x80(%rbp)
movsd  -0x70(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x80(%rbp),%rax
cmp    %rcx,%rax
jl     12f8 <stdlib_strided_dnannsumkbn2+0x1d8>
movsd  -0x50(%rbp),%xmm0
subsd  -0x68(%rbp),%xmm0
addsd  -0x70(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
jmp    130c <stdlib_strided_dnannsumkbn2+0x1ec>
movsd  -0x70(%rbp),%xmm0
subsd  -0x68(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x58(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rax
add    -0x40(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    1206 <stdlib_strided_dnannsumkbn2+0xe6>
movsd  -0x30(%rbp),%xmm0
addsd  -0x50(%rbp),%xmm0
addsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdlib_strided_dnannsumkbn2>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x30,%rsp
movq   $0x0,(%rcx)
xorpd  %xmm0,%xmm0
test   %rdi,%rdi
jle    12e4 <stdlib_strided_dnannsumkbn2+0x1c4>
mov    %rcx,%r14
mov    %rsi,%r12
mov    %rdi,%r13
cmp    $0x1,%rdi
je     12ba <stdlib_strided_dnannsumkbn2+0x19a>
mov    %rdx,%r15
test   %rdx,%rdx
je     12ba <stdlib_strided_dnannsumkbn2+0x19a>
mov    $0x1,%eax
sub    %r13,%rax
imul   %r15,%rax
mov    %r15,%rcx
sar    $0x3f,%rcx
and    %rax,%rcx
lea    (%r12,%rcx,8),%rbx
shl    $0x3,%r15
xorpd  %xmm0,%xmm0
movsd  %xmm0,0x10(%rsp)
xorpd  %xmm0,%xmm0
xorpd  %xmm1,%xmm1
jmp    11b9 <stdlib_strided_dnannsumkbn2+0x99>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  0x28(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
add    %r15,%rbx
add    $0xffffffffffffffff,%r13
je     12da <stdlib_strided_dnannsumkbn2+0x1ba>
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,0x28(%rsp)
movsd  (%rbx),%xmm0
movsd  %xmm0,0x18(%rsp)
call   1040 <stdlib_base_is_nan@plt>
test   %rax,%rax
jne    11a0 <stdlib_strided_dnannsumkbn2+0x80>
movsd  0x8(%rsp),%xmm0
movapd %xmm0,%xmm1
addsd  0x18(%rsp),%xmm1
movsd  %xmm1,0x20(%rsp)
call   1030 <fabs@plt>
mov    %rax,%r12
movsd  0x18(%rsp),%xmm0
call   1030 <fabs@plt>
cmp    %rax,%r12
jl     121b <stdlib_strided_dnannsumkbn2+0xfb>
movsd  0x8(%rsp),%xmm1
subsd  0x20(%rsp),%xmm1
addsd  0x18(%rsp),%xmm1
jmp    1231 <stdlib_strided_dnannsumkbn2+0x111>
movsd  0x18(%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
movsd  %xmm1,0x8(%rsp)
movapd %xmm0,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x18(%rsp)
movsd  %xmm0,0x10(%rsp)
call   1030 <fabs@plt>
mov    %rax,%r12
movsd  0x8(%rsp),%xmm0
call   1030 <fabs@plt>
cmp    %rax,%r12
jl     1281 <stdlib_strided_dnannsumkbn2+0x161>
movsd  0x18(%rsp),%xmm2
movsd  0x10(%rsp),%xmm3
subsd  %xmm2,%xmm3
addsd  0x8(%rsp),%xmm3
jmp    129b <stdlib_strided_dnannsumkbn2+0x17b>
movsd  0x18(%rsp),%xmm2
movsd  0x8(%rsp),%xmm0
subsd  %xmm2,%xmm0
movsd  0x10(%rsp),%xmm3
addsd  %xmm0,%xmm3
movsd  0x28(%rsp),%xmm0
movsd  0x20(%rsp),%xmm1
addsd  %xmm3,%xmm0
addq   $0x1,(%r14)
movsd  %xmm2,0x10(%rsp)
jmp    11ac <stdlib_strided_dnannsumkbn2+0x8c>
movsd  (%r12),%xmm0
call   1040 <stdlib_base_is_nan@plt>
xorpd  %xmm0,%xmm0
test   %rax,%rax
jne    12e4 <stdlib_strided_dnannsumkbn2+0x1c4>
addq   $0x1,(%r14)
movsd  (%r12),%xmm0
jmp    12e4 <stdlib_strided_dnannsumkbn2+0x1c4>
addsd  0x10(%rsp),%xmm1
addsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define double @stdlib_strided_dnannsumkbn2(i64 %0, double* %1, i64 %2, i64* %3) {
%5 = alloca double
%6 = alloca i64
%7 = alloca double*
%8 = alloca i64
%9 = alloca i64*
%10 = alloca double
%11 = alloca double
%12 = alloca i64
%13 = alloca i64
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
store i64 %0, i64* %6
store double* %1, double** %7
store i64 %2, i64* %8
store i64* %3, i64** %9
store double 0.000000e+00, double* %10
%19 = load i64*, i64** %9
store i64 0, i64* %19
%20 = load i64, i64* %6
%21 = icmp sle i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %4
%23 = load double, double* %10
store double %23, double* %5
br label %131
24: ; preds = %4
%25 = load i64, i64* %6
%26 = icmp eq i64 %25, 1
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = load i64, i64* %8
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %45
30: ; preds = %27, %24
%31 = load double*, double** %7
%32 = getelementptr inbounds double, double* %31, i64 0
%33 = load double, double* %32
%34 = call i64 @stdlib_base_is_nan(double %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %38
36: ; preds = %30
%37 = load double, double* %10
store double %37, double* %5
br label %131
38: ; preds = %30
%39 = load i64*, i64** %9
%40 = load i64, i64* %39
%41 = add nsw i64 %40, 1
store i64 %41, i64* %39
%42 = load double*, double** %7
%43 = getelementptr inbounds double, double* %42, i64 0
%44 = load double, double* %43
store double %44, double* %5
br label %131
45: ; preds = %27
%46 = load i64, i64* %8
%47 = icmp slt i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %45
%49 = load i64, i64* %6
%50 = sub nsw i64 1, %49
%51 = load i64, i64* %8
%52 = mul nsw i64 %50, %51
store i64 %52, i64* %12
br label %54
53: ; preds = %45
store i64 0, i64* %12
br label %54
54: ; preds = %53, %48
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %14
store i64 0, i64* %13
br label %55
55: ; preds = %122, %54
%56 = load i64, i64* %13
%57 = load i64, i64* %6
%58 = icmp slt i64 %56, %57
br i1 %58, label %59, label %125
59: ; preds = %55
%60 = load double*, double** %7
%61 = load i64, i64* %12
%62 = getelementptr inbounds double, double* %60, i64 %61
%63 = load double, double* %62
store double %63, double* %16
%64 = load double, double* %16
%65 = call i64 @stdlib_base_is_nan(double %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %118, label %67
67: ; preds = %59
%68 = load double, double* %10
%69 = load double, double* %16
%70 = fadd double %68, %69
store double %70, double* %17
%71 = load double, double* %10
%72 = call i64 @fabs(double %71)
%73 = load double, double* %16
%74 = call i64 @fabs(double %73)
%75 = icmp sge i64 %72, %74
br i1 %75, label %76, label %82
76: ; preds = %67
%77 = load double, double* %10
%78 = load double, double* %17
%79 = fsub double %77, %78
%80 = load double, double* %16
%81 = fadd double %79, %80
store double %81, double* %18
br label %88
82: ; preds = %67
%83 = load double, double* %16
%84 = load double, double* %17
%85 = fsub double %83, %84
%86 = load double, double* %10
%87 = fadd double %85, %86
store double %87, double* %18
br label %88
88: ; preds = %82, %76
%89 = load double, double* %17
store double %89, double* %10
%90 = load double, double* %14
%91 = load double, double* %18
%92 = fadd double %90, %91
store double %92, double* %17
%93 = load double, double* %14
%94 = call i64 @fabs(double %93)
%95 = load double, double* %18
%96 = call i64 @fabs(double %95)
%97 = icmp sge i64 %94, %96
br i1 %97, label %98, label %104
98: ; preds = %88
%99 = load double, double* %14
%100 = load double, double* %17
%101 = fsub double %99, %100
%102 = load double, double* %18
%103 = fadd double %101, %102
store double %103, double* %15
br label %110
104: ; preds = %88
%105 = load double, double* %18
%106 = load double, double* %17
%107 = fsub double %105, %106
%108 = load double, double* %14
%109 = fadd double %107, %108
store double %109, double* %15
br label %110
110: ; preds = %104, %98
%111 = load double, double* %17
store double %111, double* %14
%112 = load double, double* %15
%113 = load double, double* %11
%114 = fadd double %113, %112
store double %114, double* %11
%115 = load i64*, i64** %9
%116 = load i64, i64* %115
%117 = add nsw i64 %116, 1
store i64 %117, i64* %115
br label %118
118: ; preds = %110, %59
%119 = load i64, i64* %8
%120 = load i64, i64* %12
%121 = add nsw i64 %120, %119
store i64 %121, i64* %12
br label %122
122: ; preds = %118
%123 = load i64, i64* %13
%124 = add nsw i64 %123, 1
store i64 %124, i64* %13
br label %55
125: ; preds = %55
%126 = load double, double* %10
%127 = load double, double* %14
%128 = fadd double %126, %127
%129 = load double, double* %11
%130 = fadd double %128, %129
store double %130, double* %5
br label %131
131: ; preds = %125, %38, %36, %22
%132 = load double, double* %5
ret double %132
}

LLVM IR (-O2):
define double @stdlib_strided_dnannsumkbn2(i64 %0, double* nocapture %1, i64 %2, i64* nocapture %3) {
store i64 0, i64* %3
%5 = icmp slt i64 %0, 1
br i1 %5, label %65, label %6
6: ; preds = %4
%7 = icmp eq i64 %0, 1
%8 = icmp eq i64 %2, 0
%9 = or i1 %7, %8
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = load double, double* %1
%12 = tail call i64 @stdlib_base_is_nan(double %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %65
14: ; preds = %10
%15 = load i64, i64* %3
%16 = add nsw i64 %15, 1
store i64 %16, i64* %3
%17 = load double, double* %1
br label %65
18: ; preds = %6
%19 = icmp slt i64 %2, 0
%20 = sub nsw i64 1, %0
%21 = mul nsw i64 %20, %2
%22 = select i1 %19, i64 %21, i64 0
br label %23
23: ; preds = %18, %55
%24 = phi double [ %58, %55 ], [ 0.000000e+00, %18 ]
%25 = phi i64 [ %60, %55 ], [ 0, %18 ]
%26 = phi i64 [ %59, %55 ], [ %22, %18 ]
%27 = phi double [ %57, %55 ], [ 0.000000e+00, %18 ]
%28 = phi double [ %56, %55 ], [ 0.000000e+00, %18 ]
%29 = getelementptr inbounds double, double* %1, i64 %26
%30 = load double, double* %29
%31 = tail call i64 @stdlib_base_is_nan(double %30)
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %55
33: ; preds = %23
%34 = fadd double %28, %30
%35 = tail call i64 @fabs(double %28)
%36 = tail call i64 @fabs(double %30)
%37 = icmp slt i64 %35, %36
%38 = fsub double %28, %34
%39 = fadd double %30, %38
%40 = fsub double %30, %34
%41 = fadd double %28, %40
%42 = select i1 %37, double %41, double %39
%43 = fadd double %24, %42
%44 = tail call i64 @fabs(double %24)
%45 = tail call i64 @fabs(double %42)
%46 = icmp slt i64 %44, %45
%47 = fsub double %24, %43
%48 = fadd double %42, %47
%49 = fsub double %42, %43
%50 = fadd double %24, %49
%51 = select i1 %46, double %50, double %48
%52 = fadd double %27, %51
%53 = load i64, i64* %3
%54 = add nsw i64 %53, 1
store i64 %54, i64* %3
br label %55
55: ; preds = %33, %23
%56 = phi double [ %28, %23 ], [ %34, %33 ]
%57 = phi double [ %27, %23 ], [ %52, %33 ]
%58 = phi double [ %24, %23 ], [ %43, %33 ]
%59 = add nsw i64 %26, %2
%60 = add nuw nsw i64 %25, 1
%61 = icmp eq i64 %60, %0
br i1 %61, label %62, label %23
62: ; preds = %55
%63 = fadd double %56, %58
%64 = fadd double %57, %63
br label %65
65: ; preds = %10, %4, %62, %14
%66 = phi double [ %17, %14 ], [ %64, %62 ], [ 0.000000e+00, %4 ], [ 0.000000e+00, %10 ]
ret double %66
}