double difference(double n) {
  register double soq = 0;
  register double i;
  for (i = 1; i <= n; i++)
    soq += (i) * (i);
  return ((n * (n + 1.0) / 2.0)) * ((n * (n + 1.0) / 2.0)) - soq;
}


x86 assembly (clang, -O0):
<difference>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xee7(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1165 <difference+0x65>
movsd  -0x18(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm2
movsd  -0x10(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xeaa(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    111e <difference+0x1e>
movsd  -0x8(%rbp),%xmm0
movsd  0xe8e(%rip),%xmm1
addsd  -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe85(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  -0x8(%rbp),%xmm2
movsd  0xe6c(%rip),%xmm1
addsd  -0x8(%rbp),%xmm1
mulsd  %xmm1,%xmm2
movsd  0xe63(%rip),%xmm1
divsd  %xmm1,%xmm2
movsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<difference>:
xorpd  %xmm2,%xmm2
ucomisd 0xef4(%rip),%xmm0
jb     1136 <difference+0x36>
xorpd  %xmm2,%xmm2
movsd  0xee6(%rip),%xmm1
movapd %xmm1,%xmm3
xchg   %ax,%ax
movapd %xmm3,%xmm4
mulsd  %xmm3,%xmm4
addsd  %xmm4,%xmm2
addsd  %xmm1,%xmm3
ucomisd %xmm3,%xmm0
jae    1120 <difference+0x20>
movsd  0xec2(%rip),%xmm1
addsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
mulsd  0xeba(%rip),%xmm1
mulsd  %xmm1,%xmm1
subsd  %xmm2,%xmm1
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
define double @difference(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %2
store double 0.000000e+00, double* %3
store double 1.000000e+00, double* %4
br label %5
5: ; preds = %14, %1
%6 = load double, double* %4
%7 = load double, double* %2
%8 = fcmp ole double %6, %7
br i1 %8, label %9, label %17
9: ; preds = %5
%10 = load double, double* %4
%11 = load double, double* %4
%12 = load double, double* %3
%13 = call double @llvm.fmuladd.f64(double %10, double %11, double %12)
store double %13, double* %3
br label %14
14: ; preds = %9
%15 = load double, double* %4
%16 = fadd double %15, 1.000000e+00
store double %16, double* %4
br label %5
17: ; preds = %5
%18 = load double, double* %2
%19 = load double, double* %2
%20 = fadd double %19, 1.000000e+00
%21 = fmul double %18, %20
%22 = fdiv double %21, 2.000000e+00
%23 = load double, double* %2
%24 = load double, double* %2
%25 = fadd double %24, 1.000000e+00
%26 = fmul double %23, %25
%27 = fdiv double %26, 2.000000e+00
%28 = load double, double* %3
%29 = fneg double %28
%30 = call double @llvm.fmuladd.f64(double %22, double %27, double %29)
ret double %30
}

LLVM IR (-O2):
define double @difference(double %0) {
%2 = fcmp ult double %0, 1.000000e+00
br i1 %2, label %9, label %3
3: ; preds = %1, %3
%4 = phi double [ %7, %3 ], [ 1.000000e+00, %1 ]
%5 = phi double [ %6, %3 ], [ 0.000000e+00, %1 ]
%6 = tail call double @llvm.fmuladd.f64(double %4, double %4, double %5)
%7 = fadd double %4, 1.000000e+00
%8 = fcmp ugt double %7, %0
br i1 %8, label %9, label %3
9: ; preds = %3, %1
%10 = phi double [ 0.000000e+00, %1 ], [ %6, %3 ]
%11 = fadd double %0, 1.000000e+00
%12 = fmul double %11, %0
%13 = fmul double %12, 5.000000e-01
%14 = fneg double %10
%15 = tail call double @llvm.fmuladd.f64(double %13, double %13, double %14)
ret double %15
}