#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 */
int /*<<< orphan*/ EXIT_SUCCESS;
#define SIGFPE 131
#define SIGILL 130
#define SIGINT 129
#define SIGSEGV 128
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
void signal_handler(int signal) {
  switch (signal) {
  case SIGFPE:
    perror("A floating point exception occured.\n");
    break;
  case SIGILL:
    perror("An illegal instruction occured.\n");
    break;
  case SIGINT:
    break;
  case SIGSEGV:
    perror("A segmentation violation occured.\n");
    break;
  default:
    perror("An unknown signal was caught.\n");
    break;
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
mov    %eax,%ecx
mov    %rcx,-0x10(%rbp)
sub    $0x3,%eax
ja     118c <signal_handler+0x6c>
mov    -0x10(%rbp),%rax
lea    0xeb5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeb5(%rip),%rdi
call   1030 <perror@plt>
jmp    1198 <signal_handler+0x78>
lea    0xec9(%rip),%rdi
call   1030 <perror@plt>
jmp    1198 <signal_handler+0x78>
jmp    1198 <signal_handler+0x78>
lea    0xed4(%rip),%rdi
call   1030 <perror@plt>
jmp    1198 <signal_handler+0x78>
lea    0xee6(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

x86 assembly (clang, -O2):
<signal_handler>:
push   %rax
mov    %edi,%eax
add    $0xffffff80,%eax
cmp    $0x3,%eax
ja     114b <signal_handler+0x2b>
lea    0xede(%rip),%rdi
lea    0xec7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf0d(%rip),%rdi
jmp    115b <signal_handler+0x3b>
lea    0xf27(%rip),%rdi
jmp    115b <signal_handler+0x3b>
lea    0xeda(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"A floating point exception occured.\0A\00"
@.str.1 = [33 x i8] c"An illegal instruction occured.\0A\00"
@.str.2 = [35 x i8] c"A segmentation violation occured.\0A\00"
@.str.3 = [31 x i8] c"An unknown signal was caught.\0A\00"
@EXIT_SUCCESS = global i32 0
define void @signal_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %11 [
i32 131, label %4
i32 130, label %6
i32 129, label %8
i32 128, label %9
]
4: ; preds = %1
%5 = call i32 @perror(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %13
6: ; preds = %1
%7 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
br label %13
8: ; preds = %1
br label %13
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
br label %13
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
br label %13
13: ; preds = %11, %9, %8, %6, %4
%14 = load i32, i32* @EXIT_SUCCESS
%15 = call i32 @exit(i32 %14)
unreachable
}

LLVM IR (-O2):
@.str = [37 x i8] c"A floating point exception occured.\0A\00"
@.str.1 = [33 x i8] c"An illegal instruction occured.\0A\00"
@.str.2 = [35 x i8] c"A segmentation violation occured.\0A\00"
@.str.3 = [31 x i8] c"An unknown signal was caught.\0A\00"
@EXIT_SUCCESS = global i32 0
define void @signal_handler(i32 %0) {
switch i32 %0, label %4 [
i32 131, label %5
i32 130, label %2
i32 129, label %8
i32 128, label %3
]
2: ; preds = %1
br label %5
3: ; preds = %1
br label %5
4: ; preds = %1
br label %5
5: ; preds = %1, %2, %3, %4
%6 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), %4 ], [ getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), %1 ]
%7 = tail call i32 @perror(i8* %6)
br label %8
8: ; preds = %5, %1
%9 = load i32, i32* @EXIT_SUCCESS
%10 = tail call i32 @exit(i32 %9)
unreachable
}