#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 /*<<< orphan*/ EXIT_FAILURE;
int SIGINT;
int SIGUSR1;
int SIGUSR2;
int /*<<< orphan*/ SIG_DFL;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ abort();
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ signal(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void signal_handler(int signum) {
  if (signum == SIGUSR1) {
    if (signal(SIGUSR1, SIG_DFL) == SIG_ERR) {
      fprintf(stderr, "Err.(%s), can't catch SIGUSR1\n", strerror(errno));
      exit(EXIT_FAILURE);
    }
    printf("Got signal: SIGUSR1\n");
  } else if (signum == SIGUSR2)
    printf("Got Signal: SIGUSR2\n");
  else if (signum == SIGINT)
    printf("Got signal: SIGINT\n");
  else
    abort();
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%eax
jne    11ef <signal_handler+0x8f>
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
mov    0x2e2d(%rip),%rcx
cmp    (%rcx),%rax
jne    11de <signal_handler+0x7e>
mov    0x2e25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x8(%rbp),%edi
mov    %rax,%rdx
lea    0xe35(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
lea    0xe3a(%rip),%rdi
call   1040 <printf@plt>
jmp    1246 <signal_handler+0xe6>
mov    -0x4(%rbp),%eax
mov    0x2dc7(%rip),%rcx
cmp    (%rcx),%eax
jne    1212 <signal_handler+0xb2>
lea    0xe2c(%rip),%rdi
call   1040 <printf@plt>
jmp    1241 <signal_handler+0xe1>
mov    -0x4(%rbp),%eax
mov    0x2dc4(%rip),%rcx
cmp    (%rcx),%eax
jne    1235 <signal_handler+0xd5>
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
jmp    123c <signal_handler+0xdc>
mov    $0x0,%al
call   1030 <abort@plt>
jmp    1241 <signal_handler+0xe1>
jmp    1246 <signal_handler+0xe6>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %rbx
mov    0x2e80(%rip),%rax
cmp    %edi,(%rax)
jne    1193 <signal_handler+0x33>
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
mov    0x2e47(%rip),%rcx
cmp    (%rcx),%rax
je     11c3 <signal_handler+0x63>
lea    0xeb9(%rip),%rdi
pop    %rbx
jmp    1040 <puts@plt>
mov    0x2e26(%rip),%rax
cmp    %edi,(%rax)
jne    11ab <signal_handler+0x4b>
lea    0xe8d(%rip),%rdi
pop    %rbx
jmp    1040 <puts@plt>
mov    0x2e2e(%rip),%rax
cmp    %edi,(%rax)
jne    11f9 <signal_handler+0x99>
lea    0xe62(%rip),%rdi
pop    %rbx
jmp    1040 <puts@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%ebx
mov    0x2de5(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe1f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@SIGUSR1 = global i32 0
@SIG_DFL = global i32 0
@SIG_ERR = global i64 0
@stderr = global i32 0
@.str = [31 x i8] c"Err.(%s), can't catch SIGUSR1\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [21 x i8] c"Got signal: SIGUSR1\0A\00"
@SIGUSR2 = global i32 0
@.str.2 = [21 x i8] c"Got Signal: SIGUSR2\0A\00"
@SIGINT = global i32 0
@.str.3 = [20 x i8] c"Got signal: SIGINT\0A\00"
define void @signal_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGUSR1
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %21
6: ; preds = %1
%7 = load i32, i32* @SIGUSR1
%8 = load i32, i32* @SIG_DFL
%9 = call i64 @signal(i32 %7, i32 %8)
%10 = load i64, i64* @SIG_ERR
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %19
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %6
%20 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %37
21: ; preds = %1
%22 = load i32, i32* %2
%23 = load i32, i32* @SIGUSR2
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %36
27: ; preds = %21
%28 = load i32, i32* %2
%29 = load i32, i32* @SIGINT
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %33
31: ; preds = %27
%32 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %35
33: ; preds = %27
%34 = call i32 (...) @abort()
unreachable
35: ; preds = %31
br label %36
36: ; preds = %35, %25
br label %37
37: ; preds = %36, %19
ret void
}

LLVM IR (-O2):
@SIGUSR1 = global i32 0
@SIG_DFL = global i32 0
@SIG_ERR = global i64 0
@stderr = global i32 0
@.str = [31 x i8] c"Err.(%s), can't catch SIGUSR1\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@SIGUSR2 = global i32 0
@SIGINT = global i32 0
@str = [19 x i8] c"Got signal: SIGINT\00"
@str.4 = [20 x i8] c"Got Signal: SIGUSR2\00"
@str.5 = [20 x i8] c"Got signal: SIGUSR1\00"
define void @signal_handler(i32 %0) {
%2 = load i32, i32* @SIGUSR1
%3 = icmp eq i32 %2, %0
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = load i32, i32* @SIG_DFL
%6 = tail call i64 @signal(i32 %0, i32 %5)
%7 = load i64, i64* @SIG_ERR
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %24
9: ; preds = %4
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = tail call i8* @strerror(i32 %11)
%13 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
%17 = load i32, i32* @SIGUSR2
%18 = icmp eq i32 %17, %0
br i1 %18, label %24, label %19
19: ; preds = %16
%20 = load i32, i32* @SIGINT
%21 = icmp eq i32 %20, %0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = tail call i32 (...) @abort()
unreachable
24: ; preds = %19, %16, %4
%25 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.5, i64 0, i64 0), %4 ], [ getelementptr inbounds ([20 x i8], [20 x i8]* @str.4, i64 0, i64 0), %16 ], [ getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), %19 ]
%26 = tail call i32 @puts(i8* dereferenceable(1) %25)
ret void
}