#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*/ SIGQUIT;
int /*<<< orphan*/ SIG_DFL;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
void handler(int sig_num) {
  printf("Segnale SIGQUIT catturato\n");
  if (signal(SIGQUIT, SIG_DFL) == SIG_ERR) {
    fprintf(stderr, "Err.(%s) signal(SIGQUIT) failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe9e(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%rax
jne    11c8 <handler+0x78>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x8(%rbp),%edi
mov    %rax,%rdx
lea    0xe66(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler>:
push   %rbx
lea    0xec9(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%rax
je     1182 <handler+0x32>
pop    %rbx
ret
mov    0x2e4f(%rip),%rax
mov    (%rax),%ebx
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe60(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"Segnale SIGQUIT catturato\0A\00"
@SIGQUIT = global i32 0
@SIG_DFL = global i32 0
@SIG_ERR = global i64 0
@stderr = global i32 0
@.str.1 = [33 x i8] c"Err.(%s) signal(SIGQUIT) failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define void @handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @SIGQUIT
%5 = load i32, i32* @SIG_DFL
%6 = call i64 @signal(i32 %4, i32 %5)
%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 ([33 x i8], [33 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):
@SIGQUIT = global i32 0
@SIG_DFL = global i32 0
@SIG_ERR = global i64 0
@stderr = global i32 0
@.str.1 = [33 x i8] c"Err.(%s) signal(SIGQUIT) failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@str = [26 x i8] c"Segnale SIGQUIT catturato\00"
define void @handler(i32 %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%3 = load i32, i32* @SIGQUIT
%4 = load i32, i32* @SIG_DFL
%5 = tail call i64 @signal(i32 %3, i32 %4)
%6 = load i64, i64* @SIG_ERR
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
ret void
}