#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ ucontext_t;
struct TYPE_3__ {
  int si_errno;
  int si_code;
  int si_addr;
};
typedef TYPE_1__ siginfo_t;

/* Variables and functions */
int SEGV_MAPERR;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ print_call_link(int /*<<< orphan*/ const *);
int /*<<< orphan*/ stderr;
void sigsegv_handler(int signo, siginfo_t *info, void *context) {
  fprintf(stderr, "Segmentation Fault!"
                  "\n");
  fprintf(stderr,
          "info.si_signo = %d"
          "\n",
          signo);
  if (info) {
    fprintf(stderr,
            "info.si_errno = %d"
            "\n",
            info->si_errno);
    fprintf(stderr,
            "info.si_code  = %d (%s)"
            "\n",
            info->si_code,
            (info->si_code == SEGV_MAPERR) ? "SEGV_MAPERR" : "SEGV_ACCERR");
    fprintf(stderr,
            "info.si_addr  = %p\n"
            "\n",
            info->si_addr);
  }
  if (context) {
    const ucontext_t *uc = (const ucontext_t *)context;
    print_call_link(uc);
  }
  _exit(0);
}


x86 assembly (clang, -O0):
<sigsegv_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpq   $0x0,-0x10(%rbp)
je     11fe <sigsegv_handler+0xce>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xe94(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edx
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%esi
mov    0x2e1e(%rip),%rax
mov    (%rax),%r8d
lea    0xe9e(%rip),%rcx
lea    0xe8b(%rip),%rax
cmp    %r8d,%esi
cmove  %rax,%rcx
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edx
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpq   $0x0,-0x18(%rbp)
je     121a <sigsegv_handler+0xea>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <print_call_link@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

x86 assembly (clang, -O2):
<sigsegv_handler>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2e9a(%rip),%r15
mov    (%r15),%edi
lea    0xeb0(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
lea    0xeb4(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %rbx,%rbx
jne    117b <sigsegv_handler+0x4b>
test   %r14,%r14
jne    11d6 <sigsegv_handler+0xa6>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    (%r15),%edi
mov    (%rbx),%edx
lea    0xea2(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
mov    0x4(%rbx),%edx
mov    0x2e3d(%rip),%rax
cmp    (%rax),%edx
lea    0xeb2(%rip),%rax
lea    0xeb7(%rip),%rcx
cmove  %rax,%rcx
lea    0xe87(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%edi
mov    0x8(%rbx),%edx
lea    0xea4(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
test   %r14,%r14
je     1174 <sigsegv_handler+0x44>
mov    %r14,%rdi
call   1040 <print_call_link@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [21 x i8] c"Segmentation Fault!\0A\00"
@.str.1 = [20 x i8] c"info.si_signo = %d\0A\00"
@.str.2 = [20 x i8] c"info.si_errno = %d\0A\00"
@.str.3 = [25 x i8] c"info.si_code = %d (%s)\0A\00"
@SEGV_MAPERR = global i32 0
@.str.4 = [12 x i8] c"SEGV_MAPERR\00"
@.str.5 = [12 x i8] c"SEGV_ACCERR\00"
@.str.6 = [21 x i8] c"info.si_addr = %p\0A\0A\00"
define void @sigsegv_handler(i32 %0, %struct.TYPE_3__* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i8*
%7 = alloca i32*
store i32 %0, i32* %4
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %5
store i8* %2, i8** %6
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%10 = load i32, i32* @stderr
%11 = load i32, i32* %4
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%14 = icmp ne %struct.TYPE_3__* %13, null
br i1 %14, label %15, label %38
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @stderr
%22 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%23 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %22, i32 0, i32 1
%24 = load i32, i32* %23
%25 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = load i32, i32* @SEGV_MAPERR
%29 = icmp eq i32 %27, %28
%30 = zext i1 %29 to i64
%31 = select i1 %29, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %24, i8* %31)
%33 = load i32, i32* @stderr
%34 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%35 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %34, i32 0, i32 2
%36 = load i32, i32* %35
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %15, %3
%39 = load i8*, i8** %6
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %46
41: ; preds = %38
%42 = load i8*, i8** %6
%43 = bitcast i8* %42 to i32*
store i32* %43, i32** %7
%44 = load i32*, i32** %7
%45 = call i32 @print_call_link(i32* %44)
br label %46
46: ; preds = %41, %38
%47 = call i32 @_exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32, i32 }
@stderr = global i32 0
@.str = [21 x i8] c"Segmentation Fault!\0A\00"
@.str.1 = [20 x i8] c"info.si_signo = %d\0A\00"
@.str.2 = [20 x i8] c"info.si_errno = %d\0A\00"
@.str.3 = [25 x i8] c"info.si_code = %d (%s)\0A\00"
@SEGV_MAPERR = global i32 0
@.str.4 = [12 x i8] c"SEGV_MAPERR\00"
@.str.5 = [12 x i8] c"SEGV_ACCERR\00"
@.str.6 = [21 x i8] c"info.si_addr = %p\0A\0A\00"
define void @sigsegv_handler(i32 %0, %struct.TYPE_3__* %1, i8* %2) {
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%8 = icmp eq %struct.TYPE_3__* %1, null
br i1 %8, label %25, label %9
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = load i32, i32* @stderr
%15 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 1
%16 = load i32, i32* %15
%17 = load i32, i32* @SEGV_MAPERR
%18 = icmp eq i32 %16, %17
%19 = select i1 %18, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0)
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %16, i8* %19)
%21 = load i32, i32* @stderr
%22 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 2
%23 = load i32, i32* %22
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.6, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %9, %3
%26 = icmp eq i8* %2, null
br i1 %26, label %30, label %27
27: ; preds = %25
%28 = bitcast i8* %2 to i32*
%29 = tail call i32 @print_call_link(i32* %28)
br label %30
30: ; preds = %27, %25
%31 = tail call i32 @_exit(i32 0)
unreachable
}