void quaternion_mult(double z[4], double x[4], double y[4]) {
  double a = x[0];
  double b = x[1];
  double c = x[2];
  double d = x[3];
  double y0 = y[0];
  double y1 = y[1];
  double y2 = y[2];
  double y3 = y[3];
  z[0] = a * y0 - b * y1 - c * y2 - d * y3;
  z[1] = b * y0 + a * y1 - d * y2 + c * y3;
  z[2] = c * y0 + d * y1 + a * y2 - b * y3;
  z[3] = d * y0 - c * y1 + b * y2 + a * y3;
}


x86 assembly (clang, -O0):
<quaternion_mult>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x10(%rax),%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x18(%rbp),%rax
movsd  0x18(%rax),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x28(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x28(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x38(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x8(%rax)
movsd  -0x30(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x38(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x10(%rax)
movsd  -0x38(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm1
mulsd  -0x48(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  -0x50(%rbp),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,0x18(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<quaternion_mult>:
movupd (%rsi),%xmm3
movupd 0x10(%rsi),%xmm9
movapd %xmm3,%xmm0
unpckhpd %xmm3,%xmm0
movapd 0xee6(%rip),%xmm2
xorpd  %xmm2,%xmm0
xorpd  %xmm9,%xmm2
movsd  (%rdx),%xmm4
movsd  0x8(%rdx),%xmm1
movsd  0x10(%rdx),%xmm5
movsd  0x18(%rdx),%xmm8
movapd %xmm1,%xmm6
unpcklpd %xmm3,%xmm6
movapd %xmm0,%xmm7
unpcklpd %xmm1,%xmm7
mulpd  %xmm6,%xmm7
unpcklpd %xmm4,%xmm4
unpcklpd %xmm5,%xmm5
movapd %xmm9,%xmm6
mulpd  %xmm5,%xmm6
mulpd  %xmm3,%xmm5
unpcklpd %xmm3,%xmm0
mulpd  %xmm4,%xmm3
addpd  %xmm7,%xmm3
subpd  %xmm6,%xmm3
movapd %xmm9,%xmm6
shufpd $0x1,%xmm2,%xmm6
shufpd $0x1,%xmm9,%xmm2
unpcklpd %xmm8,%xmm8
mulpd  %xmm8,%xmm2
addpd  %xmm3,%xmm2
movupd %xmm2,(%rdi)
unpcklpd %xmm1,%xmm1
mulpd  %xmm6,%xmm1
mulpd  %xmm9,%xmm4
addpd  %xmm1,%xmm4
addpd  %xmm4,%xmm5
mulpd  %xmm8,%xmm0
addpd  %xmm5,%xmm0
movupd %xmm0,0x10(%rdi)
ret

LLVM IR (-O0):
define void @quaternion_mult(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
%12 = alloca double
%13 = alloca double
%14 = alloca double
store double* %0, double** %4
store double* %1, double** %5
store double* %2, double** %6
%15 = load double*, double** %5
%16 = getelementptr inbounds double, double* %15, i64 0
%17 = load double, double* %16
store double %17, double* %7
%18 = load double*, double** %5
%19 = getelementptr inbounds double, double* %18, i64 1
%20 = load double, double* %19
store double %20, double* %8
%21 = load double*, double** %5
%22 = getelementptr inbounds double, double* %21, i64 2
%23 = load double, double* %22
store double %23, double* %9
%24 = load double*, double** %5
%25 = getelementptr inbounds double, double* %24, i64 3
%26 = load double, double* %25
store double %26, double* %10
%27 = load double*, double** %6
%28 = getelementptr inbounds double, double* %27, i64 0
%29 = load double, double* %28
store double %29, double* %11
%30 = load double*, double** %6
%31 = getelementptr inbounds double, double* %30, i64 1
%32 = load double, double* %31
store double %32, double* %12
%33 = load double*, double** %6
%34 = getelementptr inbounds double, double* %33, i64 2
%35 = load double, double* %34
store double %35, double* %13
%36 = load double*, double** %6
%37 = getelementptr inbounds double, double* %36, i64 3
%38 = load double, double* %37
store double %38, double* %14
%39 = load double, double* %7
%40 = load double, double* %11
%41 = load double, double* %8
%42 = load double, double* %12
%43 = fmul double %41, %42
%44 = fneg double %43
%45 = call double @llvm.fmuladd.f64(double %39, double %40, double %44)
%46 = load double, double* %9
%47 = load double, double* %13
%48 = fneg double %46
%49 = call double @llvm.fmuladd.f64(double %48, double %47, double %45)
%50 = load double, double* %10
%51 = load double, double* %14
%52 = fneg double %50
%53 = call double @llvm.fmuladd.f64(double %52, double %51, double %49)
%54 = load double*, double** %4
%55 = getelementptr inbounds double, double* %54, i64 0
store double %53, double* %55
%56 = load double, double* %8
%57 = load double, double* %11
%58 = load double, double* %7
%59 = load double, double* %12
%60 = fmul double %58, %59
%61 = call double @llvm.fmuladd.f64(double %56, double %57, double %60)
%62 = load double, double* %10
%63 = load double, double* %13
%64 = fneg double %62
%65 = call double @llvm.fmuladd.f64(double %64, double %63, double %61)
%66 = load double, double* %9
%67 = load double, double* %14
%68 = call double @llvm.fmuladd.f64(double %66, double %67, double %65)
%69 = load double*, double** %4
%70 = getelementptr inbounds double, double* %69, i64 1
store double %68, double* %70
%71 = load double, double* %9
%72 = load double, double* %11
%73 = load double, double* %10
%74 = load double, double* %12
%75 = fmul double %73, %74
%76 = call double @llvm.fmuladd.f64(double %71, double %72, double %75)
%77 = load double, double* %7
%78 = load double, double* %13
%79 = call double @llvm.fmuladd.f64(double %77, double %78, double %76)
%80 = load double, double* %8
%81 = load double, double* %14
%82 = fneg double %80
%83 = call double @llvm.fmuladd.f64(double %82, double %81, double %79)
%84 = load double*, double** %4
%85 = getelementptr inbounds double, double* %84, i64 2
store double %83, double* %85
%86 = load double, double* %10
%87 = load double, double* %11
%88 = load double, double* %9
%89 = load double, double* %12
%90 = fmul double %88, %89
%91 = fneg double %90
%92 = call double @llvm.fmuladd.f64(double %86, double %87, double %91)
%93 = load double, double* %8
%94 = load double, double* %13
%95 = call double @llvm.fmuladd.f64(double %93, double %94, double %92)
%96 = load double, double* %7
%97 = load double, double* %14
%98 = call double @llvm.fmuladd.f64(double %96, double %97, double %95)
%99 = load double*, double** %4
%100 = getelementptr inbounds double, double* %99, i64 3
store double %98, double* %100
ret void
}

LLVM IR (-O2):
define void @quaternion_mult(double* nocapture writeonly %0, double* nocapture %1, double* nocapture %2) {
%4 = bitcast double* %1 to <2 x double>*
%5 = load <2 x double>, <2 x double>* %4
%6 = getelementptr inbounds double, double* %1, i64 2
%7 = bitcast double* %6 to <2 x double>*
%8 = load <2 x double>, <2 x double>* %7
%9 = load double, double* %2
%10 = getelementptr inbounds double, double* %2, i64 1
%11 = load double, double* %10
%12 = getelementptr inbounds double, double* %2, i64 2
%13 = load double, double* %12
%14 = getelementptr inbounds double, double* %2, i64 3
%15 = load double, double* %14
%16 = extractelement <2 x double> %5, i64 1
%17 = fneg double %16
%18 = fneg <2 x double> %8
%19 = insertelement <2 x double> %5, double %11, i64 1
%20 = insertelement <2 x double> poison, double %11, i64 0
%21 = insertelement <2 x double> %20, double %17, i64 1
%22 = fmul <2 x double> %19, %21
%23 = shufflevector <2 x double> %22, <2 x double> poison, <2 x i32> <i32 1, i32 0>
%24 = insertelement <2 x double> poison, double %9, i64 0
%25 = shufflevector <2 x double> %24, <2 x double> poison, <2 x i32> zeroinitializer
%26 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %5, <2 x double> %25, <2 x double> %23)
%27 = insertelement <2 x double> poison, double %13, i64 0
%28 = shufflevector <2 x double> %27, <2 x double> poison, <2 x i32> zeroinitializer
%29 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %18, <2 x double> %28, <2 x double> %26)
%30 = shufflevector <2 x double> %18, <2 x double> %8, <2 x i32> <i32 1, i32 2>
%31 = insertelement <2 x double> poison, double %15, 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> %30, <2 x double> %32, <2 x double> %29)
%34 = bitcast double* %0 to <2 x double>*
store <2 x double> %33, <2 x double>* %34
%35 = getelementptr inbounds double, double* %0, i64 2
%36 = shufflevector <2 x double> %8, <2 x double> %18, <2 x i32> <i32 1, i32 2>
%37 = shufflevector <2 x double> %20, <2 x double> poison, <2 x i32> zeroinitializer
%38 = fmul <2 x double> %36, %37
%39 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %8, <2 x double> %25, <2 x double> %38)
%40 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %5, <2 x double> %28, <2 x double> %39)
%41 = insertelement <2 x double> poison, double %17, i64 0
%42 = shufflevector <2 x double> %41, <2 x double> %5, <2 x i32> <i32 0, i32 2>
%43 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %42, <2 x double> %32, <2 x double> %40)
%44 = bitcast double* %35 to <2 x double>*
store <2 x double> %43, <2 x double>* %44
ret void
}