unsigned char single_bmap_unit(unsigned int bitmap) {
  unsigned int invmap[] = {6, 14, 2, 10, 1, 9, 5, 13,
                           7, 15, 3, 11, 0, 8, 4, 12};
  unsigned int mask = 1;
  unsigned char units[17], nunits;
  int j;
  nunits = 0;
  units[0] = 0;
  for (j = 0; j < 16; j++) {
    mask = 0x01 << invmap[j];
    if (bitmap & mask) {
      units[nunits++] = invmap[j];
    }
  }
  return (nunits <= 1) ? units[0] : 0xff;
}


x86 assembly (clang, -O0):
<single_bmap_unit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xed7(%rip),%rsi
mov    $0x40,%edx
call   1030 <memcpy@plt>
movl   $0x1,-0x54(%rbp)
movb   $0x0,-0x71(%rbp)
movb   $0x0,-0x70(%rbp)
movl   $0x0,-0x78(%rbp)
cmpl   $0x10,-0x78(%rbp)
jge    11a3 <single_bmap_unit+0x93>
movslq -0x78(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%ecx
mov    $0x1,%eax
shl    %cl,%eax
mov    %eax,-0x54(%rbp)
mov    -0x4(%rbp),%eax
and    -0x54(%rbp),%eax
cmp    $0x0,%eax
je     1190 <single_bmap_unit+0x80>
movslq -0x78(%rbp),%rax
mov    -0x50(%rbp,%rax,4),%eax
mov    %al,%cl
mov    -0x71(%rbp),%al
mov    %al,%dl
add    $0x1,%dl
mov    %dl,-0x71(%rbp)
movzbl %al,%eax
mov    %cl,-0x70(%rbp,%rax,1)
jmp    1195 <single_bmap_unit+0x85>
mov    -0x78(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x78(%rbp)
jmp    1149 <single_bmap_unit+0x39>
movzbl -0x71(%rbp),%eax
cmp    $0x1,%eax
jg     11bc <single_bmap_unit+0xac>
movzbl -0x70(%rbp),%eax
mov    %eax,-0x7c(%rbp)
jmp    11c9 <single_bmap_unit+0xb9>
mov    $0xff,%eax
mov    %eax,-0x7c(%rbp)
jmp    11c9 <single_bmap_unit+0xb9>
mov    -0x7c(%rbp),%eax
movzbl %al,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<single_bmap_unit>:
movb   $0x0,-0x18(%rsp)
xor    %eax,%eax
lea    0xef2(%rip),%r8
xor    %ecx,%ecx
jmp    112a <single_bmap_unit+0x2a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x2,%rax
cmp    $0x10,%rax
je     1155 <single_bmap_unit+0x55>
mov    (%r8,%rax,4),%esi
bt     %esi,%edi
jae    113e <single_bmap_unit+0x3e>
movzbl %cl,%edx
add    $0x1,%cl
mov    %sil,-0x18(%rsp,%rdx,1)
mov    0x4(%r8,%rax,4),%esi
bt     %esi,%edi
jae    1120 <single_bmap_unit+0x20>
movzbl %cl,%edx
add    $0x1,%cl
mov    %sil,-0x18(%rsp,%rdx,1)
jmp    1120 <single_bmap_unit+0x20>
mov    $0xff,%eax
cmp    $0x2,%cl
jae    1163 <single_bmap_unit+0x63>
mov    -0x18(%rsp),%eax
ret

LLVM IR (-O0):
@__const.single_bmap_unit.invmap = [16 x i32] [i32 6, i32 14, i32 2, i32 10, i32 1, i32 9, i32 5, i32 13, i32 7, i32 15, i32 3, i32 11, i32 0, i32 8, i32 4, i32 12]
define zeroext i8 @single_bmap_unit(i32 %0) {
%2 = alloca i32
%3 = alloca [16 x i32]
%4 = alloca i32
%5 = alloca [17 x i8]
%6 = alloca i8
%7 = alloca i32
store i32 %0, i32* %2
%8 = bitcast [16 x i32]* %3 to i8*
store i32 1, i32* %4
store i8 0, i8* %6
%9 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
store i8 0, i8* %9
store i32 0, i32* %7
br label %10
10: ; preds = %34, %1
%11 = load i32, i32* %7
%12 = icmp slt i32 %11, 16
br i1 %12, label %13, label %37
13: ; preds = %10
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = shl i32 1, %17
store i32 %18, i32* %4
%19 = load i32, i32* %2
%20 = load i32, i32* %4
%21 = and i32 %19, %20
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %33
23: ; preds = %13
%24 = load i32, i32* %7
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [16 x i32], [16 x i32]* %3, i64 0, i64 %25
%27 = load i32, i32* %26
%28 = trunc i32 %27 to i8
%29 = load i8, i8* %6
%30 = add i8 %29, 1
store i8 %30, i8* %6
%31 = zext i8 %29 to i64
%32 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 %31
store i8 %28, i8* %32
br label %33
33: ; preds = %23, %13
br label %34
34: ; preds = %33
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
store i32 %36, i32* %7
br label %10
37: ; preds = %10
%38 = load i8, i8* %6
%39 = zext i8 %38 to i32
%40 = icmp sle i32 %39, 1
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = getelementptr inbounds [17 x i8], [17 x i8]* %5, i64 0, i64 0
%43 = load i8, i8* %42
%44 = zext i8 %43 to i32
br label %46
45: ; preds = %37
br label %46
46: ; preds = %45, %41
%47 = phi i32 [ %44, %41 ], [ 255, %45 ]
%48 = trunc i32 %47 to i8
ret i8 %48
}

LLVM IR (-O2):
@__const.single_bmap_unit.invmap = [16 x i32] [i32 6, i32 14, i32 2, i32 10, i32 1, i32 9, i32 5, i32 13, i32 7, i32 15, i32 3, i32 11, i32 0, i32 8, i32 4, i32 12]
define zeroext i8 @single_bmap_unit(i32 %0) {
%2 = alloca [17 x i8]
%3 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 0
store i8 0, i8* %3
br label %4
4: ; preds = %30, %1
%5 = phi i64 [ 0, %1 ], [ %32, %30 ]
%6 = phi i8 [ 0, %1 ], [ %31, %30 ]
%7 = getelementptr inbounds [16 x i32], [16 x i32]* @__const.single_bmap_unit.invmap, i64 0, i64 %5
%8 = load i32, i32* %7
%9 = shl nuw i32 1, %8
%10 = and i32 %9, %0
%11 = icmp eq i32 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %4
%13 = trunc i32 %8 to i8
%14 = add i8 %6, 1
%15 = zext i8 %6 to i64
%16 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 %15
store i8 %13, i8* %16
br label %17
17: ; preds = %4, %12
%18 = phi i8 [ %14, %12 ], [ %6, %4 ]
%19 = or i64 %5, 1
%20 = getelementptr inbounds [16 x i32], [16 x i32]* @__const.single_bmap_unit.invmap, i64 0, i64 %19
%21 = load i32, i32* %20
%22 = shl nuw i32 1, %21
%23 = and i32 %22, %0
%24 = icmp eq i32 %23, 0
br i1 %24, label %30, label %25
25: ; preds = %17
%26 = trunc i32 %21 to i8
%27 = add i8 %18, 1
%28 = zext i8 %18 to i64
%29 = getelementptr inbounds [17 x i8], [17 x i8]* %2, i64 0, i64 %28
store i8 %26, i8* %29
br label %30
30: ; preds = %25, %17
%31 = phi i8 [ %27, %25 ], [ %18, %17 ]
%32 = add nuw nsw i64 %5, 2
%33 = icmp eq i64 %32, 16
br i1 %33, label %34, label %4
34: ; preds = %30
%35 = icmp ult i8 %31, 2
%36 = load i8, i8* %3
%37 = select i1 %35, i8 %36, i8 -1
ret i8 %37
}