unsigned char me_decode16(unsigned short m) {
  unsigned char i, c;
  c = 0;
  for (i = 0; i < 8; i++) {
    c <<= 1;
    c |= (m & 0xc000) == 0x8000;
    m <<= 2;
  }
  return c;
}


x86 assembly (clang, -O0):
<me_decode16>:
push   %rbp
mov    %rsp,%rbp
mov    %di,%ax
mov    %ax,-0x2(%rbp)
movb   $0x0,-0x4(%rbp)
movb   $0x0,-0x3(%rbp)
movzbl -0x3(%rbp),%eax
cmp    $0x8,%eax
jge    1161 <me_decode16+0x61>
movzbl -0x4(%rbp),%eax
shl    $0x1,%eax
mov    %al,-0x4(%rbp)
movzwl -0x2(%rbp),%eax
and    $0xc000,%eax
cmp    $0x8000,%eax
sete   %al
and    $0x1,%al
movzbl %al,%ecx
movzbl -0x4(%rbp),%eax
or     %ecx,%eax
mov    %al,-0x4(%rbp)
movzwl -0x2(%rbp),%eax
shl    $0x2,%eax
mov    %ax,-0x2(%rbp)
mov    -0x3(%rbp),%al
add    $0x1,%al
mov    %al,-0x3(%rbp)
jmp    1113 <me_decode16+0x13>
movzbl -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<me_decode16>:
movd   %edi,%xmm0
pshuflw $0x0,%xmm0,%xmm0
pshufd $0x0,%xmm0,%xmm0
pand   0xeea(%rip),%xmm0
pcmpeqw 0xef2(%rip),%xmm0
packsswb %xmm0,%xmm0
pmovmskb %xmm0,%eax
mov    %eax,%esi
and    $0x2,%sil
mov    %eax,%edi
and    $0x4,%dil
shr    $0x2,%dil
mov    %eax,%r10d
and    $0x8,%r10b
mov    %eax,%r8d
and    $0x10,%r8b
shr    $0x4,%r8b
mov    %eax,%ecx
and    $0x20,%cl
mov    %eax,%r9d
and    $0x40,%r9b
shr    $0x6,%r9b
mov    %eax,%edx
shr    $0x6,%dl
and    $0x2,%dl
or     %r9b,%dl
shl    $0x2,%dl
shr    $0x4,%cl
or     %dl,%cl
or     %r8b,%cl
shl    $0x2,%cl
shr    $0x2,%r10b
or     %cl,%r10b
or     %dil,%r10b
shl    $0x2,%r10b
or     %sil,%r10b
and    $0x1,%al
or     %r10b,%al
ret

LLVM IR (-O0):
define zeroext i8 @me_decode16(i16 zeroext %0) {
%2 = alloca i16
%3 = alloca i8
%4 = alloca i8
store i16 %0, i16* %2
store i8 0, i8* %4
store i8 0, i8* %3
br label %5
5: ; preds = %27, %1
%6 = load i8, i8* %3
%7 = zext i8 %6 to i32
%8 = icmp slt i32 %7, 8
br i1 %8, label %9, label %30
9: ; preds = %5
%10 = load i8, i8* %4
%11 = zext i8 %10 to i32
%12 = shl i32 %11, 1
%13 = trunc i32 %12 to i8
store i8 %13, i8* %4
%14 = load i16, i16* %2
%15 = zext i16 %14 to i32
%16 = and i32 %15, 49152
%17 = icmp eq i32 %16, 32768
%18 = zext i1 %17 to i32
%19 = load i8, i8* %4
%20 = zext i8 %19 to i32
%21 = or i32 %20, %18
%22 = trunc i32 %21 to i8
store i8 %22, i8* %4
%23 = load i16, i16* %2
%24 = zext i16 %23 to i32
%25 = shl i32 %24, 2
%26 = trunc i32 %25 to i16
store i16 %26, i16* %2
br label %27
27: ; preds = %9
%28 = load i8, i8* %3
%29 = add i8 %28, 1
store i8 %29, i8* %3
br label %5
30: ; preds = %5
%31 = load i8, i8* %4
ret i8 %31
}

LLVM IR (-O2):
define zeroext i8 @me_decode16(i16 zeroext %0) {
%2 = insertelement <8 x i16> poison, i16 %0, i64 0
%3 = shufflevector <8 x i16> %2, <8 x i16> poison, <8 x i32> zeroinitializer
%4 = and <8 x i16> %3, <i16 3, i16 12, i16 48, i16 192, i16 768, i16 3072, i16 12288, i16 -16384>
%5 = icmp eq <8 x i16> %4, <i16 2, i16 8, i16 32, i16 128, i16 512, i16 2048, i16 8192, i16 -32768>
%6 = extractelement <8 x i1> %5, i64 7
%7 = select i1 %6, i8 2, i8 0
%8 = extractelement <8 x i1> %5, i64 6
%9 = zext i1 %8 to i8
%10 = or i8 %7, %9
%11 = shl nuw nsw i8 %10, 2
%12 = extractelement <8 x i1> %5, i64 5
%13 = select i1 %12, i8 2, i8 0
%14 = or i8 %11, %13
%15 = extractelement <8 x i1> %5, i64 4
%16 = zext i1 %15 to i8
%17 = or i8 %14, %16
%18 = shl nuw nsw i8 %17, 2
%19 = extractelement <8 x i1> %5, i64 3
%20 = select i1 %19, i8 2, i8 0
%21 = or i8 %18, %20
%22 = extractelement <8 x i1> %5, i64 2
%23 = zext i1 %22 to i8
%24 = or i8 %21, %23
%25 = shl i8 %24, 2
%26 = extractelement <8 x i1> %5, i64 1
%27 = select i1 %26, i8 2, i8 0
%28 = or i8 %25, %27
%29 = extractelement <8 x i1> %5, i64 0
%30 = zext i1 %29 to i8
%31 = or i8 %28, %30
ret i8 %31
}