char *get_day(int d) {
  char *days[7] = {"Monday", "Tuesday",  "Wednesday", "Thursday",
                   "Friday", "Saturday", "Sunday"};
  if (d >= 1 && d <= 7)
    return days[d - 1];
}


x86 assembly (clang, -O0):
<get_day>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x50(%rbp),%rdi
lea    0x2cba(%rip),%rsi
mov    $0x38,%edx
call   1030 <memcpy@plt>
cmpl   $0x1,-0xc(%rbp)
jl     1155 <get_day+0x45>
cmpl   $0x7,-0xc(%rbp)
jg     1155 <get_day+0x45>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x50(%rbp,%rax,8),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_day>:
add    $0xffffffff,%edi
cmp    $0x6,%edi
ja     1118 <get_day+0x18>
mov    %edi,%eax
lea    0xf2b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
@.str = [7 x i8] c"Monday\00"
@.str.1 = [8 x i8] c"Tuesday\00"
@.str.2 = [10 x i8] c"Wednesday\00"
@.str.3 = [9 x i8] c"Thursday\00"
@.str.4 = [7 x i8] c"Friday\00"
@.str.5 = [9 x i8] c"Saturday\00"
@.str.6 = [7 x i8] c"Sunday\00"
@__const.get_day.days = [7 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i32 0, i32 0)]
define i8* @get_day(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca [7 x i8*]
store i32 %0, i32* %3
%5 = bitcast [7 x i8*]* %4 to i8*
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 1
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i32, i32* %3
%10 = icmp sle i32 %9, 7
br i1 %10, label %11, label %17
11: ; preds = %8
%12 = load i32, i32* %3
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds [7 x i8*], [7 x i8*]* %4, i64 0, i64 %14
%16 = load i8*, i8** %15
store i8* %16, i8** %2
br label %17
17: ; preds = %11, %8, %1
%18 = load i8*, i8** %2
ret i8* %18
}

LLVM IR (-O2):
@.str = [7 x i8] c"Monday\00"
@.str.1 = [8 x i8] c"Tuesday\00"
@.str.2 = [10 x i8] c"Wednesday\00"
@.str.3 = [9 x i8] c"Thursday\00"
@.str.4 = [7 x i8] c"Friday\00"
@.str.5 = [9 x i8] c"Saturday\00"
@.str.6 = [7 x i8] c"Sunday\00"
@reltable.get_day = [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.get_day to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.get_day to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.get_day to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.get_day to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.get_day to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.get_day to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.get_day to i64)) to i32)]
define i8* @get_day(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 7
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = zext i32 %2 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.get_day to i8*), i64 %6)
br label %8
8: ; preds = %1, %4
%9 = phi i8* [ %7, %4 ], [ undef, %1 ]
ret i8* %9
}