char *get_last_digit(long a) {
  long last = a % 10;
  switch (last) {
  case 0:
    return ("Zero");
    break;
  case 1:
    return ("One");
    break;
  case 2:
    return ("Two");
    break;
  case 3:
    return ("Three");
    break;
  case 4:
    return ("Four");
    break;
  case 5:
    return ("Five");
    break;
  case 6:
    return ("Six");
    break;
  case 7:
    return ("Seven");
    break;
  case 8:
    return ("Eight");
    break;
  case 9:
    return ("Nine");
    break;
  }
}


x86 assembly (clang, -O0):
<get_last_digit>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movabs $0x6666666666666667,%rcx
66 66 66
imul   %rcx
mov    -0x28(%rbp),%rax
mov    %rdx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2,%rcx
add    %rdx,%rcx
add    %rcx,%rcx
lea    (%rcx,%rcx,4),%rcx
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
sub    $0x9,%rax
ja     1201 <get_last_digit+0x101>
mov    -0x20(%rbp),%rax
lea    0xea3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xebb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <get_last_digit+0x101>
lea    0xeb0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <get_last_digit+0x101>
lea    0xea4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <get_last_digit+0x101>
lea    0xe98(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <get_last_digit+0x101>
lea    0xe8e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <get_last_digit+0x101>
lea    0xe83(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <get_last_digit+0x101>
lea    0xe78(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <get_last_digit+0x101>
lea    0xe6c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <get_last_digit+0x101>
lea    0xe62(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <get_last_digit+0x101>
lea    0xe58(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_last_digit>:
movabs $0x6666666666666667,%rcx
66 66 66
mov    %rdi,%rax
imul   %rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x2,%rdx
add    %rax,%rdx
add    %rdx,%rdx
lea    (%rdx,%rdx,4),%rax
not    %rax
add    %rdi,%rax
cmp    $0x8,%rax
ja     1140 <get_last_digit+0x40>
lea    0xefc(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xeb9(%rip),%rax
ret

LLVM IR (-O0):
@.str = [5 x i8] c"Zero\00"
@.str.1 = [4 x i8] c"One\00"
@.str.2 = [4 x i8] c"Two\00"
@.str.3 = [6 x i8] c"Three\00"
@.str.4 = [5 x i8] c"Four\00"
@.str.5 = [5 x i8] c"Five\00"
@.str.6 = [4 x i8] c"Six\00"
@.str.7 = [6 x i8] c"Seven\00"
@.str.8 = [6 x i8] c"Eight\00"
@.str.9 = [5 x i8] c"Nine\00"
define i8* @get_last_digit(i64 %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
store i64 %0, i64* %3
%5 = load i64, i64* %3
%6 = srem i64 %5, 10
store i64 %6, i64* %4
%7 = load i64, i64* %4
switch i64 %7, label %18 [
i64 0, label %8
i64 1, label %9
i64 2, label %10
i64 3, label %11
i64 4, label %12
i64 5, label %13
i64 6, label %14
i64 7, label %15
i64 8, label %16
i64 9, label %17
]
8: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %2
br label %18
9: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %18
10: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %18
11: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %18
12: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %18
13: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %18
14: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %18
15: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %18
16: ; preds = %1
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0), i8** %2
br label %18
17: ; preds = %1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i8** %2
br label %18
18: ; preds = %8, %9, %10, %11, %12, %13, %14, %15, %16, %17, %1
%19 = load i8*, i8** %2
ret i8* %19
}

LLVM IR (-O2):
@.str = [5 x i8] c"Zero\00"
@.str.1 = [4 x i8] c"One\00"
@.str.2 = [4 x i8] c"Two\00"
@.str.3 = [6 x i8] c"Three\00"
@.str.4 = [5 x i8] c"Four\00"
@.str.5 = [5 x i8] c"Five\00"
@.str.6 = [4 x i8] c"Six\00"
@.str.7 = [6 x i8] c"Seven\00"
@.str.8 = [6 x i8] c"Eight\00"
@.str.9 = [5 x i8] c"Nine\00"
@reltable.get_last_digit = [9 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([9 x i32]* @reltable.get_last_digit to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([9 x i32]* @reltable.get_last_digit to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([9 x i32]* @reltable.get_last_digit to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.4 to i64), i64 ptrtoint ([9 x i32]* @reltable.get_last_digit to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([9 x i32]* @reltable.get_last_digit to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([9 x i32]* @reltable.get_last_digit to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.7 to i64), i64 ptrtoint ([9 x i32]* @reltable.get_last_digit to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.8 to i64), i64 ptrtoint ([9 x i32]* @reltable.get_last_digit to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.9 to i64), i64 ptrtoint ([9 x i32]* @reltable.get_last_digit to i64)) to i32)]
define i8* @get_last_digit(i64 %0) {
%2 = srem i64 %0, 10
%3 = add nsw i64 %2, -1
%4 = icmp ult i64 %3, 9
br i1 %4, label %5, label %8
5: ; preds = %1
%6 = shl i64 %3, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([9 x i32]* @reltable.get_last_digit to i8*), i64 %6)
br label %8
8: ; preds = %5, %1
%9 = phi i8* [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %1 ], [ %7, %5 ]
ret i8* %9
}