#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);
double stdlib_strided_dsumkbn2(const int64_t N, const double *X,
                               const int64_t stride) {
  double sum;
  double ccs;
  int64_t ix;
  int64_t i;
  double cs;
  double cc;
  double v;
  double t;
  double c;
  if (N <= 0) {
    return 0.0;
  }
  if (N == 1 || stride == 0) {
    return X[0];
  }
  if (stride < 0) {
    ix = (1 - N) * stride;
  } else {
    ix = 0;
  }
  sum = 0.0;
  ccs = 0.0;
  cs = 0.0;
  for (i = 0; i < N; i++) {
    v = X[ix];
    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;
    ix += stride;
  }
  return sum + cs + ccs;
}


x86 assembly (clang, -O0):
<stdlib_strided_dsumkbn2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
jg     113f <stdlib_strided_dsumkbn2+0x2f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ed <stdlib_strided_dsumkbn2+0x1dd>
cmpq   $0x1,-0x10(%rbp)
je     1155 <stdlib_strided_dsumkbn2+0x45>
cmpq   $0x0,-0x20(%rbp)
jne    1167 <stdlib_strided_dsumkbn2+0x57>
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12ed <stdlib_strided_dsumkbn2+0x1dd>
cmpq   $0x0,-0x20(%rbp)
jge    1189 <stdlib_strided_dsumkbn2+0x79>
mov    $0x1,%eax
sub    -0x10(%rbp),%rax
imul   -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
jmp    1191 <stdlib_strided_dsumkbn2+0x81>
movq   $0x0,-0x38(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
movq   $0x0,-0x40(%rbp)
mov    -0x40(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    12d9 <stdlib_strided_dsumkbn2+0x1c9>
mov    -0x18(%rbp),%rax
mov    -0x38(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x70(%rbp)
movsd  -0x58(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x70(%rbp),%rax
cmp    %rcx,%rax
jl     1221 <stdlib_strided_dsumkbn2+0x111>
movsd  -0x28(%rbp),%xmm0
subsd  -0x60(%rbp),%xmm0
addsd  -0x58(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    1235 <stdlib_strided_dsumkbn2+0x125>
movsd  -0x58(%rbp),%xmm0
subsd  -0x60(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x48(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x48(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,-0x78(%rbp)
movsd  -0x68(%rbp),%xmm0
call   1030 <fabs@plt>
mov    %rax,%rcx
mov    -0x78(%rbp),%rax
cmp    %rcx,%rax
jl     128f <stdlib_strided_dsumkbn2+0x17f>
movsd  -0x48(%rbp),%xmm0
subsd  -0x60(%rbp),%xmm0
addsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
jmp    12a3 <stdlib_strided_dsumkbn2+0x193>
movsd  -0x68(%rbp),%xmm0
subsd  -0x60(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x60(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x50(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x40(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x40(%rbp)
jmp    11b1 <stdlib_strided_dsumkbn2+0xa1>
movsd  -0x28(%rbp),%xmm0
addsd  -0x48(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdlib_strided_dsumkbn2>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
jle    1268 <stdlib_strided_dsumkbn2+0x158>
mov    %rdi,%r15
cmp    $0x1,%rdi
je     126e <stdlib_strided_dsumkbn2+0x15e>
mov    %rdx,%r14
test   %rdx,%rdx
je     126e <stdlib_strided_dsumkbn2+0x15e>
mov    $0x1,%eax
sub    %r15,%rax
imul   %r14,%rax
mov    %r14,%rcx
sar    $0x3f,%rcx
and    %rax,%rcx
lea    (%rsi,%rcx,8),%r12
shl    $0x3,%r14
xorpd  %xmm2,%xmm2
xorpd  %xmm0,%xmm0
xorpd  %xmm3,%xmm3
xorpd  %xmm1,%xmm1
jmp    11aa <stdlib_strided_dsumkbn2+0x9a>
nopl   (%rax)
movsd  (%rsp),%xmm4
movsd  0x10(%rsp),%xmm2
subsd  %xmm4,%xmm2
addsd  0x8(%rsp),%xmm2
movsd  0x20(%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
addsd  %xmm2,%xmm0
add    %r14,%r12
movapd %xmm4,%xmm2
movapd %xmm1,%xmm3
add    $0xffffffffffffffff,%r15
je     1274 <stdlib_strided_dsumkbn2+0x164>
movsd  %xmm2,0x10(%rsp)
movsd  %xmm0,0x20(%rsp)
movsd  (%r12),%xmm0
movsd  %xmm0,(%rsp)
addsd  %xmm0,%xmm1
movsd  %xmm1,0x18(%rsp)
movsd  %xmm3,0x8(%rsp)
movapd %xmm3,%xmm0
call   1030 <fabs@plt>
mov    %rax,%rbx
movsd  (%rsp),%xmm0
call   1030 <fabs@plt>
cmp    %rax,%rbx
jl     1200 <stdlib_strided_dsumkbn2+0xf0>
movsd  0x8(%rsp),%xmm1
subsd  0x18(%rsp),%xmm1
addsd  (%rsp),%xmm1
jmp    1215 <stdlib_strided_dsumkbn2+0x105>
nop
movsd  (%rsp),%xmm0
subsd  0x18(%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,(%rsp)
call   1030 <fabs@plt>
mov    %rax,%rbx
movsd  0x8(%rsp),%xmm0
call   1030 <fabs@plt>
cmp    %rax,%rbx
jge    1170 <stdlib_strided_dsumkbn2+0x60>
movsd  0x8(%rsp),%xmm0
movsd  (%rsp),%xmm4
subsd  %xmm4,%xmm0
movsd  0x10(%rsp),%xmm2
addsd  %xmm0,%xmm2
jmp    1185 <stdlib_strided_dsumkbn2+0x75>
xorpd  %xmm0,%xmm0
jmp    127c <stdlib_strided_dsumkbn2+0x16c>
movsd  (%rsi),%xmm0
jmp    127c <stdlib_strided_dsumkbn2+0x16c>
addsd  %xmm4,%xmm1
addsd  %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

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