#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;
  scalar_t__ sa_flags;
};

/* Variables and functions */
int /*<<< orphan*/ SIGABRT;
int /*<<< orphan*/ ignore_stderr();
int /*<<< orphan*/ sigaction(int /*<<< orphan*/, struct sigaction *,
                             int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
void __attribute__((unused)) set_fortify_handler(void (*handler)(int sig)) {
  struct sigaction sa;
  sa.sa_handler = handler;
  sa.sa_flags = 0;
  sigemptyset(&sa.sa_mask);
  sigaction(SIGABRT, &sa, NULL);
  ignore_stderr();
}


x86 assembly (clang, -O0):
<set_fortify_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
add    $0x8,%rdi
call   1040 <sigemptyset@plt>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
mov    $0x0,%al
call   1050 <ignore_stderr@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_fortify_handler>:
sub    $0x18,%rsp
mov    %rdi,(%rsp)
movq   $0x0,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
xor    %eax,%eax
call   1050 <ignore_stderr@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32)*, i32, i64 }
@SIGABRT = global i32 0
define void @set_fortify_handler(void (i32)* %0) {
%2 = alloca void (i32)*
%3 = alloca %struct.sigaction
store void (i32)* %0, void (i32)** %2
%4 = load void (i32)*, void (i32)** %2
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 0
store void (i32)* %4, void (i32)** %5
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 2
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %3, i32 0, i32 1
%8 = call i32 @sigemptyset(i32* %7)
%9 = load i32, i32* @SIGABRT
%10 = call i32 @sigaction(i32 %9, %struct.sigaction* %3, i32* null)
%11 = call i32 (...) @ignore_stderr()
ret void
}

LLVM IR (-O2):
%struct.sigaction = type { void (i32)*, i32, i64 }
@SIGABRT = global i32 0
define void @set_fortify_handler(void (i32)* %0) {
%2 = alloca %struct.sigaction
%3 = bitcast %struct.sigaction* %2 to i8*
%4 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 0
store void (i32)* %0, void (i32)** %4
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 2
store i64 0, i64* %5
%6 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %2, i64 0, i32 1
%7 = call i32 @sigemptyset(i32* %6)
%8 = load i32, i32* @SIGABRT
%9 = call i32 @sigaction(i32 %8, %struct.sigaction* %2, i32* null)
%10 = call i32 (...) @ignore_stderr()
ret void
}