unsigned mpn_base_power_of_two_p(unsigned b) {
  switch (b) {
  case 2:
    return 1;
  case 4:
    return 2;
  case 8:
    return 3;
  case 16:
    return 4;
  case 32:
    return 5;
  case 64:
    return 6;
  case 128:
    return 7;
  case 256:
    return 8;
  default:
    return 0;
  }
}


x86 assembly (clang, -O0):
<mpn_base_power_of_two_p>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
sub    $0x2,%eax
je     1196 <mpn_base_power_of_two_p+0x96>
jmp    111b <mpn_base_power_of_two_p+0x1b>
mov    -0xc(%rbp),%eax
sub    $0x4,%eax
je     11a2 <mpn_base_power_of_two_p+0xa2>
jmp    112c <mpn_base_power_of_two_p+0x2c>
mov    -0xc(%rbp),%eax
sub    $0x8,%eax
je     11ae <mpn_base_power_of_two_p+0xae>
jmp    113d <mpn_base_power_of_two_p+0x3d>
mov    -0xc(%rbp),%eax
sub    $0x10,%eax
je     11ba <mpn_base_power_of_two_p+0xba>
jmp    114e <mpn_base_power_of_two_p+0x4e>
mov    -0xc(%rbp),%eax
sub    $0x20,%eax
je     11c6 <mpn_base_power_of_two_p+0xc6>
jmp    115f <mpn_base_power_of_two_p+0x5f>
mov    -0xc(%rbp),%eax
sub    $0x40,%eax
je     11d2 <mpn_base_power_of_two_p+0xd2>
jmp    1170 <mpn_base_power_of_two_p+0x70>
mov    -0xc(%rbp),%eax
sub    $0x80,%eax
je     11de <mpn_base_power_of_two_p+0xde>
jmp    1183 <mpn_base_power_of_two_p+0x83>
mov    -0xc(%rbp),%eax
sub    $0x100,%eax
je     11ea <mpn_base_power_of_two_p+0xea>
jmp    11f6 <mpn_base_power_of_two_p+0xf6>
movl   $0x1,-0x4(%rbp)
jmp    11fd <mpn_base_power_of_two_p+0xfd>
movl   $0x2,-0x4(%rbp)
jmp    11fd <mpn_base_power_of_two_p+0xfd>
movl   $0x3,-0x4(%rbp)
jmp    11fd <mpn_base_power_of_two_p+0xfd>
movl   $0x4,-0x4(%rbp)
jmp    11fd <mpn_base_power_of_two_p+0xfd>
movl   $0x5,-0x4(%rbp)
jmp    11fd <mpn_base_power_of_two_p+0xfd>
movl   $0x6,-0x4(%rbp)
jmp    11fd <mpn_base_power_of_two_p+0xfd>
movl   $0x7,-0x4(%rbp)
jmp    11fd <mpn_base_power_of_two_p+0xfd>
movl   $0x8,-0x4(%rbp)
jmp    11fd <mpn_base_power_of_two_p+0xfd>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<mpn_base_power_of_two_p>:
cmp    $0x3f,%edi
jg     1128 <mpn_base_power_of_two_p+0x28>
add    $0xfffffffe,%edi
cmp    $0x1e,%edi
ja     1161 <mpn_base_power_of_two_p+0x61>
mov    $0x1,%eax
lea    0xee7(%rip),%rcx
movslq (%rcx,%rdi,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
mov    $0x2,%eax
ret
cmp    $0x40,%edi
je     1155 <mpn_base_power_of_two_p+0x55>
cmp    $0x80,%edi
je     115b <mpn_base_power_of_two_p+0x5b>
cmp    $0x100,%edi
jne    1161 <mpn_base_power_of_two_p+0x61>
mov    $0x8,%eax
ret
mov    $0x3,%eax
ret
mov    $0x4,%eax
ret
mov    $0x5,%eax
ret
mov    $0x6,%eax
ret
mov    $0x7,%eax
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define i32 @mpn_base_power_of_two_p(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %13 [
i32 2, label %5
i32 4, label %6
i32 8, label %7
i32 16, label %8
i32 32, label %9
i32 64, label %10
i32 128, label %11
i32 256, label %12
]
5: ; preds = %1
store i32 1, i32* %2
br label %14
6: ; preds = %1
store i32 2, i32* %2
br label %14
7: ; preds = %1
store i32 3, i32* %2
br label %14
8: ; preds = %1
store i32 4, i32* %2
br label %14
9: ; preds = %1
store i32 5, i32* %2
br label %14
10: ; preds = %1
store i32 6, i32* %2
br label %14
11: ; preds = %1
store i32 7, i32* %2
br label %14
12: ; preds = %1
store i32 8, i32* %2
br label %14
13: ; preds = %1
store i32 0, i32* %2
br label %14
14: ; preds = %13, %12, %11, %10, %9, %8, %7, %6, %5
%15 = load i32, i32* %2
ret i32 %15
}

LLVM IR (-O2):
define i32 @mpn_base_power_of_two_p(i32 %0) {
switch i32 %0, label %9 [
i32 2, label %10
i32 4, label %2
i32 8, label %3
i32 16, label %4
i32 32, label %5
i32 64, label %6
i32 128, label %7
i32 256, label %8
]
2: ; preds = %1
br label %10
3: ; preds = %1
br label %10
4: ; preds = %1
br label %10
5: ; preds = %1
br label %10
6: ; preds = %1
br label %10
7: ; preds = %1
br label %10
8: ; preds = %1
br label %10
9: ; preds = %1
br label %10
10: ; preds = %1, %9, %8, %7, %6, %5, %4, %3, %2
%11 = phi i32 [ 0, %9 ], [ 8, %8 ], [ 7, %7 ], [ 6, %6 ], [ 5, %5 ], [ 4, %4 ], [ 3, %3 ], [ 2, %2 ], [ 1, %1 ]
ret i32 %11
}