int hb_layout_to_mode(int layout) {
  int mode;
  switch (layout & 0xFFFF0FF) {
  case 0x0110010:
    mode = 0;
    break;
  case 0x0220020:
    mode = 1;
    break;
  case 0x0430030:
    mode = 2;
    break;
  case 0x0521021:
    mode = 3;
    break;
  case 0x0631031:
    mode = 4;
    break;
  case 0x0722022:
    mode = 5;
    break;
  case 0x0832032:
    mode = 6;
    break;
  case 0x0942042:
    mode = 6 | 0x10;
    break;
  case 0x0a34034:
    mode = 7;
    break;
  case 0x0320031:
    mode = 1;
    break;
  default:
    mode = 1;
    break;
  }
  if (layout & 0x0000F00)
    mode |= 0x10;
  return mode;
}


x86 assembly (clang, -O0):
<hb_layout_to_mode>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
and    $0xffff0ff,%eax
mov    %eax,-0xc(%rbp)
sub    $0x110010,%eax
je     11cd <hb_layout_to_mode+0xcd>
jmp    1122 <hb_layout_to_mode+0x22>
mov    -0xc(%rbp),%eax
sub    $0x220020,%eax
je     11d9 <hb_layout_to_mode+0xd9>
jmp    1135 <hb_layout_to_mode+0x35>
mov    -0xc(%rbp),%eax
sub    $0x320031,%eax
je     1239 <hb_layout_to_mode+0x139>
jmp    1148 <hb_layout_to_mode+0x48>
mov    -0xc(%rbp),%eax
sub    $0x430030,%eax
je     11e5 <hb_layout_to_mode+0xe5>
jmp    115b <hb_layout_to_mode+0x5b>
mov    -0xc(%rbp),%eax
sub    $0x521021,%eax
je     11f1 <hb_layout_to_mode+0xf1>
jmp    116e <hb_layout_to_mode+0x6e>
mov    -0xc(%rbp),%eax
sub    $0x631031,%eax
je     11fd <hb_layout_to_mode+0xfd>
jmp    1181 <hb_layout_to_mode+0x81>
mov    -0xc(%rbp),%eax
sub    $0x722022,%eax
je     1209 <hb_layout_to_mode+0x109>
jmp    1194 <hb_layout_to_mode+0x94>
mov    -0xc(%rbp),%eax
sub    $0x832032,%eax
je     1215 <hb_layout_to_mode+0x115>
jmp    11a7 <hb_layout_to_mode+0xa7>
mov    -0xc(%rbp),%eax
sub    $0x942042,%eax
je     1221 <hb_layout_to_mode+0x121>
jmp    11ba <hb_layout_to_mode+0xba>
mov    -0xc(%rbp),%eax
sub    $0xa34034,%eax
je     122d <hb_layout_to_mode+0x12d>
jmp    1245 <hb_layout_to_mode+0x145>
movl   $0x0,-0x8(%rbp)
jmp    124c <hb_layout_to_mode+0x14c>
movl   $0x1,-0x8(%rbp)
jmp    124c <hb_layout_to_mode+0x14c>
movl   $0x2,-0x8(%rbp)
jmp    124c <hb_layout_to_mode+0x14c>
movl   $0x3,-0x8(%rbp)
jmp    124c <hb_layout_to_mode+0x14c>
movl   $0x4,-0x8(%rbp)
jmp    124c <hb_layout_to_mode+0x14c>
movl   $0x5,-0x8(%rbp)
jmp    124c <hb_layout_to_mode+0x14c>
movl   $0x6,-0x8(%rbp)
jmp    124c <hb_layout_to_mode+0x14c>
movl   $0x16,-0x8(%rbp)
jmp    124c <hb_layout_to_mode+0x14c>
movl   $0x7,-0x8(%rbp)
jmp    124c <hb_layout_to_mode+0x14c>
movl   $0x1,-0x8(%rbp)
jmp    124c <hb_layout_to_mode+0x14c>
movl   $0x1,-0x8(%rbp)
mov    -0x4(%rbp),%eax
and    $0xf00,%eax
cmp    $0x0,%eax
je     1266 <hb_layout_to_mode+0x166>
mov    -0x8(%rbp),%eax
or     $0x10,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hb_layout_to_mode>:
mov    %edi,%eax
and    $0xffff0ff,%eax
cmp    $0x631030,%eax
jg     1131 <hb_layout_to_mode+0x31>
cmp    $0x320030,%eax
jle    1154 <hb_layout_to_mode+0x54>
cmp    $0x320031,%eax
je     1162 <hb_layout_to_mode+0x62>
cmp    $0x430030,%eax
je     117e <hb_layout_to_mode+0x7e>
cmp    $0x521021,%eax
jne    1162 <hb_layout_to_mode+0x62>
mov    $0x3,%ecx
jmp    1198 <hb_layout_to_mode+0x98>
cmp    $0x832031,%eax
jle    1169 <hb_layout_to_mode+0x69>
cmp    $0x832032,%eax
je     1185 <hb_layout_to_mode+0x85>
cmp    $0x942042,%eax
je     118c <hb_layout_to_mode+0x8c>
cmp    $0xa34034,%eax
jne    1162 <hb_layout_to_mode+0x62>
mov    $0x7,%ecx
jmp    1198 <hb_layout_to_mode+0x98>
xor    %ecx,%ecx
cmp    $0x110010,%eax
je     1198 <hb_layout_to_mode+0x98>
cmp    $0x220020,%eax
mov    $0x1,%ecx
jmp    1198 <hb_layout_to_mode+0x98>
cmp    $0x631031,%eax
je     1193 <hb_layout_to_mode+0x93>
cmp    $0x722022,%eax
jne    1162 <hb_layout_to_mode+0x62>
mov    $0x5,%ecx
jmp    1198 <hb_layout_to_mode+0x98>
mov    $0x2,%ecx
jmp    1198 <hb_layout_to_mode+0x98>
mov    $0x6,%ecx
jmp    1198 <hb_layout_to_mode+0x98>
mov    $0x16,%ecx
jmp    1198 <hb_layout_to_mode+0x98>
mov    $0x4,%ecx
mov    %ecx,%eax
or     $0x10,%eax
test   $0xf00,%edi
cmove  %ecx,%eax
ret

