__float128 compute_variance(const int N, const __float128 mean,
                            const __float128 data[]) {
  assert(N >= 2);
  int i;
  int n = 0;
  __float128 m = mean, M2 = 0.0;
  for (i = 0; i < N; i++) {
    n++;
    __float128 delta = data[i] - m;
    m += delta / (__float128)n;
    M2 += delta * (data[i] - m);
  }
  return M2 / (__float128)(n - 1);
}


x86 assembly (clang, -O0):
<compute_variance>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
xor    %eax,%eax
mov    %edi,-0x4(%rbp)
movaps %xmm0,-0x20(%rbp)
mov    %rsi,-0x28(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x2,%eax
setge  %al
movzbl %al,%edi
xor    %eax,%eax
call   1030 <assert@plt>
movl   $0x0,-0x30(%rbp)
movaps -0x20(%rbp),%xmm0
movaps %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movaps %xmm0,-0x50(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    120c <compute_variance+0xfc>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
shl    $0x4,%rcx
movaps (%rax,%rcx,1),%xmm0
movaps -0x40(%rbp),%xmm1
call   3c40 <__subtf3>
movaps %xmm0,-0x60(%rbp)
movaps -0x60(%rbp),%xmm0
movaps %xmm0,-0x90(%rbp)
mov    -0x30(%rbp),%edi
call   4f80 <__floatsitf>
movaps %xmm0,%xmm1
movaps -0x90(%rbp),%xmm0
call   2620 <__divtf3>
movaps %xmm0,%xmm1
movaps -0x40(%rbp),%xmm0
call   1240 <__addtf3>
movaps %xmm0,-0x40(%rbp)
movaps -0x60(%rbp),%xmm0
movaps %xmm0,-0x80(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
shl    $0x4,%rcx
movaps (%rax,%rcx,1),%xmm0
movaps -0x40(%rbp),%xmm1
call   3c40 <__subtf3>
movaps %xmm0,%xmm1
movaps -0x80(%rbp),%xmm0
movaps -0x50(%rbp),%xmm2
movaps %xmm2,-0x70(%rbp)
call   3170 <__multf3>
movaps -0x70(%rbp),%xmm1
call   1240 <__addtf3>
movaps %xmm0,-0x50(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1158 <compute_variance+0x48>
movaps -0x50(%rbp),%xmm0
movaps %xmm0,-0xa0(%rbp)
mov    -0x30(%rbp),%edi
add    $0xffffffff,%edi
call   4f80 <__floatsitf>
movaps %xmm0,%xmm1
movaps -0xa0(%rbp),%xmm0
call   2620 <__divtf3>
add    $0xa0,%rsp
pop    %rbp
ret
nopw   0x0(%rax,%rax,1)

x86 assembly (clang, -O2):
<compute_variance>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rbx
movaps %xmm0,(%rsp)
mov    %edi,%r15d
xor    %edi,%edi
cmp    $0x2,%r15d
setge  %dil
xor    %eax,%eax
call   1030 <assert@plt>
test   %r15d,%r15d
jle    115a <compute_variance+0x4a>
mov    %r15d,%r12d
cmp    $0x1,%r15d
movaps (%rsp),%xmm1
mov    %rbx,0x48(%rsp)
jne    1166 <compute_variance+0x56>
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
jmp    1266 <compute_variance+0x156>
movaps 0x4e9f(%rip),%xmm0
jmp    12f6 <compute_variance+0x1e6>
mov    %r12d,%r13d
and    $0xfffffffe,%r13d
lea    0x10(%rbx),%r14
xorps  %xmm0,%xmm0
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
movaps %xmm0,0x10(%rsp)
lea    0x1(%rbx),%ebp
movaps -0x10(%r14),%xmm0
movaps %xmm0,0x50(%rsp)
movaps (%r14),%xmm2
movaps %xmm2,0x30(%rsp)
movaps %xmm1,(%rsp)
call   3d10 <__subtf3>
movaps %xmm0,0x20(%rsp)
mov    %ebp,%edi
call   5050 <__floatsitf>
movaps %xmm0,%xmm1
movaps 0x20(%rsp),%xmm0
call   26f0 <__divtf3>
movaps %xmm0,%xmm1
movaps (%rsp),%xmm0
call   1310 <__addtf3>
movaps %xmm0,%xmm1
movaps %xmm0,(%rsp)
movaps 0x50(%rsp),%xmm0
call   3d10 <__subtf3>
movaps %xmm0,%xmm1
movaps 0x20(%rsp),%xmm0
call   3240 <__multf3>
movaps 0x10(%rsp),%xmm1
call   1310 <__addtf3>
movaps %xmm0,0x10(%rsp)
add    $0x2,%rbx
movaps 0x30(%rsp),%xmm0
movaps (%rsp),%xmm1
call   3d10 <__subtf3>
movaps %xmm0,0x20(%rsp)
mov    %ebx,%edi
call   5050 <__floatsitf>
movaps %xmm0,%xmm1
movaps 0x20(%rsp),%xmm0
call   26f0 <__divtf3>
movaps %xmm0,%xmm1
movaps (%rsp),%xmm0
call   1310 <__addtf3>
movaps %xmm0,%xmm1
movaps %xmm0,(%rsp)
movaps 0x30(%rsp),%xmm0
call   3d10 <__subtf3>
movaps %xmm0,%xmm1
movaps 0x20(%rsp),%xmm0
call   3240 <__multf3>
movaps 0x10(%rsp),%xmm1
call   1310 <__addtf3>
movaps (%rsp),%xmm1
add    $0x20,%r14
cmp    %rbx,%r13
jne    1180 <compute_variance+0x70>
movaps %xmm0,0x10(%rsp)
test   $0x1,%r12b
je     12dd <compute_variance+0x1cd>
lea    0x1(%rbx),%ebp
shl    $0x4,%rbx
mov    0x48(%rsp),%rax
movaps (%rax,%rbx,1),%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm1,(%rsp)
call   3d10 <__subtf3>
movaps %xmm0,0x30(%rsp)
mov    %ebp,%edi
call   5050 <__floatsitf>
movaps %xmm0,%xmm1
movaps 0x30(%rsp),%xmm0
call   26f0 <__divtf3>
movaps %xmm0,%xmm1
movaps (%rsp),%xmm0
call   1310 <__addtf3>
movaps %xmm0,%xmm1
movaps 0x20(%rsp),%xmm0
call   3d10 <__subtf3>
movaps %xmm0,%xmm1
movaps 0x30(%rsp),%xmm0
call   3240 <__multf3>
movaps 0x10(%rsp),%xmm1
call   1310 <__addtf3>
movaps %xmm0,0x10(%rsp)
add    $0xffffffff,%r15d
mov    %r15d,%edi
call   5050 <__floatsitf>
movaps %xmm0,%xmm1
movaps 0x10(%rsp),%xmm0
call   26f0 <__divtf3>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
cs nopw 0x0(%rax,%rax,1)
nop

LLVM IR (-O0):
define fp128 @compute_variance(i32 %0, fp128 %1, fp128* %2) {
%4 = alloca i32
%5 = alloca fp128
%6 = alloca fp128*
%7 = alloca i32
%8 = alloca i32
%9 = alloca fp128
%10 = alloca fp128
%11 = alloca fp128
store i32 %0, i32* %4
store fp128 %1, fp128* %5
store fp128* %2, fp128** %6
%12 = load i32, i32* %4
%13 = icmp sge i32 %12, 2
%14 = zext i1 %13 to i32
%15 = call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %14)
store i32 0, i32* %8
%16 = load fp128, fp128* %5
store fp128 %16, fp128* %9
store fp128 0xL00000000000000000000000000000000, fp128* %10
store i32 0, i32* %7
br label %17
17: ; preds = %47, %3
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %50
21: ; preds = %17
%22 = load i32, i32* %8
%23 = add nsw i32 %22, 1
store i32 %23, i32* %8
%24 = load fp128*, fp128** %6
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds fp128, fp128* %24, i64 %26
%28 = load fp128, fp128* %27
%29 = load fp128, fp128* %9
%30 = fsub fp128 %28, %29
store fp128 %30, fp128* %11
%31 = load fp128, fp128* %11
%32 = load i32, i32* %8
%33 = sitofp i32 %32 to fp128
%34 = fdiv fp128 %31, %33
%35 = load fp128, fp128* %9
%36 = fadd fp128 %35, %34
store fp128 %36, fp128* %9
%37 = load fp128, fp128* %11
%38 = load fp128*, fp128** %6
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds fp128, fp128* %38, i64 %40
%42 = load fp128, fp128* %41
%43 = load fp128, fp128* %9
%44 = fsub fp128 %42, %43
%45 = load fp128, fp128* %10
%46 = call fp128 @llvm.fmuladd.f128(fp128 %37, fp128 %44, fp128 %45)
store fp128 %46, fp128* %10
br label %47
47: ; preds = %21
%48 = load i32, i32* %7
%49 = add nsw i32 %48, 1
store i32 %49, i32* %7
br label %17
50: ; preds = %17
%51 = load fp128, fp128* %10
%52 = load i32, i32* %8
%53 = sub nsw i32 %52, 1
%54 = sitofp i32 %53 to fp128
%55 = fdiv fp128 %51, %54
ret fp128 %55
}

LLVM IR (-O2):
define fp128 @compute_variance(i32 %0, fp128 %1, fp128* nocapture %2) {
%4 = icmp sgt i32 %0, 1
%5 = zext i1 %4 to i32
%6 = tail call i32 (i32, ...) bitcast (i32 (...)* @assert to i32 (i32, ...)*)(i32 %5)
%7 = icmp sgt i32 %0, 0
br i1 %7, label %8, label %63
8: ; preds = %3
%9 = zext i32 %0 to i64
%10 = and i64 %9, 1
%11 = icmp eq i32 %0, 1
br i1 %11, label %41, label %12
12: ; preds = %8
%13 = and i64 %9, 4294967294
br label %14
14: ; preds = %14, %12
%15 = phi i64 [ 0, %12 ], [ %29, %14 ]
%16 = phi fp128 [ 0xL00000000000000000000000000000000, %12 ], [ %38, %14 ]
%17 = phi fp128 [ %1, %12 ], [ %36, %14 ]
%18 = phi i64 [ 0, %12 ], [ %39, %14 ]
%19 = or i64 %15, 1
%20 = trunc i64 %19 to i32
%21 = getelementptr inbounds fp128, fp128* %2, i64 %15
%22 = load fp128, fp128* %21
%23 = fsub fp128 %22, %17
%24 = sitofp i32 %20 to fp128
%25 = fdiv fp128 %23, %24
%26 = fadd fp128 %17, %25
%27 = fsub fp128 %22, %26
%28 = tail call fp128 @llvm.fmuladd.f128(fp128 %23, fp128 %27, fp128 %16)
%29 = add nuw nsw i64 %15, 2
%30 = trunc i64 %29 to i32
%31 = getelementptr inbounds fp128, fp128* %2, i64 %19
%32 = load fp128, fp128* %31
%33 = fsub fp128 %32, %26
%34 = sitofp i32 %30 to fp128
%35 = fdiv fp128 %33, %34
%36 = fadd fp128 %26, %35
%37 = fsub fp128 %32, %36
%38 = tail call fp128 @llvm.fmuladd.f128(fp128 %33, fp128 %37, fp128 %28)
%39 = add i64 %18, 2
%40 = icmp eq i64 %39, %13
br i1 %40, label %41, label %14
41: ; preds = %14, %8
%42 = phi fp128 [ undef, %8 ], [ %38, %14 ]
%43 = phi i64 [ 0, %8 ], [ %29, %14 ]
%44 = phi fp128 [ 0xL00000000000000000000000000000000, %8 ], [ %38, %14 ]
%45 = phi fp128 [ %1, %8 ], [ %36, %14 ]
%46 = icmp eq i64 %10, 0
br i1 %46, label %58, label %47
47: ; preds = %41
%48 = trunc i64 %43 to i32
%49 = add i32 %48, 1
%50 = getelementptr inbounds fp128, fp128* %2, i64 %43
%51 = load fp128, fp128* %50
%52 = fsub fp128 %51, %45
%53 = sitofp i32 %49 to fp128
%54 = fdiv fp128 %52, %53
%55 = fadd fp128 %45, %54
%56 = fsub fp128 %51, %55
%57 = tail call fp128 @llvm.fmuladd.f128(fp128 %52, fp128 %56, fp128 %44)
br label %58
58: ; preds = %41, %47
%59 = phi fp128 [ %42, %41 ], [ %57, %47 ]
%60 = add i32 %0, -1
%61 = sitofp i32 %60 to fp128
%62 = fdiv fp128 %59, %61
br label %63
63: ; preds = %58, %3
%64 = phi fp128 [ %62, %58 ], [ 0xL00000000000000008000000000000000, %3 ]
ret fp128 %64
}