unsigned int piece_value(unsigned int piece) {
  if (0) {
  } else if ((piece & 7) == 1)
    return 1;
  else if ((piece & 7) == 2)
    return 4;
  else if ((piece & 7) == 3)
    return 2;
  else if ((piece & 7) == 4)
    return 4;
  else if ((piece & 7) == 5)
    return 8;
  else if ((piece & 7) == 6)
    return 12;
  return 0;
}


x86 assembly (clang, -O0):
<piece_value>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x1,%eax
jne    1122 <piece_value+0x22>
movl   $0x1,-0x4(%rbp)
jmp    11c9 <piece_value+0xc9>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x2,%eax
jne    113d <piece_value+0x3d>
movl   $0x4,-0x4(%rbp)
jmp    11c9 <piece_value+0xc9>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x3,%eax
jne    1158 <piece_value+0x58>
movl   $0x2,-0x4(%rbp)
jmp    11c9 <piece_value+0xc9>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x4,%eax
jne    1173 <piece_value+0x73>
movl   $0x4,-0x4(%rbp)
jmp    11c9 <piece_value+0xc9>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x5,%eax
jne    118e <piece_value+0x8e>
movl   $0x8,-0x4(%rbp)
jmp    11c9 <piece_value+0xc9>
mov    -0x8(%rbp),%eax
and    $0x7,%eax
cmp    $0x6,%eax
jne    11a9 <piece_value+0xa9>
movl   $0xc,-0x4(%rbp)
jmp    11c9 <piece_value+0xc9>
jmp    11ae <piece_value+0xae>
jmp    11b3 <piece_value+0xb3>
jmp    11b8 <piece_value+0xb8>
jmp    11bd <piece_value+0xbd>
jmp    11c2 <piece_value+0xc2>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<piece_value>:
and    $0x7,%edi
add    $0xffffffff,%edi
xor    %eax,%eax
cmp    $0x5,%edi
ja     111a <piece_value+0x1a>
movslq %edi,%rax
lea    0xee9(%rip),%rcx
mov    (%rcx,%rax,4),%eax
ret

LLVM IR (-O0):
define i32 @piece_value(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = and i32 %4, 7
%6 = icmp eq i32 %5, 1
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 1, i32* %2
br label %39
8: ; preds = %1
%9 = load i32, i32* %3
%10 = and i32 %9, 7
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 4, i32* %2
br label %39
13: ; preds = %8
%14 = load i32, i32* %3
%15 = and i32 %14, 7
%16 = icmp eq i32 %15, 3
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 2, i32* %2
br label %39
18: ; preds = %13
%19 = load i32, i32* %3
%20 = and i32 %19, 7
%21 = icmp eq i32 %20, 4
br i1 %21, label %22, label %23
22: ; preds = %18
store i32 4, i32* %2
br label %39
23: ; preds = %18
%24 = load i32, i32* %3
%25 = and i32 %24, 7
%26 = icmp eq i32 %25, 5
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 8, i32* %2
br label %39
28: ; preds = %23
%29 = load i32, i32* %3
%30 = and i32 %29, 7
%31 = icmp eq i32 %30, 6
br i1 %31, label %32, label %33
32: ; preds = %28
store i32 12, i32* %2
br label %39
33: ; preds = %28
br label %34
34: ; preds = %33
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
br label %37
37: ; preds = %36
br label %38
38: ; preds = %37
store i32 0, i32* %2
br label %39
39: ; preds = %38, %32, %27, %22, %17, %12, %7
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
@switch.table.piece_value = [6 x i32] [i32 1, i32 4, i32 2, i32 4, i32 8, i32 12]
define i32 @piece_value(i32 %0) {
%2 = and i32 %0, 7
%3 = add nsw i32 %2, -1
%4 = icmp ult i32 %3, 6
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds [6 x i32], [6 x i32]* @switch.table.piece_value, i64 0, i64 %6
%8 = load i32, i32* %7
br label %9
9: ; preds = %1, %5
%10 = phi i32 [ %8, %5 ], [ 0, %1 ]
ret i32 %10
}