#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 SIGFPE 132
#define SIGHUP 131
#define SIGINT 130
#define SIGSEGV 129
#define SIGTERM 128
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
void sighandler(int x) {
  switch (x) {
  case SIGINT:
    printf("^C\n");
    break;
  case SIGTERM:
    printf("kill\n");
    break;
  case SIGHUP:
    printf("kill -HUP\n");
    break;
  case SIGSEGV:
    printf("segmantation fault\n");
    exit(1);
    break;
  case SIGFPE:
    printf("floating point exception (divison by zero or so)\n");
    exit(1);
    break;
  }
}


x86 assembly (clang, -O0):
<sighandler>:
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    $0x4,%eax
ja     11b3 <sighandler+0x93>
mov    -0x10(%rbp),%rax
lea    0xeb5(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xeb9(%rip),%rdi
call   1030 <printf@plt>
jmp    11b3 <sighandler+0x93>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
jmp    11b3 <sighandler+0x93>
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
jmp    11b3 <sighandler+0x93>
lea    0xe9b(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
lea    0xe99(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sighandler>:
push   %rax
mov    %edi,%eax
add    $0xffffff80,%eax
cmp    $0x4,%eax
ja     114f <sighandler+0x2f>
lea    0xf35(%rip),%rdi
lea    0xec7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xf19(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
pop    %rax
ret
lea    0xf00(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
lea    0xee0(%rip),%rdi
jmp    116e <sighandler+0x4e>
lea    0xea6(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"^C\0A\00"
@.str.1 = [6 x i8] c"kill\0A\00"
@.str.2 = [11 x i8] c"kill -HUP\0A\00"
@.str.3 = [20 x i8] c"segmantation fault\0A\00"
@.str.4 = [50 x i8] c"floating point exception (divison by zero or so)\0A\00"
define void @sighandler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %16 [
i32 130, label %4
i32 128, label %6
i32 131, label %8
i32 129, label %10
i32 132, label %13
]
4: ; preds = %1
%5 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
br label %16
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %16
8: ; preds = %1
%9 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %16
10: ; preds = %1
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = call i32 @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1, %8, %6, %4
ret void
}

LLVM IR (-O2):
@str = [49 x i8] c"floating point exception (divison by zero or so)\00"
@str.5 = [19 x i8] c"segmantation fault\00"
@str.6 = [10 x i8] c"kill -HUP\00"
@str.7 = [5 x i8] c"kill\00"
@str.8 = [3 x i8] c"^C\00"
define void @sighandler(i32 %0) {
switch i32 %0, label %13 [
i32 130, label %10
i32 128, label %2
i32 131, label %3
i32 129, label %4
i32 132, label %7
]
2: ; preds = %1
br label %10
3: ; preds = %1
br label %10
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %1
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %1, %2, %3
%11 = phi i8* [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.6, i64 0, i64 0), %3 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @str.7, i64 0, i64 0), %2 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @str.8, i64 0, i64 0), %1 ]
%12 = tail call i32 @puts(i8* dereferenceable(1) %11)
br label %13
13: ; preds = %10, %1
ret void
}