double sobel(double ul, double um, double ur, double ml, double mr, double ll,
             double lm, double lr, double fscale) {
  double T1 = ur + 2 * mr + lr - ul - 2 * ml - ll;
  double T2 = ul + 2 * um + ur - ll - 2 * lm - lr;
  return fscale * (T1 + T2);
}


x86 assembly (clang, -O0):
<sobel>:
push   %rbp
mov    %rsp,%rbp
movsd  0x10(%rbp),%xmm8
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
movsd  %xmm3,-0x20(%rbp)
movsd  %xmm4,-0x28(%rbp)
movsd  %xmm5,-0x30(%rbp)
movsd  %xmm6,-0x38(%rbp)
movsd  %xmm7,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x40(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
addsd  %xmm0,%xmm0
addsd  %xmm1,%xmm0
addsd  -0x18(%rbp),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
addsd  %xmm1,%xmm1
subsd  %xmm1,%xmm0
subsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0x10(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
addsd  -0x50(%rbp),%xmm1
mulsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<sobel>:
unpcklpd %xmm4,%xmm1
movapd %xmm5,%xmm4
unpcklpd %xmm0,%xmm4
unpcklpd %xmm2,%xmm0
addpd  %xmm1,%xmm1
addpd  %xmm1,%xmm0
unpcklpd %xmm7,%xmm2
addpd  %xmm2,%xmm0
subpd  %xmm4,%xmm0
unpcklpd %xmm3,%xmm6
addpd  %xmm6,%xmm6
subpd  %xmm6,%xmm0
unpcklpd %xmm5,%xmm7
subpd  %xmm7,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
addsd  %xmm1,%xmm0
mulsd  0x8(%rsp),%xmm0
ret

LLVM IR (-O0):
define double @sobel(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7, double %8) {
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = alloca double
%14 = alloca double
%15 = alloca double
%16 = alloca double
%17 = alloca double
%18 = alloca double
%19 = alloca double
%20 = alloca double
store double %0, double* %10
store double %1, double* %11
store double %2, double* %12
store double %3, double* %13
store double %4, double* %14
store double %5, double* %15
store double %6, double* %16
store double %7, double* %17
store double %8, double* %18
%21 = load double, double* %12
%22 = load double, double* %14
%23 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %22, double %21)
%24 = load double, double* %17
%25 = fadd double %23, %24
%26 = load double, double* %10
%27 = fsub double %25, %26
%28 = load double, double* %13
%29 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %28, double %27)
%30 = load double, double* %15
%31 = fsub double %29, %30
store double %31, double* %19
%32 = load double, double* %10
%33 = load double, double* %11
%34 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %33, double %32)
%35 = load double, double* %12
%36 = fadd double %34, %35
%37 = load double, double* %15
%38 = fsub double %36, %37
%39 = load double, double* %16
%40 = call double @llvm.fmuladd.f64(double -2.000000e+00, double %39, double %38)
%41 = load double, double* %17
%42 = fsub double %40, %41
store double %42, double* %20
%43 = load double, double* %18
%44 = load double, double* %19
%45 = load double, double* %20
%46 = fadd double %44, %45
%47 = fmul double %43, %46
ret double %47
}

LLVM IR (-O2):
define double @sobel(double %0, double %1, double %2, double %3, double %4, double %5, double %6, double %7, double %8) {
%10 = insertelement <2 x double> poison, double %1, i64 0
%11 = insertelement <2 x double> %10, double %4, i64 1
%12 = insertelement <2 x double> poison, double %0, i64 0
%13 = insertelement <2 x double> %12, double %2, i64 1
%14 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %11, <2 x double> <double 2.000000e+00, double 2.000000e+00>, <2 x double> %13)
%15 = insertelement <2 x double> poison, double %2, i64 0
%16 = insertelement <2 x double> %15, double %7, i64 1
%17 = fadd <2 x double> %14, %16
%18 = insertelement <2 x double> poison, double %5, i64 0
%19 = insertelement <2 x double> %18, double %0, i64 1
%20 = fsub <2 x double> %17, %19
%21 = insertelement <2 x double> poison, double %6, i64 0
%22 = insertelement <2 x double> %21, double %3, i64 1
%23 = call <2 x double> @llvm.fmuladd.v2f64(<2 x double> %22, <2 x double> <double -2.000000e+00, double -2.000000e+00>, <2 x double> %20)
%24 = insertelement <2 x double> poison, double %7, i64 0
%25 = insertelement <2 x double> %24, double %5, i64 1
%26 = fsub <2 x double> %23, %25
%27 = shufflevector <2 x double> %26, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%28 = fadd <2 x double> %26, %27
%29 = extractelement <2 x double> %28, i64 0
%30 = fmul double %29, %8
ret double %30
}