#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*/ SIGQUIT;
int /*<<< orphan*/ SIG_DFL;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ signal(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void sig_handler(int signo) {
  printf("SIG_QUIT caught, %d\n", signo);
  if (signal(SIGQUIT, SIG_DFL) == SIG_ERR)
    fprintf(stderr, "cannt reset SIGQUIT\n");
}


x86 assembly (clang, -O0):
<sig_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xebb(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e97(%rip),%rax
mov    (%rax),%edi
mov    0x2e6e(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%rax
jne    1186 <sig_handler+0x56>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    0xe94(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_handler>:
push   %rax
mov    %edi,%esi
lea    0xec6(%rip),%rdi
call   1030 <printf@plt>
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
jne    1178 <sig_handler+0x48>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xea3(%rip),%rsi
pop    %rax
jmp    1050 <fprintf@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [21 x i8] c"SIG_QUIT caught, %d\0A\00"
@SIGQUIT = global i32 0
@SIG_DFL = global i32 0
@SIG_ERR = global i64 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"cannt reset SIGQUIT\0A\00"
define void @sig_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* @SIGQUIT
%6 = load i32, i32* @SIG_DFL
%7 = call i64 @signal(i32 %5, i32 %6)
%8 = load i64, i64* @SIG_ERR
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"SIG_QUIT caught, %d\0A\00"
@SIGQUIT = global i32 0
@SIG_DFL = global i32 0
@SIG_ERR = global i64 0
@stderr = global i32 0
@.str.1 = [21 x i8] c"cannt reset SIGQUIT\0A\00"
define void @sig_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* @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 %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %8, %1
ret void
}