const char *filter_name(short filt) {
  int id;
  const char *fname[11] = {"EVFILT_READ",  "EVFILT_WRITE",  "EVFILT_AIO",
                           "EVFILT_VNODE", "EVFILT_PROC",   "EVFILT_SIGNAL",
                           "EVFILT_TIMER", "EVFILT_NETDEV", "EVFILT_FS",
                           "EVFILT_LIO",   "EVFILT_USER"};
  id = ~filt;
  if (id < 0 || id >= 11)
    return "EVFILT_INVALID";
  else
    return fname[id];
}


x86 assembly (clang, -O0):
<filter_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %di,%ax
mov    %ax,-0xa(%rbp)
lea    -0x70(%rbp),%rdi
lea    0x2c96(%rip),%rsi
mov    $0x58,%edx
call   1030 <memcpy@plt>
movswl -0xa(%rbp),%eax
xor    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1152 <filter_name+0x42>
cmpl   $0xb,-0x10(%rbp)
jl     1162 <filter_name+0x52>
lea    0xf2e(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    116f <filter_name+0x5f>
movslq -0x10(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<filter_name>:
cmp    $0xfff5,%di
jae    110e <filter_name+0xe>
lea    0xf7a(%rip),%rax
ret
not    %edi
movswq %di,%rax
lea    0xf7d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret

LLVM IR (-O0):
@.str = [12 x i8] c"EVFILT_READ\00"
@.str.1 = [13 x i8] c"EVFILT_WRITE\00"
@.str.2 = [11 x i8] c"EVFILT_AIO\00"
@.str.3 = [13 x i8] c"EVFILT_VNODE\00"
@.str.4 = [12 x i8] c"EVFILT_PROC\00"
@.str.5 = [14 x i8] c"EVFILT_SIGNAL\00"
@.str.6 = [13 x i8] c"EVFILT_TIMER\00"
@.str.7 = [14 x i8] c"EVFILT_NETDEV\00"
@.str.8 = [10 x i8] c"EVFILT_FS\00"
@.str.9 = [11 x i8] c"EVFILT_LIO\00"
@.str.10 = [12 x i8] c"EVFILT_USER\00"
@__const.filter_name.fname = [11 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i32 0, i32 0)]
@.str.11 = [15 x i8] c"EVFILT_INVALID\00"
define i8* @filter_name(i16 signext %0) {
%2 = alloca i8*
%3 = alloca i16
%4 = alloca i32
%5 = alloca [11 x i8*]
store i16 %0, i16* %3
%6 = bitcast [11 x i8*]* %5 to i8*
%7 = load i16, i16* %3
%8 = sext i16 %7 to i32
%9 = xor i32 %8, -1
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %1
%13 = load i32, i32* %4
%14 = icmp sge i32 %13, 11
br i1 %14, label %15, label %16
15: ; preds = %12, %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8** %2
br label %21
16: ; preds = %12
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [11 x i8*], [11 x i8*]* %5, i64 0, i64 %18
%20 = load i8*, i8** %19
store i8* %20, i8** %2
br label %21
21: ; preds = %16, %15
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@.str = [12 x i8] c"EVFILT_READ\00"
@.str.1 = [13 x i8] c"EVFILT_WRITE\00"
@.str.2 = [11 x i8] c"EVFILT_AIO\00"
@.str.3 = [13 x i8] c"EVFILT_VNODE\00"
@.str.4 = [12 x i8] c"EVFILT_PROC\00"
@.str.5 = [14 x i8] c"EVFILT_SIGNAL\00"
@.str.6 = [13 x i8] c"EVFILT_TIMER\00"
@.str.7 = [14 x i8] c"EVFILT_NETDEV\00"
@.str.8 = [10 x i8] c"EVFILT_FS\00"
@.str.9 = [11 x i8] c"EVFILT_LIO\00"
@.str.10 = [12 x i8] c"EVFILT_USER\00"
@reltable.filter_name = [11 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str to i64), i64 ptrtoint ([11 x i32]* @reltable.filter_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.1 to i64), i64 ptrtoint ([11 x i32]* @reltable.filter_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.2 to i64), i64 ptrtoint ([11 x i32]* @reltable.filter_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.3 to i64), i64 ptrtoint ([11 x i32]* @reltable.filter_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.4 to i64), i64 ptrtoint ([11 x i32]* @reltable.filter_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.5 to i64), i64 ptrtoint ([11 x i32]* @reltable.filter_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.6 to i64), i64 ptrtoint ([11 x i32]* @reltable.filter_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([14 x i8]* @.str.7 to i64), i64 ptrtoint ([11 x i32]* @reltable.filter_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.8 to i64), i64 ptrtoint ([11 x i32]* @reltable.filter_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([11 x i8]* @.str.9 to i64), i64 ptrtoint ([11 x i32]* @reltable.filter_name to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.10 to i64), i64 ptrtoint ([11 x i32]* @reltable.filter_name to i64)) to i32)]
@.str.11 = [15 x i8] c"EVFILT_INVALID\00"
define i8* @filter_name(i16 signext %0) {
%2 = icmp ult i16 %0, -11
br i1 %2, label %8, label %3
3: ; preds = %1
%4 = xor i16 %0, -1
%5 = sext i16 %4 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([11 x i32]* @reltable.filter_name to i8*), i64 %6)
br label %8
8: ; preds = %1, %3
%9 = phi i8* [ %7, %3 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), %1 ]
ret i8* %9
}