#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 */

/* Variables and functions */
#define SIGABRT 132
#define SIGBUS 131
#define SIGFPE 130
#define SIGILL 129
#define SIGSEGV 128
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int /*<<< orphan*/ printStackTrace(int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
void abortHandler(int signum) {
  const char *name = NULL;
  switch (signum) {
  case SIGABRT:
    name = "SIGABRT";
    break;
  case SIGSEGV:
    name = "SIGSEGV";
    break;
  case SIGBUS:
    name = "SIGBUS";
    break;
  case SIGILL:
    name = "SIGILL";
    break;
  case SIGFPE:
    name = "SIGFPE";
    break;
  }
  if (name)
    fprintf(stderr, "Caught signal %d (%s)\n", signum, name);
  else
    fprintf(stderr, "Caught signal %d\n", signum);
  printStackTrace(stderr, 63);
  exit(signum);
}


x86 assembly (clang, -O0):
<abortHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x4,%eax
ja     11b7 <abortHandler+0x87>
mov    -0x18(%rbp),%rax
lea    0xe9d(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xea1(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b7 <abortHandler+0x87>
lea    0xe99(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b7 <abortHandler+0x87>
lea    0xe91(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b7 <abortHandler+0x87>
lea    0xe88(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11b7 <abortHandler+0x87>
lea    0xe7f(%rip),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e5 <abortHandler+0xb5>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
mov    -0x10(%rbp),%rcx
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11ff <abortHandler+0xcf>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe58(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
mov    $0x3f,%esi
call   1040 <printStackTrace@plt>
mov    -0x4(%rbp),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<abortHandler>:
push   %rbx
mov    %edi,%ebx
lea    -0x80(%rbx),%eax
cmp    $0x4,%eax
ja     1166 <abortHandler+0x36>
cltq
lea    0xf0c(%rip),%rdx
movslq (%rdx,%rax,4),%rcx
add    %rdx,%rcx
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
lea    0xeca(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    117f <abortHandler+0x4f>
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
lea    0xec6(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    $0x3f,%esi
call   1040 <printStackTrace@plt>
mov    %ebx,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"SIGABRT\00"
@.str.1 = [8 x i8] c"SIGSEGV\00"
@.str.2 = [7 x i8] c"SIGBUS\00"
@.str.3 = [7 x i8] c"SIGILL\00"
@.str.4 = [7 x i8] c"SIGFPE\00"
@stderr = global i32 0
@.str.5 = [23 x i8] c"Caught signal %d (%s)\0A\00"
@.str.6 = [18 x i8] c"Caught signal %d\0A\00"
define void @abortHandler(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
store i32 %0, i32* %2
store i8* null, i8** %3
%4 = load i32, i32* %2
switch i32 %4, label %10 [
i32 132, label %5
i32 128, label %6
i32 131, label %7
i32 129, label %8
i32 130, label %9
]
5: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8** %3
br label %10
6: ; preds = %1
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8** %3
br label %10
7: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8** %3
br label %10
8: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8** %3
br label %10
9: ; preds = %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i8** %3
br label %10
10: ; preds = %1, %9, %8, %7, %6, %5
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = load i32, i32* @stderr
%15 = load i32, i32* %2
%16 = load i8*, i8** %3
%17 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %15, i8* %16)
br label %22
18: ; preds = %10
%19 = load i32, i32* @stderr
%20 = load i32, i32* %2
%21 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %20)
br label %22
22: ; preds = %18, %13
%23 = load i32, i32* @stderr
%24 = call i32 @printStackTrace(i32 %23, i32 63)
%25 = load i32, i32* %2
%26 = call i32 @exit(i32 %25)
unreachable
}

LLVM IR (-O2):
@.str = [8 x i8] c"SIGABRT\00"
@.str.1 = [8 x i8] c"SIGSEGV\00"
@.str.2 = [7 x i8] c"SIGBUS\00"
@.str.3 = [7 x i8] c"SIGILL\00"
@.str.4 = [7 x i8] c"SIGFPE\00"
@stderr = global i32 0
@.str.5 = [23 x i8] c"Caught signal %d (%s)\0A\00"
@.str.6 = [18 x i8] c"Caught signal %d\0A\00"
@reltable.abortHandler = [5 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str.1 to i64), i64 ptrtoint ([5 x i32]* @reltable.abortHandler to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.3 to i64), i64 ptrtoint ([5 x i32]* @reltable.abortHandler to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.4 to i64), i64 ptrtoint ([5 x i32]* @reltable.abortHandler to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([7 x i8]* @.str.2 to i64), i64 ptrtoint ([5 x i32]* @reltable.abortHandler to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([8 x i8]* @.str to i64), i64 ptrtoint ([5 x i32]* @reltable.abortHandler to i64)) to i32)]
define void @abortHandler(i32 %0) {
%2 = add i32 %0, -128
%3 = icmp ult i32 %2, 5
br i1 %3, label %4, label %10
4: ; preds = %1
%5 = sext i32 %2 to i64
%6 = shl i64 %5, 2
%7 = call i8* @llvm.load.relative.i64(i8* bitcast ([5 x i32]* @reltable.abortHandler to i8*), i64 %6)
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0), i32 %0, i8* %7)
br label %13
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i32 %0)
br label %13
13: ; preds = %10, %4
%14 = load i32, i32* @stderr
%15 = tail call i32 @printStackTrace(i32 %14, i32 63)
%16 = tail call i32 @exit(i32 %0)
unreachable
}