#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_sigaction)(int, int /*<<< orphan*/ *, void *);
  int /*<<< orphan*/ sa_mask;
  int /*<<< orphan*/ sa_flags;
};
typedef int /*<<< orphan*/ siginfo_t;

/* Variables and functions */
int /*<<< orphan*/ SA_SIGINFO;
int /*<<< orphan*/ SIGSEGV;
int sigaction(int /*<<< orphan*/, struct sigaction *, int /*<<< orphan*/ *);
int /*<<< orphan*/ sigemptyset(int /*<<< orphan*/ *);
int set_sigsegv() {
  struct sigaction action;
  void linux_segv(int signo, siginfo_t *info, void *context);
  action.sa_flags = SA_SIGINFO;
  action.sa_sigaction = linux_segv;
  sigemptyset(&action.sa_mask);
  return sigaction(SIGSEGV, &action, NULL);
}


x86 assembly (clang, -O0):
<set_sigsegv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    0x2e9d(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
add    $0x8,%rdi
call   1040 <sigemptyset@plt>
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigaction@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_sigsegv>:
sub    $0x18,%rsp
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    0x2ea0(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0x10(%rsp),%rdi
call   1040 <sigemptyset@plt>
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigaction@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sigaction = type { void (i32, i32*, i8*)*, i32, i32 }
@SA_SIGINFO = global i32 0
@SIGSEGV = global i32 0
define i32 @set_sigsegv() {
%1 = alloca %struct.sigaction
%2 = load i32, i32* @SA_SIGINFO
%3 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 2
store i32 %2, i32* %3
%4 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 0
store void (i32, i32*, i8*)* @linux_segv, void (i32, i32*, i8*)** %4
%5 = getelementptr inbounds %struct.sigaction, %struct.sigaction* %1, i32 0, i32 1
%6 = call i32 @sigemptyset(i32* %5)
%7 = load i32, i32* @SIGSEGV
%8 = call i32 @sigaction(i32 %7, %struct.sigaction* %1, i32* null)
ret i32 %8
}

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