#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*/ _(char const *);
scalar_t__ __asprintf(char **, int /*<<< orphan*/, char const *, char const *,
                      int);
int /*<<< orphan*/ __fxprintf(int /*<<< orphan*/ *, char *, char const *, ...);
char **_sys_siglist;
int /*<<< orphan*/ free(char *);
void psignal(int sig, const char *s) {
  const char *colon, *desc;
  if (s == NULL || *s == '\0')
    s = colon = "";
  else
    colon = ": ";
  if (sig >= 0 && sig < NSIG && (desc = _sys_siglist[sig]) != NULL)
    (void)__fxprintf(NULL, "%s%s%s\n", s, colon, _(desc));
  else {
    char *buf;
    if (__asprintf(&buf, _("%s%sUnknown signal %d\n"), s, colon, sig) < 0)
      (void)__fxprintf(NULL, "%s%s%s\n", s, colon, _("Unknown signal"));
    else {
      (void)__fxprintf(NULL, "%s", buf);
      free(buf);
    }
  }
}


x86 assembly (clang, -O0):
<psignal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     116a <psignal+0x2a>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1185 <psignal+0x45>
lea    0xeb0(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xea5(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    1190 <psignal+0x50>
lea    0xe74(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     1207 <psignal+0xc7>
mov    -0x4(%rbp),%eax
mov    0x2e34(%rip),%rcx
cmp    (%rcx),%eax
jge    1207 <psignal+0xc7>
mov    0x2e35(%rip),%rax
mov    (%rax),%rax
movslq -0x4(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1207 <psignal+0xc7>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <_@plt>
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    %eax,%r8d
xor    %eax,%eax
mov    %eax,%edi
lea    0xe08(%rip),%rsi
mov    $0x0,%al
call   1050 <__fxprintf@plt>
jmp    1296 <psignal+0x156>
lea    0xdfd(%rip),%rdi
call   1060 <_@plt>
mov    %eax,%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x4(%rbp),%r8d
lea    -0x28(%rbp),%rdi
call   1030 <__asprintf@plt>
cmp    $0x0,%rax
jge    1272 <psignal+0x132>
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xdd7(%rip),%rdi
call   1060 <_@plt>
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    %eax,%r8d
xor    %eax,%eax
mov    %eax,%edi
lea    0xd9d(%rip),%rsi
mov    $0x0,%al
call   1050 <__fxprintf@plt>
jmp    1291 <psignal+0x151>
mov    -0x28(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   1050 <__fxprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
jmp    1296 <psignal+0x156>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psignal>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
lea    0xed0(%rip),%rbx
test   %rsi,%rsi
je     116e <psignal+0x2e>
cmpb   $0x0,(%rsi)
mov    %rbx,%r14
je     1168 <psignal+0x28>
lea    0xe9b(%rip),%rbx
mov    %rsi,%r14
test   %ebp,%ebp
jns    1175 <psignal+0x35>
jmp    11bb <psignal+0x7b>
mov    %rbx,%r14
test   %ebp,%ebp
js     11bb <psignal+0x7b>
mov    0x2e5c(%rip),%rax
cmp    %ebp,(%rax)
jle    11bb <psignal+0x7b>
mov    0x2e61(%rip),%rax
mov    (%rax),%rax
mov    %ebp,%ecx
mov    (%rax,%rcx,8),%rdi
test   %rdi,%rdi
je     11bb <psignal+0x7b>
call   1060 <_@plt>
lea    0xe62(%rip),%rsi
xor    %edi,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <__fxprintf@plt>
lea    0xe49(%rip),%rdi
call   1060 <_@plt>
lea    0x8(%rsp),%rdi
mov    %eax,%esi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %ebp,%r8d
call   1030 <__asprintf@plt>
test   %rax,%rax
js     1202 <psignal+0xc2>
mov    0x8(%rsp),%rdx
lea    0xe44(%rip),%rsi
xor    %edi,%edi
xor    %eax,%eax
call   1050 <__fxprintf@plt>
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
jmp    1227 <psignal+0xe7>
lea    0xe19(%rip),%rdi
call   1060 <_@plt>
lea    0xdee(%rip),%rsi
xor    %edi,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <__fxprintf@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c": \00"
@NSIG = global i32 0
@_sys_siglist = global i8** null
@.str.2 = [8 x i8] c"%s%s%s\0A\00"
@.str.3 = [23 x i8] c"%s%sUnknown signal %d\0A\00"
@.str.4 = [15 x i8] c"Unknown signal\00"
@.str.5 = [3 x i8] c"%s\00"
define void @psignal(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10, %2
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %5
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), i8** %4
br label %17
16: ; preds = %10
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %5
br label %17
17: ; preds = %16, %15
%18 = load i32, i32* %3
%19 = icmp sge i32 %18, 0
br i1 %19, label %20, label %37
20: ; preds = %17
%21 = load i32, i32* %3
%22 = load i32, i32* @NSIG
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %37
24: ; preds = %20
%25 = load i8**, i8*** @_sys_siglist
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8*, i8** %25, i64 %27
%29 = load i8*, i8** %28
store i8* %29, i8** %6
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %37
31: ; preds = %24
%32 = load i8*, i8** %4
%33 = load i8*, i8** %5
%34 = load i8*, i8** %6
%35 = call i32 @_(i8* %34)
%36 = call i32 (i32*, i8*, i8*, ...) @__fxprintf(i32* null, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %32, i8* %33, i32 %35)
br label %55
37: ; preds = %24, %20, %17
%38 = call i32 @_(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%39 = load i8*, i8** %4
%40 = load i8*, i8** %5
%41 = load i32, i32* %3
%42 = call i64 @__asprintf(i8** %7, i32 %38, i8* %39, i8* %40, i32 %41)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %49
44: ; preds = %37
%45 = load i8*, i8** %4
%46 = load i8*, i8** %5
%47 = call i32 @_(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 (i32*, i8*, i8*, ...) @__fxprintf(i32* null, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %45, i8* %46, i32 %47)
br label %54
49: ; preds = %37
%50 = load i8*, i8** %7
%51 = call i32 (i32*, i8*, i8*, ...) @__fxprintf(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %50)
%52 = load i8*, i8** %7
%53 = call i32 @free(i8* %52)
br label %54
54: ; preds = %49, %44
br label %55
55: ; preds = %54, %31
ret void
}

LLVM IR (-O2):
@.str = [1 x i8] zeroinitializer
@.str.1 = [3 x i8] c": \00"
@NSIG = global i32 0
@_sys_siglist = global i8** null
@.str.2 = [8 x i8] c"%s%s%s\0A\00"
@.str.3 = [23 x i8] c"%s%sUnknown signal %d\0A\00"
@.str.4 = [15 x i8] c"Unknown signal\00"
@.str.5 = [3 x i8] c"%s\00"
define void @psignal(i32 %0, i8* %1) {
%3 = alloca i8*
%4 = icmp eq i8* %1, null
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, 0
br i1 %7, label %9, label %8
8: ; preds = %5
br label %9
9: ; preds = %2, %5, %8
%10 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), %8 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
%11 = phi i8* [ %1, %8 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0), %2 ]
%12 = icmp sgt i32 %0, -1
%13 = load i32, i32* @NSIG
%14 = icmp sgt i32 %13, %0
%15 = select i1 %12, i1 %14, i1 false
br i1 %15, label %16, label %25
16: ; preds = %9
%17 = load i8**, i8*** @_sys_siglist
%18 = zext i32 %0 to i64
%19 = getelementptr inbounds i8*, i8** %17, i64 %18
%20 = load i8*, i8** %19
%21 = icmp eq i8* %20, null
br i1 %21, label %25, label %22
22: ; preds = %16
%23 = tail call i32 @_(i8* %20)
%24 = tail call i32 (i32*, i8*, i8*, ...) @__fxprintf(i32* null, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* %10, i32 %23)
br label %39
25: ; preds = %16, %9
%26 = bitcast i8** %3 to i8*
%27 = tail call i32 @_(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%28 = call i64 @__asprintf(i8** %3, i32 %27, i8* %11, i8* %10, i32 %0)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = call i32 @_(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 (i32*, i8*, i8*, ...) @__fxprintf(i32* null, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %11, i8* %10, i32 %31)
br label %38
33: ; preds = %25
%34 = load i8*, i8** %3
%35 = call i32 (i32*, i8*, i8*, ...) @__fxprintf(i32* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %3
%37 = call i32 @free(i8* %36)
br label %38
38: ; preds = %33, %30
br label %39
39: ; preds = %38, %22
ret void
}