char *last_digit_to_word(int num) {
  char *words[] = {"zero", "one", "two",   "three", "four",
                   "five", "six", "seven", "eight", "nine"};
  int lastDigit;
  lastDigit = num % 10;
  return (words[lastDigit]);
}


x86 assembly (clang, -O0):
<last_digit_to_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x60(%rbp),%rdi
lea    0x2caa(%rip),%rsi
mov    $0x50,%edx
call   1030 <memcpy@plt>
mov    -0x4(%rbp),%eax
mov    $0xa,%ecx
cltd
idiv   %ecx
mov    %edx,-0x64(%rbp)
movslq -0x64(%rbp),%rax
mov    -0x60(%rbp,%rax,8),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<last_digit_to_word>:
movslq %edi,%rax
imul   $0x66666667,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x22,%rcx
add    %edx,%ecx
add    %ecx,%ecx
lea    (%rcx,%rcx,4),%ecx
sub    %ecx,%eax
cltq
lea    0xf0d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%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"
@__const.last_digit_to_word.words = [10 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i32 0, i32 0)]
define i8* @last_digit_to_word(i32 %0) {
%2 = alloca i32
%3 = alloca [10 x i8*]
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast [10 x i8*]* %3 to i8*
%6 = load i32, i32* %2
%7 = srem i32 %6, 10
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = sext i32 %8 to i64
%10 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 %9
%11 = load i8*, i8** %10
ret i8* %11
}

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.last_digit_to_word = [10 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([10 x i32]* @reltable.last_digit_to_word to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.1 to i64), i64 ptrtoint ([10 x i32]* @reltable.last_digit_to_word to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.2 to i64), i64 ptrtoint ([10 x i32]* @reltable.last_digit_to_word to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.3 to i64), i64 ptrtoint ([10 x i32]* @reltable.last_digit_to_word to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.4 to i64), i64 ptrtoint ([10 x i32]* @reltable.last_digit_to_word to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.5 to i64), i64 ptrtoint ([10 x i32]* @reltable.last_digit_to_word to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.6 to i64), i64 ptrtoint ([10 x i32]* @reltable.last_digit_to_word to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.7 to i64), i64 ptrtoint ([10 x i32]* @reltable.last_digit_to_word to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.8 to i64), i64 ptrtoint ([10 x i32]* @reltable.last_digit_to_word to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str.9 to i64), i64 ptrtoint ([10 x i32]* @reltable.last_digit_to_word to i64)) to i32)]
define i8* @last_digit_to_word(i32 %0) {
%2 = srem i32 %0, 10
%3 = sext i32 %2 to i64
%4 = shl i64 %3, 2
%5 = call i8* @llvm.load.relative.i64(i8* bitcast ([10 x i32]* @reltable.last_digit_to_word to i8*), i64 %4)
ret i8* %5
}