char *print_state(const char state) {
  switch (state) {
  case 'R':
    return ("running");
  case 'S':
    return ("sleeping");
  case 'D':
    return ("disk sleep");
  case 'Z':
    return ("zombie");
  case 'T':
    return ("traced");
  case 'W':
    return ("paging");
  }
  return ("unknown");
}


x86 assembly (clang, -O0):
<print_state>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x9(%rbp)
movsbl -0x9(%rbp),%eax
add    $0xffffffbc,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x16,%eax
ja     1194 <print_state+0x94>
mov    -0x18(%rbp),%rax
lea    0xed5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf21(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <print_state+0x9f>
lea    0xf19(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <print_state+0x9f>
lea    0xf12(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <print_state+0x9f>
lea    0xf0d(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <print_state+0x9f>
lea    0xf04(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <print_state+0x9f>
lea    0xefb(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    119f <print_state+0x9f>
lea    0xef2(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_state>:
add    $0xffffffbc,%edi
cmp    $0x16,%edi
ja     1127 <print_state+0x27>
lea    0xf4d(%rip),%rax
lea    0xeea(%rip),%rcx
movslq (%rcx,%rdi,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
lea    0xf47(%rip),%rax
ret
lea    0xf5f(%rip),%rax
ret
lea    0xf2e(%rip),%rax
ret
lea    0xf41(%rip),%rax
ret
lea    0xf40(%rip),%rax
ret
lea    0xf2a(%rip),%rax
ret

LLVM IR (-O0):
@.str = [8 x i8] c"running\00"
@.str.1 = [9 x i8] c"sleeping\00"
@.str.2 = [11 x i8] c"disk sleep\00"
@.str.3 = [7 x i8] c"zombie\00"
@.str.4 = [7 x i8] c"traced\00"
@.str.5 = [7 x i8] c"paging\00"
@.str.6 = [8 x i8] c"unknown\00"
define i8* @print_state(i8 signext %0) {
%2 = alloca i8*
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = sext i8 %4 to i32
switch i32 %5, label %12 [
i32 82, label %6
i32 83, label %7
i32 68, label %8
i32 90, label %9
i32 84, label %10
i32 87, label %11
]
6: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %2
br label %13
7: ; preds = %1
store i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %13
8: ; preds = %1
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %13
9: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %13
10: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %13
11: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %13
12: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %2
br label %13
13: ; preds = %12, %11, %10, %9, %8, %7, %6
%14 = load i8*, i8** %2
ret i8* %14
}

LLVM IR (-O2):
@.str = [8 x i8] c"running\00"
@.str.1 = [9 x i8] c"sleeping\00"
@.str.2 = [11 x i8] c"disk sleep\00"
@.str.3 = [7 x i8] c"zombie\00"
@.str.4 = [7 x i8] c"traced\00"
@.str.5 = [7 x i8] c"paging\00"
@.str.6 = [8 x i8] c"unknown\00"
define i8* @print_state(i8 signext %0) {
%2 = sext i8 %0 to i32
switch i32 %2, label %8 [
i32 82, label %9
i32 83, label %3
i32 68, label %4
i32 90, label %5
i32 84, label %6
i32 87, label %7
]
3: ; preds = %1
br label %9
4: ; preds = %1
br label %9
5: ; preds = %1
br label %9
6: ; preds = %1
br label %9
7: ; preds = %1
br label %9
8: ; preds = %1
br label %9
9: ; preds = %1, %8, %7, %6, %5, %4, %3
%10 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), %8 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), %7 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), %6 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), %5 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), %4 ], [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), %3 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %10
}