#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 */
struct sigaction {
  void (*sa_handler)(int);
  int /*<<< orphan*/ sa_mask;
};
typedef int /*<<< orphan*/ sigset_t;
typedef int /*<<< orphan*/ action;

/* Variables and functions */
int /*<<< orphan*/ SIGABRT;
int /*<<< orphan*/ SIGILL;
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ SIGPIPE;
int /*<<< orphan*/ SIGQUIT;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ memset(struct sigaction *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sigaction(int /*<<< orphan*/, struct sigaction *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ sigaddset(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void sigtrapSetup(void(sigtrap_function)(int)) {
  sigset_t sig_nset;
  struct sigaction action;
  sigemptyset(&sig_nset);
  sigaddset(&sig_nset, SIGABRT);
  sigaddset(&sig_nset, SIGILL);
  sigaddset(&sig_nset, SIGINT);
  sigaddset(&sig_nset, SIGPIPE);
  sigaddset(&sig_nset, SIGTERM);
  sigaddset(&sig_nset, SIGQUIT);
  memset(&action, 0, sizeof(action));
  action.sa_handler = sigtrap_function;
  action.sa_mask = sig_nset;
  sigaction(SIGABRT, &action, NULL);
  sigaction(SIGINT, &action, NULL);
  sigaction(SIGILL, &action, NULL);
  sigaction(SIGPIPE, &action, NULL);
  sigaction(SIGTERM, &action, NULL);
  sigaction(SIGQUIT, &action, NULL);
}


x86 assembly (clang, -O0):
<sigtrapSetup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <sigemptyset@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1060 <sigaddset@plt>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1060 <sigaddset@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1060 <sigaddset@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1060 <sigaddset@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1060 <sigaddset@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
lea    -0xc(%rbp),%rdi
call   1060 <sigaddset@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    0x2d98(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigtrapSetup>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
lea    0x4(%rsp),%rbx
mov    %rbx,%rdi
call   1050 <sigemptyset@plt>
mov    0x2e53(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
call   1060 <sigaddset@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <sigaddset@plt>
mov    0x2e60(%rip),%r12
mov    (%r12),%esi
mov    %rbx,%rdi
call   1060 <sigaddset@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1060 <sigaddset@plt>
mov    0x2e34(%rip),%r13
mov    0x0(%r13),%esi
mov    %rbx,%rdi
call   1060 <sigaddset@plt>
mov    0x2e19(%rip),%rbp
mov    0x0(%rbp),%esi
mov    %rbx,%rdi
call   1060 <sigaddset@plt>
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <memset@plt>
mov    %r14,0x8(%rsp)
mov    0x4(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    (%r15),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
mov    (%r12),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
mov    0x0(%r13),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i32 }
@SIGABRT = global i32 0
@SIGILL = global i32 0
@SIGINT = global i32 0
@SIGPIPE = global i32 0
@SIGTERM = global i32 0
@SIGQUIT = global i32 0
define void @sigtrapSetup(void (i32)* %0) {
%2 = alloca void (i32)*
%3 = alloca i32
%4 = alloca %struct.sigaction
store void (i32)* %0, void (i32)** %2
%5 = call i32 @sigemptyset(i32* %3)
%6 = load i32, i32* @SIGABRT
%7 = call i32 @sigaddset(i32* %3, i32 %6)
%8 = load i32, i32* @SIGILL
%9 = call i32 @sigaddset(i32* %3, i32 %8)
%10 = load i32, i32* @SIGINT
%11 = call i32 @sigaddset(i32* %3, i32 %10)
%12 = load i32, i32* @SIGPIPE
%13 = call i32 @sigaddset(i32* %3, i32 %12)
%14 = load i32, i32* @SIGTERM
%15 = call i32 @sigaddset(i32* %3, i32 %14)
%16 = load i32, i32* @SIGQUIT
%17 = call i32 @sigaddset(i32* %3, i32 %16)
%18 = call i32 @memset(%struct.sigaction* %4, i32 0, i32 16)
%19 = load void (i32)*, void (i32)** %2
%20 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i32 0, i32 0
store void (i32)* %19, void (i32)** %20
%21 = load i32, i32* %3
%22 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %4, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @SIGABRT
%24 = call i32 @sigaction(i32 %23, %struct.sigaction* %4, i32* null)
%25 = load i32, i32* @SIGINT
%26 = call i32 @sigaction(i32 %25, %struct.sigaction* %4, i32* null)
%27 = load i32, i32* @SIGILL
%28 = call i32 @sigaction(i32 %27, %struct.sigaction* %4, i32* null)
%29 = load i32, i32* @SIGPIPE
%30 = call i32 @sigaction(i32 %29, %struct.sigaction* %4, i32* null)
%31 = load i32, i32* @SIGTERM
%32 = call i32 @sigaction(i32 %31, %struct.sigaction* %4, i32* null)
%33 = load i32, i32* @SIGQUIT
%34 = call i32 @sigaction(i32 %33, %struct.sigaction* %4, i32* null)
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i32 }
@SIGABRT = global i32 0
@SIGILL = global i32 0
@SIGINT = global i32 0
@SIGPIPE = global i32 0
@SIGTERM = global i32 0
@SIGQUIT = global i32 0
define void @sigtrapSetup(void (i32)* %0) {
%2 = alloca i32
%3 = alloca %struct.sigaction
%4 = bitcast i32* %2 to i8*
%5 = bitcast %struct.sigaction* %3 to i8*
%6 = call i32 @sigemptyset(i32* %2)
%7 = load i32, i32* @SIGABRT
%8 = call i32 @sigaddset(i32* %2, i32 %7)
%9 = load i32, i32* @SIGILL
%10 = call i32 @sigaddset(i32* %2, i32 %9)
%11 = load i32, i32* @SIGINT
%12 = call i32 @sigaddset(i32* %2, i32 %11)
%13 = load i32, i32* @SIGPIPE
%14 = call i32 @sigaddset(i32* %2, i32 %13)
%15 = load i32, i32* @SIGTERM
%16 = call i32 @sigaddset(i32* %2, i32 %15)
%17 = load i32, i32* @SIGQUIT
%18 = call i32 @sigaddset(i32* %2, i32 %17)
%19 = call i32 @memset(%struct.sigaction* %3, i32 0, i32 16)
%20 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 0
store void (i32)* %0, void (i32)** %20
%21 = load i32, i32* %2
%22 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i64 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @SIGABRT
%24 = call i32 @sigaction(i32 %23, %struct.sigaction* %3, i32* null)
%25 = load i32, i32* @SIGINT
%26 = call i32 @sigaction(i32 %25, %struct.sigaction* %3, i32* null)
%27 = load i32, i32* @SIGILL
%28 = call i32 @sigaction(i32 %27, %struct.sigaction* %3, i32* null)
%29 = load i32, i32* @SIGPIPE
%30 = call i32 @sigaction(i32 %29, %struct.sigaction* %3, i32* null)
%31 = load i32, i32* @SIGTERM
%32 = call i32 @sigaction(i32 %31, %struct.sigaction* %3, i32* null)
%33 = load i32, i32* @SIGQUIT
%34 = call i32 @sigaction(i32 %33, %struct.sigaction* %3, i32* null)
ret void
}