const char *SignalName(int sig) {
  static char *sig_map[] = {
      "NULL",    "SIGHUP",  "SIGINT",    "SIGQUIT", "SIGILL",    "SIGTRAP",
      "SIGABRT", "SIGBUS",  "SIGFPE",    "SIGKILL", "SIGUSR1",   "SIGSEGV",
      "SIGUSR2", "SIGPIPE", "SIGALRM",   "SIGTERM", "SIGSTKFLT", "SIGCHLD",
      "SIGCONT", "SIGSTOP", "SIGTSTP",   "SIGTTIN", "SIGTTOU",   "SIGURG",
      "SIGXCPU", "SIGXFSZ", "SIGVTALRM", "SIGPROF", "SIGWINCH",  "SIGIO",
      "SIGPWR",  "SIGSYS"};
  return sig > 0 && sig < (int)sizeof(sig_map) ? sig_map[sig] : sig_map[0];
}


x86 assembly (clang, -O0):
<SignalName>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    1136 <SignalName+0x36>
cmpl   $0x100,-0x4(%rbp)
jge    1136 <SignalName+0x36>
movslq -0x4(%rbp),%rcx
lea    0x2f07(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x10(%rbp)
jmp    1141 <SignalName+0x41>
mov    0x2ef3(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<SignalName>:
lea    -0x1(%rdi),%eax
cmp    $0xfe,%eax
ja     111b <SignalName+0x1b>
mov    %edi,%eax
lea    0xeed(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
ret
lea    0xf5e(%rip),%rax
ret

LLVM IR (-O0):
@SignalName.sig_map = internal global [32 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.16, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.17, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.18, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.19, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.20, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.21, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.22, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.23, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.24, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.25, i32 0, i32 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.26, i32 0, i32 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.27, i32 0, i32 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.28, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.29, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.30, i32 0, i32 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.31, i32 0, i32 0)]
@.str = [5 x i8] c"NULL\00"
@.str.1 = [7 x i8] c"SIGHUP\00"
@.str.2 = [7 x i8] c"SIGINT\00"
@.str.3 = [8 x i8] c"SIGQUIT\00"
@.str.4 = [7 x i8] c"SIGILL\00"
@.str.5 = [8 x i8] c"SIGTRAP\00"
@.str.6 = [8 x i8] c"SIGABRT\00"
@.str.7 = [7 x i8] c"SIGBUS\00"
@.str.8 = [7 x i8] c"SIGFPE\00"
@.str.9 = [8 x i8] c"SIGKILL\00"
@.str.10 = [8 x i8] c"SIGUSR1\00"
@.str.11 = [8 x i8] c"SIGSEGV\00"
@.str.12 = [8 x i8] c"SIGUSR2\00"
@.str.13 = [8 x i8] c"SIGPIPE\00"
@.str.14 = [8 x i8] c"SIGALRM\00"
@.str.15 = [8 x i8] c"SIGTERM\00"
@.str.16 = [10 x i8] c"SIGSTKFLT\00"
@.str.17 = [8 x i8] c"SIGCHLD\00"
@.str.18 = [8 x i8] c"SIGCONT\00"
@.str.19 = [8 x i8] c"SIGSTOP\00"
@.str.20 = [8 x i8] c"SIGTSTP\00"
@.str.21 = [8 x i8] c"SIGTTIN\00"
@.str.22 = [8 x i8] c"SIGTTOU\00"
@.str.23 = [7 x i8] c"SIGURG\00"
@.str.24 = [8 x i8] c"SIGXCPU\00"
@.str.25 = [8 x i8] c"SIGXFSZ\00"
@.str.26 = [10 x i8] c"SIGVTALRM\00"
@.str.27 = [8 x i8] c"SIGPROF\00"
@.str.28 = [9 x i8] c"SIGWINCH\00"
@.str.29 = [6 x i8] c"SIGIO\00"
@.str.30 = [7 x i8] c"SIGPWR\00"
@.str.31 = [7 x i8] c"SIGSYS\00"
define i8* @SignalName(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %1
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 256
br i1 %7, label %8, label %13
8: ; preds = %5
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [32 x i8*], [32 x i8*]* @SignalName.sig_map, i64 0, i64 %10
%12 = load i8*, i8** %11
br label %15
13: ; preds = %5, %1
%14 = load i8*, i8** getelementptr inbounds ([32 x i8*], [32 x i8*]* @SignalName.sig_map, i64 0, i64 0)
br label %15
15: ; preds = %13, %8
%16 = phi i8* [ %12, %8 ], [ %14, %13 ]
ret i8* %16
}

LLVM IR (-O2):
@reltable.SignalName = internal unnamed_addr constant [32 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([5 x i8]* @.str to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.1 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.3 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.4 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.5 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.6 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.7 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.8 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.9 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.10 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.11 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.12 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.13 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.14 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.15 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.16 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.17 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.18 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.19 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.20 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.21 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.22 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.23 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.24 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.25 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([10 x i8]* @.str.26 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.27 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([9 x i8]* @.str.28 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.29 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.30 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.31 to i64), i64 ptrtoint ([32 x i32]* @reltable.SignalName to i64)) to i32)]
@.str = [5 x i8] c"NULL\00"
@.str.1 = [7 x i8] c"SIGHUP\00"
@.str.2 = [7 x i8] c"SIGINT\00"
@.str.3 = [8 x i8] c"SIGQUIT\00"
@.str.4 = [7 x i8] c"SIGILL\00"
@.str.5 = [8 x i8] c"SIGTRAP\00"
@.str.6 = [8 x i8] c"SIGABRT\00"
@.str.7 = [7 x i8] c"SIGBUS\00"
@.str.8 = [7 x i8] c"SIGFPE\00"
@.str.9 = [8 x i8] c"SIGKILL\00"
@.str.10 = [8 x i8] c"SIGUSR1\00"
@.str.11 = [8 x i8] c"SIGSEGV\00"
@.str.12 = [8 x i8] c"SIGUSR2\00"
@.str.13 = [8 x i8] c"SIGPIPE\00"
@.str.14 = [8 x i8] c"SIGALRM\00"
@.str.15 = [8 x i8] c"SIGTERM\00"
@.str.16 = [10 x i8] c"SIGSTKFLT\00"
@.str.17 = [8 x i8] c"SIGCHLD\00"
@.str.18 = [8 x i8] c"SIGCONT\00"
@.str.19 = [8 x i8] c"SIGSTOP\00"
@.str.20 = [8 x i8] c"SIGTSTP\00"
@.str.21 = [8 x i8] c"SIGTTIN\00"
@.str.22 = [8 x i8] c"SIGTTOU\00"
@.str.23 = [7 x i8] c"SIGURG\00"
@.str.24 = [8 x i8] c"SIGXCPU\00"
@.str.25 = [8 x i8] c"SIGXFSZ\00"
@.str.26 = [10 x i8] c"SIGVTALRM\00"
@.str.27 = [8 x i8] c"SIGPROF\00"
@.str.28 = [9 x i8] c"SIGWINCH\00"
@.str.29 = [6 x i8] c"SIGIO\00"
@.str.30 = [7 x i8] c"SIGPWR\00"
@.str.31 = [7 x i8] c"SIGSYS\00"
define i8* @SignalName(i32 %0) {
%2 = add i32 %0, -1
%3 = icmp ult i32 %2, 255
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = zext i32 %0 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([32 x i32]* @reltable.SignalName to i8*), i64 %6)
br label %8
8: ; preds = %1, %4
%9 = phi i8* [ %7, %4 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %9
}