#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 */
scalar_t__ fabsf(double);
void neumaier_cumsum_squared(float *array, int length, double *cumsum) {
  int i;
  double running_sum, square, temporary;
  double correction = 0.0;
  running_sum = (double)array[0] * (double)array[0];
  cumsum[0] = running_sum;
  for (i = 1; i < length; i++) {
    square = (double)array[i] * (double)array[i];
    temporary = running_sum + square;
    if (fabsf(running_sum) >= fabsf(square)) {
      correction += (running_sum - temporary) + square;
    } else {
      correction += (square - temporary) + running_sum;
    }
    running_sum = temporary;
    cumsum[i] = temporary + correction;
  }
}


x86 assembly (clang, -O0):
<neumaier_cumsum_squared>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1234 <neumaier_cumsum_squared+0x124>
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1030 <fabsf@plt>
mov    %rax,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1030 <fabsf@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
jl     11ec <neumaier_cumsum_squared+0xdc>
movsd  -0x28(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
jmp    1205 <neumaier_cumsum_squared+0xf5>
movsd  -0x30(%rbp),%xmm0
subsd  -0x38(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1160 <neumaier_cumsum_squared+0x50>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<neumaier_cumsum_squared>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
movss  (%rdi),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm0,%xmm0
movsd  %xmm0,(%rdx)
cmp    $0x2,%esi
jl     11e5 <neumaier_cumsum_squared+0xd5>
mov    %rdx,%r14
mov    %rdi,%r15
mov    %esi,%r12d
xorpd  %xmm1,%xmm1
mov    $0x1,%ebx
movapd %xmm0,%xmm2
jmp    118a <neumaier_cumsum_squared+0x7a>
xchg   %ax,%ax
movsd  0x18(%rsp),%xmm0
movsd  0x8(%rsp),%xmm2
subsd  %xmm2,%xmm0
addsd  (%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,(%r14,%rbx,8)
add    $0x1,%rbx
movapd %xmm2,%xmm0
cmp    %rbx,%r12
je     11e5 <neumaier_cumsum_squared+0xd5>
movsd  %xmm1,0x10(%rsp)
movss  (%r15,%rbx,4),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm1
movsd  %xmm1,(%rsp)
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
movsd  %xmm0,0x18(%rsp)
call   1030 <fabsf@plt>
mov    %rax,%r13
movsd  (%rsp),%xmm0
call   1030 <fabsf@plt>
cmp    %rax,%r13
jge    1150 <neumaier_cumsum_squared+0x40>
movsd  0x8(%rsp),%xmm2
movsd  (%rsp),%xmm1
subsd  %xmm2,%xmm1
movsd  0x18(%rsp),%xmm0
addsd  %xmm1,%xmm0
jmp    1165 <neumaier_cumsum_squared+0x55>
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @neumaier_cumsum_squared(float* nocapture %0, i32 %1, double* nocapture writeonly %2) {
%4 = load float, float* %0
%5 = fpext float %4 to double
%6 = fmul double %5, %5
store double %6, double* %2
%7 = icmp sgt i32 %1, 1
br i1 %7, label %8, label %32
8: ; preds = %3
%9 = zext i32 %1 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 1, %8 ], [ %30, %10 ]
%12 = phi double [ 0.000000e+00, %8 ], [ %27, %10 ]
%13 = phi double [ %6, %8 ], [ %18, %10 ]
%14 = getelementptr inbounds float, float* %0, i64 %11
%15 = load float, float* %14
%16 = fpext float %15 to double
%17 = fmul double %16, %16
%18 = fadd double %13, %17
%19 = tail call i64 @fabsf(double %13)
%20 = tail call i64 @fabsf(double %17)
%21 = icmp slt i64 %19, %20
%22 = fsub double %13, %18
%23 = fadd double %17, %22
%24 = fsub double %17, %18
%25 = fadd double %13, %24
%26 = select i1 %21, double %25, double %23
%27 = fadd double %12, %26
%28 = fadd double %18, %27
%29 = getelementptr inbounds double, double* %2, i64 %11
store double %28, double* %29
%30 = add nuw nsw i64 %11, 1
%31 = icmp eq i64 %30, %9
br i1 %31, label %32, label %10
32: ; preds = %10, %3
ret void
}