char get_digit(int digit) {
  switch (digit) {
  case 0:
    return '0';
  case 1:
    return '1';
  case 2:
    return '2';
  case 3:
    return '3';
  case 4:
    return '4';
  case 5:
    return '5';
  case 6:
    return '6';
  case 7:
    return '7';
  case 8:
    return '8';
  case 9:
    return '9';
  case 10:
    return 'A';
  case 11:
    return 'B';
  case 12:
    return 'C';
  case 13:
    return 'D';
  case 14:
    return 'E';
  case 15:
    return 'F';
  }
}


x86 assembly (clang, -O0):
<get_digit>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %rax,-0x10(%rbp)
sub    $0xf,%rax
ja     11b7 <get_digit+0xb7>
mov    -0x10(%rbp),%rax
lea    0xedd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movb   $0x30,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x31,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x32,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x33,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x34,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x35,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x36,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x37,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x38,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x39,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x41,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x42,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x43,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x44,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x45,-0x1(%rbp)
jmp    11b7 <get_digit+0xb7>
movb   $0x46,-0x1(%rbp)
movsbl -0x1(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_digit>:
add    $0xffffffff,%edi
mov    $0x30,%al
cmp    $0xe,%edi
ja     1117 <get_digit+0x17>
movslq %edi,%rax
lea    0xeec(%rip),%rcx
mov    (%rax,%rcx,1),%al
ret

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

LLVM IR (-O2):
@switch.table.get_digit = [15 x i8] c"123456789ABCDEF"
define signext i8 @get_digit(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 15
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = getelementptr inbounds [15 x i8], [15 x i8]* @switch.table.get_digit, i64 0, i64 %5
%7 = load i8, i8* %6
br label %8
8: ; preds = %4, %1
%9 = phi i8 [ 48, %1 ], [ %7, %4 ]
ret i8 %9
}