unsigned char hDigit2byte(int hex) {
  switch (hex) {
  case '0':
    return (0x0);
  case '1':
    return (0x1);
  case '2':
    return (0x2);
  case '3':
    return (0x3);
  case '4':
    return (0x4);
  case '5':
    return (0x5);
  case '6':
    return (0x6);
  case '7':
    return (0x7);
  case '8':
    return (0x8);
  case '9':
    return (0x9);
  case 'A':
    return (0xA);
  case 'B':
    return (0xB);
  case 'C':
    return (0xC);
  case 'D':
    return (0xD);
  case 'E':
    return (0xE);
  case 'F':
    return (0xF);
  default:
    return (0);
  }
}


x86 assembly (clang, -O0):
<hDigit2byte>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffd0,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x16,%eax
ja     11c0 <hDigit2byte+0xc0>
mov    -0x10(%rbp),%rax
lea    0xed9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x0,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0x1,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0x2,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0x3,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0x4,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0x5,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0x6,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0x7,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0x8,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0x9,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0xa,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0xb,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0xc,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0xd,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0xe,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0xf,-0x1(%rbp)
jmp    11c4 <hDigit2byte+0xc4>
movb   $0x0,-0x1(%rbp)
movzbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<hDigit2byte>:
add    $0xffffffcf,%edi
cmp    $0x15,%edi
ja     1116 <hDigit2byte+0x16>
movslq %edi,%rax
lea    0xeee(%rip),%rcx
mov    (%rax,%rcx,1),%al
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
define zeroext i8 @hDigit2byte(i32 %0) {
%2 = alloca i8
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %21 [
i32 48, label %5
i32 49, label %6
i32 50, label %7
i32 51, label %8
i32 52, label %9
i32 53, label %10
i32 54, label %11
i32 55, label %12
i32 56, label %13
i32 57, label %14
i32 65, label %15
i32 66, label %16
i32 67, label %17
i32 68, label %18
i32 69, label %19
i32 70, label %20
]
5: ; preds = %1
store i8 0, i8* %2
br label %22
6: ; preds = %1
store i8 1, i8* %2
br label %22
7: ; preds = %1
store i8 2, i8* %2
br label %22
8: ; preds = %1
store i8 3, i8* %2
br label %22
9: ; preds = %1
store i8 4, i8* %2
br label %22
10: ; preds = %1
store i8 5, i8* %2
br label %22
11: ; preds = %1
store i8 6, i8* %2
br label %22
12: ; preds = %1
store i8 7, i8* %2
br label %22
13: ; preds = %1
store i8 8, i8* %2
br label %22
14: ; preds = %1
store i8 9, i8* %2
br label %22
15: ; preds = %1
store i8 10, i8* %2
br label %22
16: ; preds = %1
store i8 11, i8* %2
br label %22
17: ; preds = %1
store i8 12, i8* %2
br label %22
18: ; preds = %1
store i8 13, i8* %2
br label %22
19: ; preds = %1
store i8 14, i8* %2
br label %22
20: ; preds = %1
store i8 15, i8* %2
br label %22
21: ; preds = %1
store i8 0, i8* %2
br label %22
22: ; preds = %21, %20, %19, %18, %17, %16, %15, %14, %13, %12, %11, %10, %9, %8, %7, %6, %5
%23 = load i8, i8* %2
ret i8 %23
}

LLVM IR (-O2):
@switch.table.hDigit2byte = [22 x i8] c"\01\02\03\04\05\06\07\08\09\00\00\00\00\00\00\00\0A\0B\0C\0D\0E\0F"
define zeroext i8 @hDigit2byte(i32 %0) {
%2 = add i32 %0, -49
%3 = icmp ult i32 %2, 22
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds [22 x i8], [22 x i8]* @switch.table.hDigit2byte, i64 0, i64 %5
%7 = load i8, i8* %6
br label %8
8: ; preds = %4, %1
%9 = phi i8 [ 0, %1 ], [ %7, %4 ]
ret i8 %9
}