void mulpm(double *result, const double *s1, const double *s2) {
  const double x = s1[0] * s2[(0 + (0 << 2))] + s1[1] * s2[(1 + (0 << 2))] +
                   s1[2] * s2[(2 + (0 << 2))] + s2[(3 + (0 << 2))];
  const double y = s1[0] * s2[(0 + (1 << 2))] + s1[1] * s2[(1 + (1 << 2))] +
                   s1[2] * s2[(2 + (1 << 2))] + s2[(3 + (1 << 2))];
  const double z = s1[0] * s2[(0 + (2 << 2))] + s1[1] * s2[(1 + (2 << 2))] +
                   s1[2] * s2[(2 + (2 << 2))] + s2[(3 + (2 << 2))];
  const double w = s1[0] * s2[(0 + (3 << 2))] + s1[1] * s2[(1 + (3 << 2))] +
                   s1[2] * s2[(2 + (3 << 2))] + s2[(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):
<mulpm>:
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  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x8(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
addsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  0x20(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x28(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x30(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
addsd  0x38(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  0x40(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x48(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x50(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
addsd  0x58(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
mov    -0x18(%rbp),%rax
movsd  0x60(%rax),%xmm2
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
mov    -0x18(%rbp),%rax
mulsd  0x68(%rax),%xmm0
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
mov    -0x18(%rbp),%rax
movsd  0x70(%rax),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
addsd  0x78(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xd98(%rip),%xmm1
ucomisd %xmm1,%xmm0
jne    127d <mulpm+0x17d>
jp     127d <mulpm+0x17d>
jmp    12cc <mulpm+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 <mulpm+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):
<mulpm>:
movsd  (%rsi),%xmm1
movsd  0x8(%rsi),%xmm8
movsd  0x8(%rdx),%xmm0
mulsd  %xmm8,%xmm0
movsd  (%rdx),%xmm3
mulsd  %xmm1,%xmm3
addsd  %xmm0,%xmm3
movsd  0x10(%rsi),%xmm2
movsd  0x10(%rdx),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm3,%xmm0
addsd  0x18(%rdx),%xmm0
movapd %xmm8,%xmm6
unpcklpd %xmm8,%xmm6
movsd  0x20(%rdx),%xmm7
movsd  0x28(%rdx),%xmm4
movsd  0x30(%rdx),%xmm5
movhpd 0x48(%rdx),%xmm4
movsd  0x38(%rdx),%xmm3
mulpd  %xmm6,%xmm4
movapd %xmm1,%xmm6
movhpd 0x40(%rdx),%xmm7
unpcklpd %xmm1,%xmm6
mulpd  %xmm6,%xmm7
addpd  %xmm4,%xmm7
movapd %xmm2,%xmm4
unpcklpd %xmm2,%xmm4
movhpd 0x50(%rdx),%xmm5
mulpd  %xmm4,%xmm5
addpd  %xmm7,%xmm5
movhpd 0x58(%rdx),%xmm3
mulsd  0x68(%rdx),%xmm8
mulsd  0x60(%rdx),%xmm1
mulsd  0x70(%rdx),%xmm2
addsd  %xmm8,%xmm1
addsd  %xmm1,%xmm2
addsd  0x78(%rdx),%xmm2
addpd  %xmm5,%xmm3
ucomisd 0xe49(%rip),%xmm2
jne    11bb <mulpm+0xbb>
jnp    11dd <mulpm+0xdd>
movsd  0xe3d(%rip),%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,(%rdi)
unpcklpd %xmm1,%xmm1
mulpd  %xmm1,%xmm3
movupd %xmm3,0x8(%rdi)
ret
movsd  %xmm0,(%rdi)
movupd %xmm3,0x8(%rdi)
ret

LLVM IR (-O0):
define void @mulpm(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 1
%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 2
%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** %6
%34 = getelementptr inbounds double, double* %33, i64 3
%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 0
%39 = load double, double* %38
%40 = load double*, double** %6
%41 = getelementptr inbounds double, double* %40, i64 4
%42 = load double, double* %41
%43 = load double*, double** %5
%44 = getelementptr inbounds double, double* %43, i64 1
%45 = load double, double* %44
%46 = load double*, double** %6
%47 = getelementptr inbounds double, double* %46, i64 5
%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 2
%53 = load double, double* %52
%54 = load double*, double** %6
%55 = getelementptr inbounds double, double* %54, i64 6
%56 = load double, double* %55
%57 = call double @llvm.fmuladd.f64(double %53, double %56, double %50)
%58 = load double*, double** %6
%59 = getelementptr inbounds double, double* %58, i64 7
%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 0
%64 = load double, double* %63
%65 = load double*, double** %6
%66 = getelementptr inbounds double, double* %65, i64 8
%67 = load double, double* %66
%68 = load double*, double** %5
%69 = getelementptr inbounds double, double* %68, i64 1
%70 = load double, double* %69
%71 = load double*, double** %6
%72 = getelementptr inbounds double, double* %71, i64 9
%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 2
%78 = load double, double* %77
%79 = load double*, double** %6
%80 = getelementptr inbounds double, double* %79, i64 10
%81 = load double, double* %80
%82 = call double @llvm.fmuladd.f64(double %78, double %81, double %75)
%83 = load double*, double** %6
%84 = getelementptr inbounds double, double* %83, i64 11
%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 0
%89 = load double, double* %88
%90 = load double*, double** %6
%91 = getelementptr inbounds double, double* %90, i64 12
%92 = load double, double* %91
%93 = load double*, double** %5
%94 = getelementptr inbounds double, double* %93, i64 1
%95 = load double, double* %94
%96 = load double*, double** %6
%97 = getelementptr inbounds double, double* %96, i64 13
%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 2
%103 = load double, double* %102
%104 = load double*, double** %6
%105 = getelementptr inbounds double, double* %104, i64 14
%106 = load double, double* %105
%107 = call double @llvm.fmuladd.f64(double %103, double %106, double %100)
%108 = load double*, double** %6
%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 @mulpm(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 1
%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 2
%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* %2, i64 3
%18 = load double, double* %17
%19 = fadd double %16, %18
%20 = getelementptr inbounds double, double* %2, i64 4
%21 = load double, double* %20
%22 = getelementptr inbounds double, double* %2, i64 5
%23 = load double, double* %22
%24 = getelementptr inbounds double, double* %2, i64 6
%25 = load double, double* %24
%26 = getelementptr inbounds double, double* %2, i64 7
%27 = load double, double* %26
%28 = getelementptr inbounds double, double* %2, i64 8
%29 = load double, double* %28
%30 = getelementptr inbounds double, double* %2, i64 9
%31 = load double, double* %30
%32 = insertelement <2 x double> poison, double %7, i64 0
%33 = shufflevector <2 x double> %32, <2 x double> poison, <2 x i32> zeroinitializer
%34 = insertelement <2 x double> poison, double %23, i64 0
%35 = insertelement <2 x double> %34, double %31, i64 1
%36 = fmul <2 x double> %33, %35
%37 = insertelement <2 x double> poison, double %4, i64 0
%38 = shufflevector <2 x double> %37, <2 x double> poison, <2 x i32> zeroinitializer
%39 = insertelement <2 x double> poison, double %21, i64 0
%40 = insertelement <2 x double> %39, double %29, i64 1
%41 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %38, <2 x double> %40, <2 x double> %36)
%42 = getelementptr inbounds double, double* %2, i64 10
%43 = load double, double* %42
%44 = insertelement <2 x double> poison, double %13, i64 0
%45 = shufflevector <2 x double> %44, <2 x double> poison, <2 x i32> zeroinitializer
%46 = insertelement <2 x double> poison, double %25, i64 0
%47 = insertelement <2 x double> %46, double %43, i64 1
%48 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %45, <2 x double> %47, <2 x double> %41)
%49 = getelementptr inbounds double, double* %2, i64 11
%50 = load double, double* %49
%51 = insertelement <2 x double> poison, double %27, i64 0
%52 = insertelement <2 x double> %51, double %50, i64 1
%53 = fadd <2 x double> %52, %48
%54 = getelementptr inbounds double, double* %2, i64 12
%55 = load double, double* %54
%56 = getelementptr inbounds double, double* %2, i64 13
%57 = load double, double* %56
%58 = fmul double %7, %57
%59 = tail call double @llvm.fmuladd.f64(double %4, double %55, double %58)
%60 = getelementptr inbounds double, double* %2, i64 14
%61 = load double, double* %60
%62 = tail call double @llvm.fmuladd.f64(double %13, double %61, double %59)
%63 = getelementptr inbounds double, double* %2, i64 15
%64 = load double, double* %63
%65 = fadd double %64, %62
%66 = fcmp une double %65, 1.000000e+00
br i1 %66, label %67, label %73
67: ; preds = %3
%68 = fdiv double 1.000000e+00, %65
%69 = fmul double %19, %68
store double %69, double* %0
%70 = insertelement <2 x double> poison, double %68, i64 0
%71 = shufflevector <2 x double> %70, <2 x double> poison, <2 x i32> zeroinitializer
%72 = fmul <2 x double> %53, %71
br label %74
73: ; preds = %3
store double %19, double* %0
br label %74
74: ; preds = %73, %67
%75 = phi <2 x double> [ %72, %67 ], [ %53, %73 ]
%76 = getelementptr inbounds double, double* %0, i64 1
%77 = bitcast double* %76 to <2 x double>*
store <2 x double> %75, <2 x double>* %77
ret void
}