float maths_median_filter_3x(float a, float b, float c) {
  float middle;
  if ((a <= b) && (a <= c)) {
    middle = (b <= c) ? b : c;
  } else if ((b <= a) && (b <= c)) {
    middle = (a <= c) ? a : c;
  } else {
    middle = (a <= b) ? a : b;
  }
  return middle;
}


x86 assembly (clang, -O0):
<maths_median_filter_3x>:
push   %rbp
mov    %rsp,%rbp
movss  %xmm0,-0x4(%rbp)
movss  %xmm1,-0x8(%rbp)
movss  %xmm2,-0xc(%rbp)
movss  -0x4(%rbp),%xmm1
movss  -0x8(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     1174 <maths_median_filter_3x+0x74>
movss  -0x4(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     1174 <maths_median_filter_3x+0x74>
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     115b <maths_median_filter_3x+0x5b>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1165 <maths_median_filter_3x+0x65>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    1210 <maths_median_filter_3x+0x110>
movss  -0x8(%rbp),%xmm1
movss  -0x4(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     11d5 <maths_median_filter_3x+0xd5>
movss  -0x8(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     11d5 <maths_median_filter_3x+0xd5>
movss  -0x4(%rbp),%xmm1
movss  -0xc(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     11bc <maths_median_filter_3x+0xbc>
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    11c6 <maths_median_filter_3x+0xc6>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    120b <maths_median_filter_3x+0x10b>
movss  -0x4(%rbp),%xmm1
movss  -0x8(%rbp),%xmm0
ucomiss %xmm1,%xmm0
jb     11f7 <maths_median_filter_3x+0xf7>
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
jmp    1201 <maths_median_filter_3x+0x101>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    1210 <maths_median_filter_3x+0x110>
movss  -0x10(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<maths_median_filter_3x>:
movaps %xmm0,%xmm3
ucomiss %xmm0,%xmm1
jb     111f <maths_median_filter_3x+0x1f>
ucomiss %xmm3,%xmm2
jb     111f <maths_median_filter_3x+0x1f>
movaps %xmm1,%xmm0
cmpless %xmm2,%xmm0
andps  %xmm0,%xmm1
andnps %xmm2,%xmm0
orps   %xmm1,%xmm0
ret
ucomiss %xmm1,%xmm3
jb     113b <maths_median_filter_3x+0x3b>
ucomiss %xmm1,%xmm2
jb     113b <maths_median_filter_3x+0x3b>
movaps %xmm3,%xmm0
cmpless %xmm2,%xmm0
andps  %xmm0,%xmm3
andnps %xmm2,%xmm0
orps   %xmm3,%xmm0
ret
movaps %xmm3,%xmm0
cmpless %xmm1,%xmm0
andps  %xmm0,%xmm3
andnps %xmm1,%xmm0
orps   %xmm3,%xmm0
ret

LLVM IR (-O0):
define float @maths_median_filter_3x(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
store float %0, float* %4
store float %1, float* %5
store float %2, float* %6
%8 = load float, float* %4
%9 = load float, float* %5
%10 = fcmp ole float %8, %9
br i1 %10, label %11, label %25
11: ; preds = %3
%12 = load float, float* %4
%13 = load float, float* %6
%14 = fcmp ole float %12, %13
br i1 %14, label %15, label %25
15: ; preds = %11
%16 = load float, float* %5
%17 = load float, float* %6
%18 = fcmp ole float %16, %17
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load float, float* %5
br label %23
21: ; preds = %15
%22 = load float, float* %6
br label %23
23: ; preds = %21, %19
%24 = phi float [ %20, %19 ], [ %22, %21 ]
store float %24, float* %7
br label %54
25: ; preds = %11, %3
%26 = load float, float* %5
%27 = load float, float* %4
%28 = fcmp ole float %26, %27
br i1 %28, label %29, label %43
29: ; preds = %25
%30 = load float, float* %5
%31 = load float, float* %6
%32 = fcmp ole float %30, %31
br i1 %32, label %33, label %43
33: ; preds = %29
%34 = load float, float* %4
%35 = load float, float* %6
%36 = fcmp ole float %34, %35
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = load float, float* %4
br label %41
39: ; preds = %33
%40 = load float, float* %6
br label %41
41: ; preds = %39, %37
%42 = phi float [ %38, %37 ], [ %40, %39 ]
store float %42, float* %7
br label %53
43: ; preds = %29, %25
%44 = load float, float* %4
%45 = load float, float* %5
%46 = fcmp ole float %44, %45
br i1 %46, label %47, label %49
47: ; preds = %43
%48 = load float, float* %4
br label %51
49: ; preds = %43
%50 = load float, float* %5
br label %51
51: ; preds = %49, %47
%52 = phi float [ %48, %47 ], [ %50, %49 ]
store float %52, float* %7
br label %53
53: ; preds = %51, %41
br label %54
54: ; preds = %53, %23
%55 = load float, float* %7
ret float %55
}

LLVM IR (-O2):
define float @maths_median_filter_3x(float %0, float %1, float %2) {
%4 = fcmp ole float %0, %1
%5 = fcmp ole float %0, %2
%6 = and i1 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %3
%8 = fcmp ole float %1, %2
%9 = select i1 %8, float %1, float %2
br label %18
10: ; preds = %3
%11 = fcmp ugt float %1, %0
%12 = fcmp ugt float %1, %2
%13 = or i1 %11, %12
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = select i1 %5, float %0, float %2
br label %18
16: ; preds = %10
%17 = select i1 %4, float %0, float %1
br label %18
18: ; preds = %14, %16, %7
%19 = phi float [ %9, %7 ], [ %15, %14 ], [ %17, %16 ]
ret float %19
}