#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 /*<<< orphan*/ SIGUSR1;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ signal(int /*<<< orphan*/, void (*)(int));
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void signal_handler(int signum) {
  printf("Ricevuto segnale %d\n", signum);
  if (signal(SIGUSR1, signal_handler) == SIG_ERR) {
    fprintf(stderr, "Err.(%s) signal() main failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e77(%rip),%rax
mov    (%rax),%edi
mov    0x2e56(%rip),%rsi
call   1040 <signal@plt>
mov    0x2e42(%rip),%rcx
cmp    (%rcx),%rax
jne    11c9 <signal_handler+0x79>
mov    0x2e42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x8(%rbp),%edi
mov    %rax,%rdx
lea    0xe5f(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %rbx
mov    %edi,%esi
lea    0xea6(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    0x2e61(%rip),%rsi
call   1040 <signal@plt>
mov    0x2e4d(%rip),%rcx
cmp    (%rcx),%rax
je     1182 <signal_handler+0x32>
pop    %rbx
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%ebx
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe75(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Ricevuto segnale %d\0A\00"
@SIGUSR1 = global i32 0
@SIG_ERR = global i64 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"Err.(%s) signal() main failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @signal_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* @SIGUSR1
%6 = call i64 @signal(i32 %5, void (i32)* @signal_handler)
%7 = load i64, i64* @SIG_ERR
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* @errno
%12 = call i8* @strerror(i32 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"Ricevuto segnale %d\0A\00"
@SIGUSR1 = global i32 0
@SIG_ERR = global i64 0
@stderr = global i32 0
@.str.1 = [31 x i8] c"Err.(%s) signal() main failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @signal_handler(i32 %0) {
%2 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = load i32, i32* @SIGUSR1
%4 = tail call i64 @signal(i32 %3, void (i32)* @signal_handler)
%5 = load i64, i64* @SIG_ERR
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %14
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = tail call i8* @strerror(i32 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
ret void
}