char digit2char(unsigned char digit) {
  switch (digit & 0xf) {
  case 0x0:
    return '0';
  case 0x1:
    return '1';
  case 0x2:
    return '2';
  case 0x3:
    return '3';
  case 0x4:
    return '4';
  case 0x5:
    return '5';
  case 0x6:
    return '6';
  case 0x7:
    return '7';
  case 0x8:
    return '8';
  case 0x9:
    return '9';
  case 0xa:
    return 'A';
  case 0xb:
    return 'B';
  case 0xc:
    return 'C';
  case 0xd:
    return 'D';
  case 0xe:
    return '*';
  case 0xf:
    return '#';
  default:
    return 0;
  }
}


x86 assembly (clang, -O0):
<digit2char>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x2(%rbp)
movzbl -0x2(%rbp),%eax
and    $0xf,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0xf,%eax
ja     11c4 <digit2char+0xc4>
mov    -0x10(%rbp),%rax
lea    0xed5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x30,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x31,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x32,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x33,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x34,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x35,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x36,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x37,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x38,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x39,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x41,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x42,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x43,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x44,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x2a,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x23,-0x1(%rbp)
jmp    11c8 <digit2char+0xc8>
movb   $0x0,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<digit2char>:
and    $0xf,%edi
lea    0xef6(%rip),%rax
mov    (%rdi,%rax,1),%al
ret

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

LLVM IR (-O2):
@switch.table.digit2char = [16 x i8] c"0123456789ABCD*#"
define signext i8 @digit2char(i8 zeroext %0) {
%2 = and i8 %0, 15
%3 = zext i8 %2 to i64
%4 = getelementptr inbounds [16 x i8], [16 x i8]* @switch.table.digit2char, i64 0, i64 %3
%5 = load i8, i8* %4
ret i8 %5
}