char *icmpv6_opttype(unsigned char id) {
  switch (id) {
  case 1:
    return ("Source Link-Layer Address");
  case 2:
    return ("Target Link-Layer Address");
  case 3:
    return ("Prefix Information");
  case 4:
    return ("Redirected Header");
  case 5:
    return ("MTU");
  }
  return ("UNKNOWN");
}


x86 assembly (clang, -O0):
<icmpv6_opttype>:
push   %rbp
mov    %rsp,%rbp
mov    %dil,%al
mov    %al,-0x9(%rbp)
movzbl -0x9(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x4,%eax
ja     1184 <icmpv6_opttype+0x84>
mov    -0x18(%rbp),%rax
lea    0xed5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xed9(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <icmpv6_opttype+0x8f>
lea    0xee3(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <icmpv6_opttype+0x8f>
lea    0xeed(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <icmpv6_opttype+0x8f>
lea    0xef0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <icmpv6_opttype+0x8f>
lea    0xef2(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    118f <icmpv6_opttype+0x8f>
lea    0xee6(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<icmpv6_opttype>:
add    $0xff,%dil
cmp    $0x4,%dil
ja     111d <icmpv6_opttype+0x1d>
movsbq %dil,%rax
lea    0xf53(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xf39(%rip),%rax
ret

LLVM IR (-O0):
@.str = [26 x i8] c"Source Link-Layer Address\00"
@.str.1 = [26 x i8] c"Target Link-Layer Address\00"
@.str.2 = [19 x i8] c"Prefix Information\00"
@.str.3 = [18 x i8] c"Redirected Header\00"
@.str.4 = [4 x i8] c"MTU\00"
@.str.5 = [8 x i8] c"UNKNOWN\00"
define i8* @icmpv6_opttype(i8 zeroext %0) {
%2 = alloca i8*
%3 = alloca i8
store i8 %0, i8* %3
%4 = load i8, i8* %3
%5 = zext i8 %4 to i32
switch i32 %5, label %11 [
i32 1, label %6
i32 2, label %7
i32 3, label %8
i32 4, label %9
i32 5, label %10
]
6: ; preds = %1
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8** %2
br label %12
7: ; preds = %1
store i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %12
8: ; preds = %1
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %12
9: ; preds = %1
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %12
10: ; preds = %1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %12
11: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8** %2
br label %12
12: ; preds = %11, %10, %9, %8, %7, %6
%13 = load i8*, i8** %2
ret i8* %13
}

LLVM IR (-O2):
@.str = [26 x i8] c"Source Link-Layer Address\00"
@.str.1 = [26 x i8] c"Target Link-Layer Address\00"
@.str.2 = [19 x i8] c"Prefix Information\00"
@.str.3 = [18 x i8] c"Redirected Header\00"
@.str.4 = [4 x i8] c"MTU\00"
@.str.5 = [8 x i8] c"UNKNOWN\00"
@reltable.icmpv6_opttype = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([26 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.icmpv6_opttype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([26 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.icmpv6_opttype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.icmpv6_opttype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.icmpv6_opttype to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([4 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.icmpv6_opttype to i64)) to i32)]
define i8* @icmpv6_opttype(i8 zeroext %0) {
%2 = add i8 %0, -1
%3 = icmp ult i8 %2, 5
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = sext i8 %2 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.icmpv6_opttype to i8*), i64 %6)
br label %8
8: ; preds = %1, %4
%9 = phi i8* [ %7, %4 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %1 ]
ret i8* %9
}