LLVM IR (-O0):
define i32 @hb_layout_to_mode(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = and i32 %4, 268431615
switch i32 %5, label %16 [
i32 1114128, label %6
i32 2228256, label %7
i32 4390960, label %8
i32 5378081, label %9
i32 6492209, label %10
i32 7479330, label %11
i32 8593458, label %12
i32 9707586, label %13
i32 10698804, label %14
i32 3276849, label %15
]
6: ; preds = %1
store i32 0, i32* %3
br label %17
7: ; preds = %1
store i32 1, i32* %3
br label %17
8: ; preds = %1
store i32 2, i32* %3
br label %17
9: ; preds = %1
store i32 3, i32* %3
br label %17
10: ; preds = %1
store i32 4, i32* %3
br label %17
11: ; preds = %1
store i32 5, i32* %3
br label %17
12: ; preds = %1
store i32 6, i32* %3
br label %17
13: ; preds = %1
store i32 22, i32* %3
br label %17
14: ; preds = %1
store i32 7, i32* %3
br label %17
15: ; preds = %1
store i32 1, i32* %3
br label %17
16: ; preds = %1
store i32 1, i32* %3
br label %17
17: ; preds = %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6
%18 = load i32, i32* %2
%19 = and i32 %18, 3840
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %3
%23 = or i32 %22, 16
store i32 %23, i32* %3
br label %24
24: ; preds = %21, %17
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
define i32 @hb_layout_to_mode(i32 %0) {
%2 = and i32 %0, 268431615
switch i32 %2, label %12 [
i32 1114128, label %13
i32 2228256, label %3
i32 4390960, label %4
i32 5378081, label %5
i32 6492209, label %6
i32 7479330, label %7
i32 8593458, label %8
i32 9707586, label %9
i32 10698804, label %10
i32 3276849, label %11
]
3: ; preds = %1
br label %13
4: ; preds = %1
br label %13
5: ; preds = %1
br label %13
6: ; preds = %1
br label %13
7: ; preds = %1
br label %13
8: ; preds = %1
br label %13
9: ; preds = %1
br label %13
10: ; preds = %1
br label %13
11: ; preds = %1
br label %13
12: ; preds = %1
br label %13
13: ; preds = %1, %12, %11, %10, %9, %8, %7, %6, %5, %4, %3
%14 = phi i32 [ 1, %12 ], [ 1, %11 ], [ 7, %10 ], [ 22, %9 ], [ 6, %8 ], [ 5, %7 ], [ 4, %6 ], [ 3, %5 ], [ 2, %4 ], [ 1, %3 ], [ 0, %1 ]
%15 = and i32 %0, 3840
%16 = icmp eq i32 %15, 0
%17 = or i32 %14, 16
%18 = select i1 %16, i32 %14, i32 %17
ret i32 %18
}