void gradient_step(double *vector, double *centroid, int count, int D) {
  double eta = 1.0 / count;
  double eta_compliment = 1.0 - eta;
  for (int i = 0; i < D; i++) {
    centroid[i] = eta_compliment * centroid[i] + eta * vector[i];
  }
}


x86 assembly (clang, -O0):
<gradient_step>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
cvtsi2sdl -0x14(%rbp),%xmm1
movsd  0xee1(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xed0(%rip),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    1194 <gradient_step+0x94>
movsd  -0x28(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm2
movsd  -0x20(%rbp),%xmm1
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
movslq -0x2c(%rbp),%rcx
movsd  %xmm0,(%rax,%rcx,8)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1141 <gradient_step+0x41>
pop    %rbp
ret

x86 assembly (clang, -O2):
<gradient_step>:
test   %ecx,%ecx
jle    12d7 <gradient_step+0x1d7>
cvtsi2sd %edx,%xmm2
movsd  0xeeb(%rip),%xmm8
movapd %xmm8,%xmm9
divsd  %xmm2,%xmm9
subsd  %xmm9,%xmm8
mov    %ecx,%r9d
cmp    $0x4,%ecx
jb     1146 <gradient_step+0x46>
lea    (%rdi,%r9,8),%rax
cmp    %rsi,%rax
jbe    11cb <gradient_step+0xcb>
lea    (%rsi,%r9,8),%rax
cmp    %rdi,%rax
jbe    11cb <gradient_step+0xcb>
xor    %ecx,%ecx
mov    %rcx,%rax
not    %rax
test   $0x1,%r9b
je     1175 <gradient_step+0x75>
movsd  (%rdi,%rcx,8),%xmm0
mulsd  %xmm9,%xmm0
movsd  (%rsi,%rcx,8),%xmm1
mulsd  %xmm8,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsi,%rcx,8)
or     $0x1,%rcx
add    %r9,%rax
je     12d7 <gradient_step+0x1d7>
xchg   %ax,%ax
movsd  (%rdi,%rcx,8),%xmm0
mulsd  %xmm9,%xmm0
movsd  (%rsi,%rcx,8),%xmm1
mulsd  %xmm8,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsi,%rcx,8)
movsd  0x8(%rdi,%rcx,8),%xmm0
mulsd  %xmm9,%xmm0
movsd  0x8(%rsi,%rcx,8),%xmm1
mulsd  %xmm8,%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsi,%rcx,8)
add    $0x2,%rcx
cmp    %rcx,%r9
jne    1180 <gradient_step+0x80>
jmp    12d7 <gradient_step+0x1d7>
mov    %r9d,%ecx
and    $0xfffffffc,%ecx
movapd %xmm9,%xmm3
unpcklpd %xmm9,%xmm3
movapd %xmm8,%xmm2
unpcklpd %xmm8,%xmm2
lea    -0x4(%rcx),%rax
mov    %rax,%r8
shr    $0x2,%r8
add    $0x1,%r8
test   %rax,%rax
je     12d8 <gradient_step+0x1d8>
mov    %r8,%rax
and    $0xfffffffffffffffe,%rax
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
movupd (%rdi,%rdx,8),%xmm4
movupd 0x10(%rdi,%rdx,8),%xmm5
mulpd  %xmm3,%xmm4
mulpd  %xmm3,%xmm5
movupd (%rsi,%rdx,8),%xmm6
movupd 0x10(%rsi,%rdx,8),%xmm7
movupd 0x20(%rsi,%rdx,8),%xmm0
movupd 0x30(%rsi,%rdx,8),%xmm1
mulpd  %xmm2,%xmm6
addpd  %xmm4,%xmm6
mulpd  %xmm2,%xmm7
addpd  %xmm5,%xmm7
movupd %xmm6,(%rsi,%rdx,8)
movupd %xmm7,0x10(%rsi,%rdx,8)
movupd 0x20(%rdi,%rdx,8),%xmm4
movupd 0x30(%rdi,%rdx,8),%xmm5
mulpd  %xmm3,%xmm4
mulpd  %xmm3,%xmm5
mulpd  %xmm2,%xmm0
addpd  %xmm4,%xmm0
mulpd  %xmm2,%xmm1
addpd  %xmm5,%xmm1
movupd %xmm0,0x20(%rsi,%rdx,8)
movupd %xmm1,0x30(%rsi,%rdx,8)
add    $0x8,%rdx
add    $0xfffffffffffffffe,%rax
jne    1210 <gradient_step+0x110>
test   $0x1,%r8b
je     12ce <gradient_step+0x1ce>
movupd (%rsi,%rdx,8),%xmm0
movupd 0x10(%rsi,%rdx,8),%xmm1
movupd (%rdi,%rdx,8),%xmm4
movupd 0x10(%rdi,%rdx,8),%xmm5
mulpd  %xmm3,%xmm4
mulpd  %xmm3,%xmm5
mulpd  %xmm2,%xmm0
addpd  %xmm4,%xmm0
mulpd  %xmm2,%xmm1
addpd  %xmm5,%xmm1
movupd %xmm0,(%rsi,%rdx,8)
movupd %xmm1,0x10(%rsi,%rdx,8)
cmp    %r9,%rcx
jne    1148 <gradient_step+0x48>
ret
xor    %edx,%edx
test   $0x1,%r8b
jne    1295 <gradient_step+0x195>
jmp    12ce <gradient_step+0x1ce>

