#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 */
struct TYPE_3__ {
  int /*<<< orphan*/ si_addr;
};
typedef TYPE_1__ siginfo_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ is_in_arena(int /*<<< orphan*/);
scalar_t__ is_stack_overflow(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void handle_error(int signo, siginfo_t *siginfo, void *context) {
  (void)(signo);
  (void)(context);
  if (is_stack_overflow(siginfo->si_addr)) {
    fprintf(stderr, "Stack overflow: Too many root objects\n");
  } else if (is_in_arena(siginfo->si_addr)) {
    fprintf(stderr, "Internal segmentation fault: accessing %p\n",
            siginfo->si_addr);
  } else {
    fprintf(stderr, "External segmentation fault: accessing %p\n",
            siginfo->si_addr);
  }
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<handle_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <is_stack_overflow@plt>
cmp    $0x0,%rax
je     1184 <handle_error+0x44>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xe88(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11dd <handle_error+0x9d>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <is_in_arena@plt>
cmp    $0x0,%rax
je     11bb <handle_error+0x7b>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11d8 <handle_error+0x98>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xe81(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11dd <handle_error+0x9d>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<handle_error>:
push   %rbx
mov    %rsi,%rbx
mov    (%rsi),%edi
call   1050 <is_stack_overflow@plt>
test   %rax,%rax
jne    1170 <handle_error+0x30>
mov    (%rbx),%edi
call   1030 <is_in_arena@plt>
mov    0x2e82(%rip),%rcx
mov    (%rcx),%edi
mov    (%rbx),%edx
test   %rax,%rax
jne    1189 <handle_error+0x49>
lea    0xee4(%rip),%rsi
jmp    1190 <handle_error+0x50>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1197 <handle_error+0x57>
lea    0xe97(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"Stack overflow: Too many root objects\0A\00"
@.str.1 = [43 x i8] c"Internal segmentation fault: accessing %p\0A\00"
@.str.2 = [43 x i8] c"External segmentation fault: accessing %p\0A\00"
@EXIT_FAILURE = global i32 0
define void @handle_error(i32 %0, %struct.TYPE_3__* %1, i8* %2) {
%4 = alloca i32
%5 = alloca %struct.TYPE_3__*
%6 = alloca i8*
store i32 %0, i32* %4
store %struct.TYPE_3__* %1, %struct.TYPE_3__** %5
store i8* %2, i8** %6
%7 = load i32, i32* %4
%8 = load i8*, i8** %6
%9 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%10 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = call i64 @is_stack_overflow(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %36
17: ; preds = %3
%18 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%19 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i64 @is_in_arena(i32 %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%26 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %27)
br label %35
29: ; preds = %17
%30 = load i32, i32* @stderr
%31 = load %struct.TYPE_3__*, %struct.TYPE_3__** %5
%32 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %29, %23
br label %36
36: ; preds = %35, %14
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"Stack overflow: Too many root objects\0A\00"
@.str.1 = [43 x i8] c"Internal segmentation fault: accessing %p\0A\00"
@.str.2 = [43 x i8] c"External segmentation fault: accessing %p\0A\00"
@EXIT_FAILURE = global i32 0
define void @handle_error(i32 %0, %struct.TYPE_3__* nocapture %1, i8* nocapture readnone %2) {
%4 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %1, i64 0, i32 0
%5 = load i32, i32* %4
%6 = tail call i64 @is_stack_overflow(i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %21
11: ; preds = %3
%12 = load i32, i32* %4
%13 = tail call i64 @is_in_arena(i32 %12)
%14 = icmp eq i64 %13, 0
%15 = load i32, i32* @stderr
%16 = load i32, i32* %4
br i1 %14, label %19, label %17
17: ; preds = %11
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %21
19: ; preds = %11
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %21
21: ; preds = %17, %19, %8
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
}