#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct tm {
  int tm_wday;
};

/* Variables and functions */
char *daytostring(struct tm *tmst) {
  switch (tmst->tm_wday) {
  case 0:
    return "sunday";
    break;
  case 1:
    return "monday";
    break;
  case 2:
    return "tuesday";
    break;
  case 3:
    return "wednesday";
    break;
  case 4:
    return "thursday";
    break;
  case 5:
    return "friday";
    break;
  case 6:
    return "saturday";
    break;
  default:
    return "WTF";
    break;
  }
}


x86 assembly (clang, -O0):
<daytostring>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %rax,-0x18(%rbp)
sub    $0x6,%rax
ja     11a0 <daytostring+0xa0>
mov    -0x18(%rbp),%rax
lea    0xed9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xee5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ab <daytostring+0xab>
lea    0xedc(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ab <daytostring+0xab>
lea    0xed3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ab <daytostring+0xab>
lea    0xecb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ab <daytostring+0xab>
lea    0xec5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ab <daytostring+0xab>
lea    0xebe(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ab <daytostring+0xab>
lea    0xeb5(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11ab <daytostring+0xab>
lea    0xeae(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<daytostring>:
movslq (%rdi),%rax
cmp    $0x6,%rax
ja     1118 <daytostring+0x18>
lea    0xf30(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xf1a(%rip),%rax
ret

LLVM IR (-O0):
%struct.tm = type { i32 }
@.str = [7 x i8] c"sunday\00"
@.str.1 = [7 x i8] c"monday\00"
@.str.2 = [8 x i8] c"tuesday\00"
@.str.3 = [10 x i8] c"wednesday\00"
@.str.4 = [9 x i8] c"thursday\00"
@.str.5 = [7 x i8] c"friday\00"
@.str.6 = [9 x i8] c"saturday\00"
@.str.7 = [4 x i8] c"WTF\00"
define i8* @daytostring(%struct.tm* %0) {
%2 = alloca i8*
%3 = alloca %struct.tm*
store %struct.tm* %0, %struct.tm** %3
%4 = load %struct.tm*, %struct.tm** %3
%5 = getelementptr inbounds %struct.tm, %struct.tm* %4, i32 0, i32 0
%6 = load i32, i32* %5
switch i32 %6, label %14 [
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
]
7: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
br label %15
8: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %15
9: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %15
10: ; preds = %1
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %15
11: ; preds = %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %15
12: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %15
13: ; preds = %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %15
14: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8** %2
br label %15
15: ; preds = %14, %13, %12, %11, %10, %9, %8, %7
%16 = load i8*, i8** %2
ret i8* %16
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@.str = [7 x i8] c"sunday\00"
@.str.1 = [7 x i8] c"monday\00"
@.str.2 = [8 x i8] c"tuesday\00"
@.str.3 = [10 x i8] c"wednesday\00"
@.str.4 = [9 x i8] c"thursday\00"
@.str.5 = [7 x i8] c"friday\00"
@.str.6 = [9 x i8] c"saturday\00"
@.str.7 = [4 x i8] c"WTF\00"
@reltable.daytostring = [7 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str to i64), i64 ptrtoint ([7 x i32]* @reltable.daytostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.1 to i64), i64 ptrtoint ([7 x i32]* @reltable.daytostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.2 to i64), i64 ptrtoint ([7 x i32]* @reltable.daytostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.3 to i64), i64 ptrtoint ([7 x i32]* @reltable.daytostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.4 to i64), i64 ptrtoint ([7 x i32]* @reltable.daytostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.5 to i64), i64 ptrtoint ([7 x i32]* @reltable.daytostring to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.6 to i64), i64 ptrtoint ([7 x i32]* @reltable.daytostring to i64)) to i32)]
define i8* @daytostring(%struct.tm* nocapture %0) {
%2 = getelementptr inbounds %struct.tm, %struct.tm* %0, i64 0, i32 0
%3 = load i32, i32* %2
%4 = icmp ult i32 %3, 7
br i1 %4, label %5, label %9
5: ; preds = %1
%6 = sext i32 %3 to i64
%7 = shl i64 %6, 2
%8 = call i8* @llvm.load.relative.i64(i8* bitcast ([7 x i32]* @reltable.daytostring to i8*), i64 %7)
br label %9
9: ; preds = %1, %5
%10 = phi i8* [ %8, %5 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), %1 ]
ret i8* %10
}