LLVM IR (-O0):
define void @gradient_step(double* %0, double* %1, i32 %2, i32 %3) {
%5 = alloca double*
%6 = alloca double*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca i32
store double* %0, double** %5
store double* %1, double** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%12 = load i32, i32* %7
%13 = sitofp i32 %12 to double
%14 = fdiv double 1.000000e+00, %13
store double %14, double* %9
%15 = load double, double* %9
%16 = fsub double 1.000000e+00, %15
store double %16, double* %10
store i32 0, i32* %11
br label %17
17: ; preds = %40, %4
%18 = load i32, i32* %11
%19 = load i32, i32* %8
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %43
21: ; preds = %17
%22 = load double, double* %10
%23 = load double*, double** %6
%24 = load i32, i32* %11
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds double, double* %23, i64 %25
%27 = load double, double* %26
%28 = load double, double* %9
%29 = load double*, double** %5
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds double, double* %29, i64 %31
%33 = load double, double* %32
%34 = fmul double %28, %33
%35 = call double @llvm.fmuladd.f64(double %22, double %27, double %34)
%36 = load double*, double** %6
%37 = load i32, i32* %11
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds double, double* %36, i64 %38
store double %35, double* %39
br label %40
40: ; preds = %21
%41 = load i32, i32* %11
%42 = add nsw i32 %41, 1
store i32 %42, i32* %11
br label %17
43: ; preds = %17
ret void
}

