void mulmp(double *result, const double *s1, const double *s2) {
  const double x = s1[(0 + (0 << 2))] * s2[0] + s1[(0 + (1 << 2))] * s2[1] +
                   s1[(0 + (2 << 2))] * s2[2] + s1[(0 + (3 << 2))];
  const double y = s1[(1 + (0 << 2))] * s2[0] + s1[(1 + (1 << 2))] * s2[1] +
                   s1[(1 + (2 << 2))] * s2[2] + s1[(1 + (3 << 2))];
  const double z = s1[(2 + (0 << 2))] * s2[0] + s1[(2 + (1 << 2))] * s2[1] +
                   s1[(2 + (2 << 2))] * s2[2] + s1[(2 + (3 << 2))];
  const double w = s1[(3 + (0 << 2))] * s2[0] + s1[(3 + (1 << 2))] * s2[1] +
                   s1[(3 + (2 << 2))] * s2[2] + s1[(3 + (3 << 2))];
  if (w != 1) {
    const double l = 1 / (double)w;
    result[0] = (double)(x * l);
    result[1] = (double)(y * l);
    result[2] = (double)(z * l);
  } else {
    result[0] = x;
    result[1] = y;
    result[2] = z;
  }
}


x86 assembly (clang, -O0):
<mulmp>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x20(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x40(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
addsd  0x60(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x28(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x48(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
addsd  0x68(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x30(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x50(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
addsd  0x70(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x38(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x58(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
addsd  0x78(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xd98(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    127d <mulmp+0x17d>
jp     127d <mulmp+0x17d>
jmp    12cc <mulmp+0x1cc>
movsd  0xd7b(%rip),%xmm0
divsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
jmp    12f5 <mulmp+0x1f5>
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x30(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<mulmp>:
movsd  (%rdx),%xmm7
movsd  0x8(%rdx),%xmm3
movsd  0x20(%rsi),%xmm0
mulsd  %xmm3,%xmm0
movsd  (%rsi),%xmm4
mulsd  %xmm7,%xmm4
addsd  %xmm0,%xmm4
movsd  0x10(%rdx),%xmm2
movsd  0x40(%rsi),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm4,%xmm0
addsd  0x60(%rsi),%xmm0
movapd %xmm3,%xmm4
unpcklpd %xmm3,%xmm4
movupd 0x8(%rsi),%xmm5
movupd 0x28(%rsi),%xmm6
mulpd  %xmm4,%xmm6
movupd 0x48(%rsi),%xmm9
movupd 0x68(%rsi),%xmm8
movapd %xmm7,%xmm1
unpcklpd %xmm7,%xmm1
mulpd  %xmm5,%xmm1
addpd  %xmm6,%xmm1
movapd %xmm2,%xmm4
unpcklpd %xmm2,%xmm4
mulpd  %xmm9,%xmm4
addpd  %xmm1,%xmm4
mulsd  0x38(%rsi),%xmm3
mulsd  0x18(%rsi),%xmm7
mulsd  0x58(%rsi),%xmm2
addsd  %xmm3,%xmm7
addsd  %xmm7,%xmm2
addsd  0x78(%rsi),%xmm2
addpd  %xmm8,%xmm4
ucomisd 0xe5f(%rip),%xmm2
jne    11a5 <mulmp+0xa5>
jnp    11c7 <mulmp+0xc7>
movsd  0xe53(%rip),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rdi)
unpcklpd %xmm1,%xmm1
mulpd  %xmm1,%xmm4
movupd %xmm4,0x8(%rdi)
ret
movsd  %xmm0,(%rdi)
movupd %xmm4,0x8(%rdi)
ret

LLVM IR (-O0):
define void @mulmp(double* %0, double* %1, double* %2) {
%4 = alloca double*
%5 = alloca double*
%6 = alloca double*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%12 = load double*, double** %5
%13 = getelementptr inbounds double, double* %12, i64 0
%14 = load double, double* %13
%15 = load double*, double** %6
%16 = getelementptr inbounds double, double* %15, i64 0
%17 = load double, double* %16
%18 = load double*, double** %5
%19 = getelementptr inbounds double, double* %18, i64 4
%20 = load double, double* %19
%21 = load double*, double** %6
%22 = getelementptr inbounds double, double* %21, i64 1
%23 = load double, double* %22
%24 = fmul double %20, %23
%25 = call double @llvm.fmuladd.f64(double %14, double %17, double %24)
%26 = load double*, double** %5
%27 = getelementptr inbounds double, double* %26, i64 8
%28 = load double, double* %27
%29 = load double*, double** %6
%30 = getelementptr inbounds double, double* %29, i64 2
%31 = load double, double* %30
%32 = call double @llvm.fmuladd.f64(double %28, double %31, double %25)
%33 = load double*, double** %5
%34 = getelementptr inbounds double, double* %33, i64 12
%35 = load double, double* %34
%36 = fadd double %32, %35
store double %36, double* %7
%37 = load double*, double** %5
%38 = getelementptr inbounds double, double* %37, i64 1
%39 = load double, double* %38
%40 = load double*, double** %6
%41 = getelementptr inbounds double, double* %40, i64 0
%42 = load double, double* %41
%43 = load double*, double** %5
%44 = getelementptr inbounds double, double* %43, i64 5
%45 = load double, double* %44
%46 = load double*, double** %6
%47 = getelementptr inbounds double, double* %46, i64 1
%48 = load double, double* %47
%49 = fmul double %45, %48
%50 = call double @llvm.fmuladd.f64(double %39, double %42, double %49)
%51 = load double*, double** %5
%52 = getelementptr inbounds double, double* %51, i64 9
%53 = load double, double* %52
%54 = load double*, double** %6
%55 = getelementptr inbounds double, double* %54, i64 2
%56 = load double, double* %55
%57 = call double @llvm.fmuladd.f64(double %53, double %56, double %50)
%58 = load double*, double** %5
%59 = getelementptr inbounds double, double* %58, i64 13
%60 = load double, double* %59
%61 = fadd double %57, %60
store double %61, double* %8
%62 = load double*, double** %5
%63 = getelementptr inbounds double, double* %62, i64 2
%64 = load double, double* %63
%65 = load double*, double** %6
%66 = getelementptr inbounds double, double* %65, i64 0
%67 = load double, double* %66
%68 = load double*, double** %5
%69 = getelementptr inbounds double, double* %68, i64 6
%70 = load double, double* %69
%71 = load double*, double** %6
%72 = getelementptr inbounds double, double* %71, i64 1
%73 = load double, double* %72
%74 = fmul double %70, %73
%75 = call double @llvm.fmuladd.f64(double %64, double %67, double %74)
%76 = load double*, double** %5
%77 = getelementptr inbounds double, double* %76, i64 10
%78 = load double, double* %77
%79 = load double*, double** %6
%80 = getelementptr inbounds double, double* %79, i64 2
%81 = load double, double* %80
%82 = call double @llvm.fmuladd.f64(double %78, double %81, double %75)
%83 = load double*, double** %5
%84 = getelementptr inbounds double, double* %83, i64 14
%85 = load double, double* %84
%86 = fadd double %82, %85
store double %86, double* %9
%87 = load double*, double** %5
%88 = getelementptr inbounds double, double* %87, i64 3
%89 = load double, double* %88
%90 = load double*, double** %6
%91 = getelementptr inbounds double, double* %90, i64 0
%92 = load double, double* %91
%93 = load double*, double** %5
%94 = getelementptr inbounds double, double* %93, i64 7
%95 = load double, double* %94
%96 = load double*, double** %6
%97 = getelementptr inbounds double, double* %96, i64 1
%98 = load double, double* %97
%99 = fmul double %95, %98
%100 = call double @llvm.fmuladd.f64(double %89, double %92, double %99)
%101 = load double*, double** %5
%102 = getelementptr inbounds double, double* %101, i64 11
%103 = load double, double* %102
%104 = load double*, double** %6
%105 = getelementptr inbounds double, double* %104, i64 2
%106 = load double, double* %105
%107 = call double @llvm.fmuladd.f64(double %103, double %106, double %100)
%108 = load double*, double** %5
%109 = getelementptr inbounds double, double* %108, i64 15
%110 = load double, double* %109
%111 = fadd double %107, %110
store double %111, double* %10
%112 = load double, double* %10
%113 = fcmp une double %112, 1.000000e+00
br i1 %113, label %114, label %132
114: ; preds = %3
%115 = load double, double* %10
%116 = fdiv double 1.000000e+00, %115
store double %116, double* %11
%117 = load double, double* %7
%118 = load double, double* %11
%119 = fmul double %117, %118
%120 = load double*, double** %4
%121 = getelementptr inbounds double, double* %120, i64 0
store double %119, double* %121
%122 = load double, double* %8
%123 = load double, double* %11
%124 = fmul double %122, %123
%125 = load double*, double** %4
%126 = getelementptr inbounds double, double* %125, i64 1
store double %124, double* %126
%127 = load double, double* %9
%128 = load double, double* %11
%129 = fmul double %127, %128
%130 = load double*, double** %4
%131 = getelementptr inbounds double, double* %130, i64 2
store double %129, double* %131
br label %142
132: ; preds = %3
%133 = load double, double* %7
%134 = load double*, double** %4
%135 = getelementptr inbounds double, double* %134, i64 0
store double %133, double* %135
%136 = load double, double* %8
%137 = load double*, double** %4
%138 = getelementptr inbounds double, double* %137, i64 1
store double %136, double* %138
%139 = load double, double* %9
%140 = load double*, double** %4
%141 = getelementptr inbounds double, double* %140, i64 2
store double %139, double* %141
br label %142
142: ; preds = %132, %114
ret void
}

LLVM IR (-O2):
define void @mulmp(double* nocapture writeonly %0, double* nocapture %1, double* nocapture %2) {
%4 = load double, double* %1
%5 = load double, double* %2
%6 = getelementptr inbounds double, double* %1, i64 4
%7 = load double, double* %6
%8 = getelementptr inbounds double, double* %2, i64 1
%9 = load double, double* %8
%10 = fmul double %7, %9
%11 = tail call double @llvm.fmuladd.f64(double %4, double %5, double %10)
%12 = getelementptr inbounds double, double* %1, i64 8
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %2, i64 2
%15 = load double, double* %14
%16 = tail call double @llvm.fmuladd.f64(double %13, double %15, double %11)
%17 = getelementptr inbounds double, double* %1, i64 12
%18 = load double, double* %17
%19 = fadd double %16, %18
%20 = getelementptr inbounds double, double* %1, i64 1
%21 = getelementptr inbounds double, double* %1, i64 5
%22 = getelementptr inbounds double, double* %1, i64 9
%23 = getelementptr inbounds double, double* %1, i64 13
%24 = bitcast double* %20 to <2 x double>*
%25 = load <2 x double>, <2 x double>* %24
%26 = bitcast double* %21 to <2 x double>*
%27 = load <2 x double>, <2 x double>* %26
%28 = insertelement <2 x double> poison, double %9, i64 0
%29 = shufflevector <2 x double> %28, <2 x double> poison, <2 x i32> zeroinitializer
%30 = fmul <2 x double> %29, %27
%31 = insertelement <2 x double> poison, double %5, i64 0
%32 = shufflevector <2 x double> %31, <2 x double> poison, <2 x i32> zeroinitializer
%33 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %25, <2 x double> %32, <2 x double> %30)
%34 = bitcast double* %22 to <2 x double>*
%35 = load <2 x double>, <2 x double>* %34
%36 = insertelement <2 x double> poison, double %15, i64 0
%37 = shufflevector <2 x double> %36, <2 x double> poison, <2 x i32> zeroinitializer
%38 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %35, <2 x double> %37, <2 x double> %33)
%39 = bitcast double* %23 to <2 x double>*
%40 = load <2 x double>, <2 x double>* %39
%41 = fadd <2 x double> %40, %38
%42 = getelementptr inbounds double, double* %1, i64 3
%43 = load double, double* %42
%44 = getelementptr inbounds double, double* %1, i64 7
%45 = load double, double* %44
%46 = fmul double %9, %45
%47 = tail call double @llvm.fmuladd.f64(double %43, double %5, double %46)
%48 = getelementptr inbounds double, double* %1, i64 11
%49 = load double, double* %48
%50 = tail call double @llvm.fmuladd.f64(double %49, double %15, double %47)
%51 = getelementptr inbounds double, double* %1, i64 15
%52 = load double, double* %51
%53 = fadd double %52, %50
%54 = fcmp une double %53, 1.000000e+00
br i1 %54, label %55, label %61
55: ; preds = %3
%56 = fdiv double 1.000000e+00, %53
%57 = fmul double %19, %56
store double %57, double* %0
%58 = insertelement <2 x double> poison, double %56, i64 0
%59 = shufflevector <2 x double> %58, <2 x double> poison, <2 x i32> zeroinitializer
%60 = fmul <2 x double> %41, %59
br label %62
61: ; preds = %3
store double %19, double* %0
br label %62
62: ; preds = %61, %55
%63 = phi <2 x double> [ %60, %55 ], [ %41, %61 ]
%64 = getelementptr inbounds double, double* %0, i64 1
%65 = bitcast double* %64 to <2 x double>*
store <2 x double> %63, <2 x double>* %65
ret void
}