char card2val(char card) {
  if (card >= '2' && card <= '9')
    return card - '2';
  if (card == 'T')
    return 8;
  if (card == 'J')
    return 9;
  if (card == 'Q')
    return 10;
  if (card == 'K')
    return 11;
  if (card == 'A')
    return 12;
  return -1;
}


x86 assembly (clang, -O0):
<card2val>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movsbl -0x2(%rbp),%eax
cmp    $0x32,%eax
jl     1133 <card2val+0x33>
movsbl -0x2(%rbp),%eax
cmp    $0x39,%eax
jg     1133 <card2val+0x33>
movsbl -0x2(%rbp),%eax
sub    $0x32,%eax
mov    %al,-0x1(%rbp)
jmp    11a5 <card2val+0xa5>
movsbl -0x2(%rbp),%eax
cmp    $0x54,%eax
jne    1149 <card2val+0x49>
movb   $0x8,-0x1(%rbp)
jmp    11a5 <card2val+0xa5>
movsbl -0x2(%rbp),%eax
cmp    $0x4a,%eax
jne    115f <card2val+0x5f>
movb   $0x9,-0x1(%rbp)
jmp    11a5 <card2val+0xa5>
movsbl -0x2(%rbp),%eax
cmp    $0x51,%eax
jne    1175 <card2val+0x75>
movb   $0xa,-0x1(%rbp)
jmp    11a5 <card2val+0xa5>
movsbl -0x2(%rbp),%eax
cmp    $0x4b,%eax
jne    118b <card2val+0x8b>
movb   $0xb,-0x1(%rbp)
jmp    11a5 <card2val+0xa5>
movsbl -0x2(%rbp),%eax
cmp    $0x41,%eax
jne    11a1 <card2val+0xa1>
movb   $0xc,-0x1(%rbp)
jmp    11a5 <card2val+0xa5>
movb   $0xff,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<card2val>:
lea    -0x32(%rdi),%eax
cmp    $0x8,%al
jae    1108 <card2val+0x8>
ret
add    $0xbf,%dil
cmp    $0x13,%dil
ja     112b <card2val+0x2b>
mov    $0x8,%al
movzbl %dil,%ecx
lea    0xee1(%rip),%rdx
movslq (%rdx,%rcx,4),%rcx
add    %rdx,%rcx
jmp    *%rcx
mov    $0xc,%al
ret
mov    $0xff,%al
ret
mov    $0x9,%al
ret
mov    $0xb,%al
ret
mov    $0xa,%al
ret

LLVM IR (-O0):
define signext i8 @card2val(i8 signext %0) {
%2 = alloca i8
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
%6 = icmp sge i32 %5, 50
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = load i8, i8* %3
%9 = sext i8 %8 to i32
%10 = icmp sle i32 %9, 57
br i1 %10, label %11, label %16
11: ; preds = %7
%12 = load i8, i8* %3
%13 = sext i8 %12 to i32
%14 = sub nsw i32 %13, 50
%15 = trunc i32 %14 to i8
store i8 %15, i8* %2
br label %42
16: ; preds = %7, %1
%17 = load i8, i8* %3
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 84
br i1 %19, label %20, label %21
20: ; preds = %16
store i8 8, i8* %2
br label %42
21: ; preds = %16
%22 = load i8, i8* %3
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 74
br i1 %24, label %25, label %26
25: ; preds = %21
store i8 9, i8* %2
br label %42
26: ; preds = %21
%27 = load i8, i8* %3
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 81
br i1 %29, label %30, label %31
30: ; preds = %26
store i8 10, i8* %2
br label %42
31: ; preds = %26
%32 = load i8, i8* %3
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 75
br i1 %34, label %35, label %36
35: ; preds = %31
store i8 11, i8* %2
br label %42
36: ; preds = %31
%37 = load i8, i8* %3
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 65
br i1 %39, label %40, label %41
40: ; preds = %36
store i8 12, i8* %2
br label %42
41: ; preds = %36
store i8 -1, i8* %2
br label %42
42: ; preds = %41, %40, %35, %30, %25, %20, %11
%43 = load i8, i8* %2
ret i8 %43
}

LLVM IR (-O2):
define signext i8 @card2val(i8 signext %0) {
%2 = add i8 %0, -50
%3 = icmp ult i8 %2, 8
br i1 %3, label %10, label %4
4: ; preds = %1
switch i8 %0, label %9 [
i8 84, label %10
i8 74, label %5
i8 81, label %6
i8 75, label %7
i8 65, label %8
]
5: ; preds = %4
br label %10
6: ; preds = %4
br label %10
7: ; preds = %4
br label %10
8: ; preds = %4
br label %10
9: ; preds = %4
br label %10
10: ; preds = %1, %4, %9, %8, %7, %6, %5
%11 = phi i8 [ 9, %5 ], [ 10, %6 ], [ 11, %7 ], [ 12, %8 ], [ -1, %9 ], [ 8, %4 ], [ %2, %1 ]
ret i8 %11
}