LLVM IR (-O2):
define void @gradient_step(double* nocapture %0, double* nocapture %1, i32 %2, i32 %3) {
%5 = sitofp i32 %2 to double
%6 = fdiv double 1.000000e+00, %5
%7 = fsub double 1.000000e+00, %6
%8 = icmp sgt i32 %3, 0
br i1 %8, label %9, label %119
9: ; preds = %4
%10 = zext i32 %3 to i64
%11 = icmp ult i32 %3, 4
br i1 %11, label %102, label %12
12: ; preds = %9
%13 = getelementptr double, double* %1, i64 %10
%14 = getelementptr double, double* %0, i64 %10
%15 = icmp ugt double* %14, %1
%16 = icmp ugt double* %13, %0
%17 = and i1 %15, %16
br i1 %17, label %102, label %18
18: ; preds = %12
%19 = and i64 %10, 4294967292
%20 = insertelement <2 x double> poison, double %6, i64 0
%21 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
%22 = insertelement <2 x double> poison, double %6, i64 0
%23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> zeroinitializer
%24 = insertelement <2 x double> poison, double %7, i64 0
%25 = shufflevector <2 x double> %24, <2 x double> poison, <2 x i32> zeroinitializer
%26 = insertelement <2 x double> poison, double %7, i64 0
%27 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> zeroinitializer
%28 = add nsw i64 %19, -4
%29 = lshr exact i64 %28, 2
%30 = add nuw nsw i64 %29, 1
%31 = and i64 %30, 1
%32 = icmp eq i64 %28, 0
br i1 %32, label %78, label %33
33: ; preds = %18
%34 = and i64 %30, 9223372036854775806
br label %35
35: ; preds = %35, %33
%36 = phi i64 [ 0, %33 ], [ %75, %35 ]
%37 = phi i64 [ 0, %33 ], [ %76, %35 ]
%38 = getelementptr inbounds double, double* %1, i64 %36
%39 = bitcast double* %38 to <2 x double>*
%40 = load <2 x double>, <2 x double>* %39
%41 = getelementptr inbounds double, double* %38, i64 2
%42 = bitcast double* %41 to <2 x double>*
%43 = load <2 x double>, <2 x double>* %42
%44 = getelementptr inbounds double, double* %0, i64 %36
%45 = bitcast double* %44 to <2 x double>*
%46 = load <2 x double>, <2 x double>* %45
%47 = getelementptr inbounds double, double* %44, i64 2
%48 = bitcast double* %47 to <2 x double>*
%49 = load <2 x double>, <2 x double>* %48
%50 = fmul <2 x double> %21, %46
%51 = fmul <2 x double> %23, %49
%52 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %25, <2 x double> %40, <2 x double> %50)
%53 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %27, <2 x double> %43, <2 x double> %51)
%54 = bitcast double* %38 to <2 x double>*
store <2 x double> %52, <2 x double>* %54
%55 = bitcast double* %41 to <2 x double>*
store <2 x double> %53, <2 x double>* %55
%56 = or i64 %36, 4
%57 = getelementptr inbounds double, double* %1, i64 %56
%58 = bitcast double* %57 to <2 x double>*
%59 = load <2 x double>, <2 x double>* %58
%60 = getelementptr inbounds double, double* %57, i64 2
%61 = bitcast double* %60 to <2 x double>*
%62 = load <2 x double>, <2 x double>* %61
%63 = getelementptr inbounds double, double* %0, i64 %56
%64 = bitcast double* %63 to <2 x double>*
%65 = load <2 x double>, <2 x double>* %64
%66 = getelementptr inbounds double, double* %63, i64 2
%67 = bitcast double* %66 to <2 x double>*
%68 = load <2 x double>, <2 x double>* %67
%69 = fmul <2 x double> %21, %65
%70 = fmul <2 x double> %23, %68
%71 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %25, <2 x double> %59, <2 x double> %69)
%72 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %27, <2 x double> %62, <2 x double> %70)
%73 = bitcast double* %57 to <2 x double>*
store <2 x double> %71, <2 x double>* %73
%74 = bitcast double* %60 to <2 x double>*
store <2 x double> %72, <2 x double>* %74
%75 = add nuw i64 %36, 8
%76 = add i64 %37, 2
%77 = icmp eq i64 %76, %34
br i1 %77, label %78, label %35
78: ; preds = %35, %18
%79 = phi i64 [ 0, %18 ], [ %75, %35 ]
%80 = icmp eq i64 %31, 0
br i1 %80, label %100, label %81
81: ; preds = %78
%82 = getelementptr inbounds double, double* %1, i64 %79
%83 = bitcast double* %82 to <2 x double>*
%84 = load <2 x double>, <2 x double>* %83
%85 = getelementptr inbounds double, double* %82, i64 2
%86 = bitcast double* %85 to <2 x double>*
%87 = load <2 x double>, <2 x double>* %86
%88 = getelementptr inbounds double, double* %0, i64 %79
%89 = bitcast double* %88 to <2 x double>*
%90 = load <2 x double>, <2 x double>* %89
%91 = getelementptr inbounds double, double* %88, i64 2
%92 = bitcast double* %91 to <2 x double>*
%93 = load <2 x double>, <2 x double>* %92
%94 = fmul <2 x double> %21, %90
%95 = fmul <2 x double> %23, %93
%96 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %25, <2 x double> %84, <2 x double> %94)
%97 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %27, <2 x double> %87, <2 x double> %95)
%98 = bitcast double* %82 to <2 x double>*
store <2 x double> %96, <2 x double>* %98
%99 = bitcast double* %85 to <2 x double>*
store <2 x double> %97, <2 x double>* %99
br label %100
100: ; preds = %78, %81
%101 = icmp eq i64 %19, %10
br i1 %101, label %119, label %102
102: ; preds = %12, %9, %100
%103 = phi i64 [ 0, %12 ], [ 0, %9 ], [ %19, %100 ]
%104 = xor i64 %103, -1
%105 = and i64 %10, 1
%106 = icmp eq i64 %105, 0
br i1 %106, label %115, label %107
107: ; preds = %102
%108 = getelementptr inbounds double, double* %1, i64 %103
%109 = load double, double* %108
%110 = getelementptr inbounds double, double* %0, i64 %103
%111 = load double, double* %110
%112 = fmul double %6, %111
%113 = tail call double @llvm.fmuladd.f64(double %7, double %109, double %112)
store double %113, double* %108
%114 = or i64 %103, 1
br label %115
115: ; preds = %107, %102
%116 = phi i64 [ %103, %102 ], [ %114, %107 ]
%117 = sub nsw i64 0, %10
%118 = icmp eq i64 %104, %117
br i1 %118, label %119, label %120
119: ; preds = %115, %120, %100, %4
ret void
120: ; preds = %115, %120
%121 = phi i64 [ %135, %120 ], [ %116, %115 ]
%122 = getelementptr inbounds double, double* %1, i64 %121
%123 = load double, double* %122
%124 = getelementptr inbounds double, double* %0, i64 %121
%125 = load double, double* %124
%126 = fmul double %6, %125
%127 = tail call double @llvm.fmuladd.f64(double %7, double %123, double %126)
store double %127, double* %122
%128 = add nuw nsw i64 %121, 1
%129 = getelementptr inbounds double, double* %1, i64 %128
%130 = load double, double* %129
%131 = getelementptr inbounds double, double* %0, i64 %128
%132 = load double, double* %131
%133 = fmul double %6, %132
%134 = tail call double @llvm.fmuladd.f64(double %7, double %130, double %133)
store double %134, double* %129
%135 = add nuw nsw i64 %121, 2
%136 = icmp eq i64 %135, %10
br i1 %136, label %119, label %120
}