#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 */

/* Variables and functions */
int NSIG;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ _write(int /*<<< orphan*/, char const *, int);
int strlen(char const *);
char **sys_siglist;
void psignal(int sig, const char *s) {
  const char *c;
  if (sig >= 0 && sig < NSIG)
    c = sys_siglist[sig];
  else
    c = "Unknown signal";
  if (s != NULL && *s != '\0') {
    (void)_write(STDERR_FILENO, s, strlen(s));
    (void)_write(STDERR_FILENO, ": ", 2);
  }
  (void)_write(STDERR_FILENO, c, strlen(c));
  (void)_write(STDERR_FILENO, "\n", 1);
}


x86 assembly (clang, -O0):
<psignal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1166 <psignal+0x46>
mov    -0x4(%rbp),%eax
mov    0x2e8d(%rip),%rcx
cmp    (%rcx),%eax
jge    1166 <psignal+0x46>
mov    0x2e96(%rip),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
jmp    1171 <psignal+0x51>
lea    0xe93(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d1 <psignal+0xb1>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11d1 <psignal+0xb1>
mov    0x2e45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
call   1040 <_write@plt>
mov    0x2e1a(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
mov    $0x2,%edx
call   1040 <_write@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
call   1040 <_write@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
mov    $0x1,%edx
call   1040 <_write@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psignal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
lea    0xecf(%rip),%r14
test   %edi,%edi
js     1150 <psignal+0x30>
mov    0x2e94(%rip),%rax
cmp    %edi,(%rax)
jle    1150 <psignal+0x30>
mov    0x2ea1(%rip),%rax
mov    (%rax),%rax
mov    %edi,%ecx
mov    (%rax,%rcx,8),%r14
test   %rbx,%rbx
je     118c <psignal+0x6c>
cmpb   $0x0,(%rbx)
je     118c <psignal+0x6c>
mov    0x2e77(%rip),%r15
mov    (%r15),%ebp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <_write@plt>
mov    (%r15),%edi
lea    0xe8d(%rip),%rsi
mov    $0x2,%edx
call   1040 <_write@plt>
mov    0x2e45(%rip),%rbp
mov    0x0(%rbp),%ebx
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <_write@plt>
mov    0x0(%rbp),%edi
lea    0xe5e(%rip),%rsi
mov    $0x1,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <_write@plt>

LLVM IR (-O0):
@NSIG = global i32 0
@sys_siglist = global i8** null
@.str = [15 x i8] c"Unknown signal\00"
@STDERR_FILENO = global i32 0
@.str.1 = [3 x i8] c": \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @psignal(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = load i32, i32* %3
%10 = load i32, i32* @NSIG
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %18
12: ; preds = %8
%13 = load i8**, i8*** @sys_siglist
%14 = load i32, i32* %3
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
store i8* %17, i8** %5
br label %19
18: ; preds = %8, %2
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8** %5
br label %19
19: ; preds = %18, %12
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %35
22: ; preds = %19
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %22
%28 = load i32, i32* @STDERR_FILENO
%29 = load i8*, i8** %4
%30 = load i8*, i8** %4
%31 = call i32 @strlen(i8* %30)
%32 = call i32 @_write(i32 %28, i8* %29, i32 %31)
%33 = load i32, i32* @STDERR_FILENO
%34 = call i32 @_write(i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %35
35: ; preds = %27, %22, %19
%36 = load i32, i32* @STDERR_FILENO
%37 = load i8*, i8** %5
%38 = load i8*, i8** %5
%39 = call i32 @strlen(i8* %38)
%40 = call i32 @_write(i32 %36, i8* %37, i32 %39)
%41 = load i32, i32* @STDERR_FILENO
%42 = call i32 @_write(i32 %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
ret void
}

LLVM IR (-O2):
@NSIG = global i32 0
@sys_siglist = global i8** null
@.str = [15 x i8] c"Unknown signal\00"
@STDERR_FILENO = global i32 0
@.str.1 = [3 x i8] c": \00"
@.str.2 = [2 x i8] c"\0A\00"
define void @psignal(i32 %0, i8* %1) {
%3 = icmp sgt i32 %0, -1
%4 = load i32, i32* @NSIG
%5 = icmp sgt i32 %4, %0
%6 = select i1 %3, i1 %5, i1 false
br i1 %6, label %7, label %12
7: ; preds = %2
%8 = load i8**, i8*** @sys_siglist
%9 = zext i32 %0 to i64
%10 = getelementptr inbounds i8*, i8** %8, i64 %9
%11 = load i8*, i8** %10
br label %12
12: ; preds = %2, %7
%13 = phi i8* [ %11, %7 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), %2 ]
%14 = icmp eq i8* %1, null
br i1 %14, label %24, label %15
15: ; preds = %12
%16 = load i8, i8* %1
%17 = icmp eq i8 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = load i32, i32* @STDERR_FILENO
%20 = tail call i32 @strlen(i8* %1)
%21 = tail call i32 @_write(i32 %19, i8* %1, i32 %20)
%22 = load i32, i32* @STDERR_FILENO
%23 = tail call i32 @_write(i32 %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 2)
br label %24
24: ; preds = %18, %15, %12
%25 = load i32, i32* @STDERR_FILENO
%26 = tail call i32 @strlen(i8* %13)
%27 = tail call i32 @_write(i32 %25, i8* %13, i32 %26)
%28 = load i32, i32* @STDERR_FILENO
%29 = tail call i32 @_write(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
ret void
}