char *get_msr_name(int msr) {
  switch (msr) {
  case 0xc1:
    return "MSR_P6_PERFCTR0";
  case 0x186:
    return "MSR_P6_PERFCTR0";
  case 0x38e:
    return "MSR_CORE_PERF_GLOBAL_STATUS";
  case 0x38f:
    return "MSR_CORE_PERF_GLOBAL_CTRL";
  case 0x390:
    return "MSR_CORE_PERF_GLOBAL_OVF_CTRL";
  default:
    return "UNKNOWN";
  }
}


x86 assembly (clang, -O0):
<get_msr_name>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0xc1,%eax
je     1169 <get_msr_name+0x69>
jmp    111d <get_msr_name+0x1d>
mov    -0x10(%rbp),%eax
sub    $0x186,%eax
je     1179 <get_msr_name+0x79>
jmp    1130 <get_msr_name+0x30>
mov    -0x10(%rbp),%eax
sub    $0x38e,%eax
je     1189 <get_msr_name+0x89>
jmp    1143 <get_msr_name+0x43>
mov    -0x10(%rbp),%eax
sub    $0x38f,%eax
je     1199 <get_msr_name+0x99>
jmp    1156 <get_msr_name+0x56>
mov    -0x10(%rbp),%eax
sub    $0x390,%eax
je     11a9 <get_msr_name+0xa9>
jmp    11b9 <get_msr_name+0xb9>
lea    0xe90(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c4 <get_msr_name+0xc4>
lea    0xe80(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c4 <get_msr_name+0xc4>
lea    0xe80(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c4 <get_msr_name+0xc4>
lea    0xe8c(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c4 <get_msr_name+0xc4>
lea    0xe96(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11c4 <get_msr_name+0xc4>
lea    0xea4(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_msr_name>:
cmp    $0x38d,%edi
jle    1128 <get_msr_name+0x28>
cmp    $0x390,%edi
je     1140 <get_msr_name+0x40>
cmp    $0x38f,%edi
je     1148 <get_msr_name+0x48>
cmp    $0x38e,%edi
jne    1150 <get_msr_name+0x50>
lea    0xee9(%rip),%rax
ret
lea    0xed1(%rip),%rax
cmp    $0xc1,%edi
je     113f <get_msr_name+0x3f>
cmp    $0x186,%edi
jne    1150 <get_msr_name+0x50>
ret
lea    0xeff(%rip),%rax
ret
lea    0xedd(%rip),%rax
ret
lea    0xf0d(%rip),%rax
ret

LLVM IR (-O0):
@.str = [16 x i8] c"MSR_P6_PERFCTR0\00"
@.str.1 = [28 x i8] c"MSR_CORE_PERF_GLOBAL_STATUS\00"
@.str.2 = [26 x i8] c"MSR_CORE_PERF_GLOBAL_CTRL\00"
@.str.3 = [30 x i8] c"MSR_CORE_PERF_GLOBAL_OVF_CTRL\00"
@.str.4 = [8 x i8] c"UNKNOWN\00"
define i8* @get_msr_name(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %10 [
i32 193, label %5
i32 390, label %6
i32 910, label %7
i32 911, label %8
i32 912, label %9
]
5: ; preds = %1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %2
br label %11
6: ; preds = %1
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8** %2
br label %11
7: ; preds = %1
store i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %11
8: ; preds = %1
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %11
9: ; preds = %1
store i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %11
10: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %11
11: ; preds = %10, %9, %8, %7, %6, %5
%12 = load i8*, i8** %2
ret i8* %12
}

LLVM IR (-O2):
@.str = [16 x i8] c"MSR_P6_PERFCTR0\00"
@.str.1 = [28 x i8] c"MSR_CORE_PERF_GLOBAL_STATUS\00"
@.str.2 = [26 x i8] c"MSR_CORE_PERF_GLOBAL_CTRL\00"
@.str.3 = [30 x i8] c"MSR_CORE_PERF_GLOBAL_OVF_CTRL\00"
@.str.4 = [8 x i8] c"UNKNOWN\00"
define i8* @get_msr_name(i32 %0) {
switch i32 %0, label %5 [
i32 193, label %6
i32 390, label %6
i32 910, label %2
i32 911, label %3
i32 912, label %4
]
2: ; preds = %1
br label %6
3: ; preds = %1
br label %6
4: ; preds = %1
br label %6
5: ; preds = %1
br label %6
6: ; preds = %1, %1, %5, %4, %3, %2
%7 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), %5 ], [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), %4 ], [ getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %1 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %7
}