#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
unsigned int NSIG;
int /*<<< orphan*/ fmtstr(char *, int, char *, int);
scalar_t__ *sys_siglist;
char *strsignal(int sig) {
  static char buf[19];
  if ((unsigned)sig < NSIG && sys_siglist[sig])
    return (char *)sys_siglist[sig];
  fmtstr(buf, sizeof(buf), "Signal %d", sig);
  return buf;
}


x86 assembly (clang, -O0):
<strsignal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    0x2eb3(%rip),%rcx
cmp    (%rcx),%eax
jae    1161 <strsignal+0x51>
mov    0x2eb4(%rip),%rax
mov    (%rax),%rax
movslq -0xc(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1161 <strsignal+0x51>
mov    0x2e9b(%rip),%rax
mov    (%rax),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x8(%rbp)
jmp    1187 <strsignal+0x77>
mov    -0xc(%rbp),%ecx
lea    0x2ed5(%rip),%rdi
mov    $0x13,%esi
lea    0xe89(%rip),%rdx
call   1030 <fmtstr@plt>
lea    0x2ebd(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<strsignal>:
push   %rbx
mov    %edi,%ecx
mov    0x2ebe(%rip),%rax
cmp    %edi,(%rax)
jbe    1134 <strsignal+0x24>
mov    0x2ec3(%rip),%rax
mov    (%rax),%rax
movslq %ecx,%rdx
mov    (%rax,%rdx,8),%rbx
test   %rbx,%rbx
jne    114f <strsignal+0x3f>
lea    0x2f05(%rip),%rbx
lea    0xebe(%rip),%rdx
mov    %rbx,%rdi
mov    $0x13,%esi
call   1030 <fmtstr@plt>
mov    %rbx,%rax
pop    %rbx
ret

LLVM IR (-O0):
@strsignal.buf = internal global [19 x i8] zeroinitializer
@NSIG = global i32 0
@sys_siglist = global i64* null
@.str = [10 x i8] c"Signal %d\00"
define i8* @strsignal(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
%5 = load i32, i32* @NSIG
%6 = icmp ult i32 %4, %5
br i1 %6, label %7, label %21
7: ; preds = %1
%8 = load i64*, i64** @sys_siglist
%9 = load i32, i32* %3
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i64, i64* %8, i64 %10
%12 = load i64, i64* %11
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %21
14: ; preds = %7
%15 = load i64*, i64** @sys_siglist
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i64, i64* %15, i64 %17
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to i8*
store i8* %20, i8** %2
br label %24
21: ; preds = %7, %1
%22 = load i32, i32* %3
%23 = call i32 @fmtstr(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @strsignal.buf, i64 0, i64 0), i32 19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %22)
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @strsignal.buf, i64 0, i64 0), i8** %2
br label %24
24: ; preds = %21, %14
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@strsignal.buf = internal global [19 x i8] zeroinitializer
@NSIG = global i32 0
@sys_siglist = global i64* null
@.str = [10 x i8] c"Signal %d\00"
define i8* @strsignal(i32 %0) {
%2 = load i32, i32* @NSIG
%3 = icmp ugt i32 %2, %0
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = load i64*, i64** @sys_siglist
%6 = sext i32 %0 to i64
%7 = getelementptr inbounds i64, i64* %5, i64 %6
%8 = load i64, i64* %7
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %4
%11 = inttoptr i64 %8 to i8*
br label %14
12: ; preds = %4, %1
%13 = tail call i32 @fmtstr(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @strsignal.buf, i64 0, i64 0), i32 19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %0)
br label %14
14: ; preds = %12, %10
%15 = phi i8* [ %11, %10 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @strsignal.buf, i64 0, i64 0), %12 ]
ret i8* %15
}