#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 SIGBUS;
int SIGILL;
int SIGSEGV;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ printf(char *);
void handler(int s) {
  if (s == SIGBUS) {
    printf("Now got a bus error signal\n");
  }
  if (s == SIGSEGV) {
    printf("Now got a segmentation violation signal\n");
    exit(1);
  }
  if (s == SIGILL) {
    printf("Now got an illegal instruction signal\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ebb(%rip),%rcx
cmp    (%rcx),%eax
jne    1149 <handler+0x29>
lea    0xebc(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    0x2e8d(%rip),%rcx
cmp    (%rcx),%eax
jne    1171 <handler+0x51>
lea    0xeba(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
mov    -0x4(%rbp),%eax
mov    0x2e5d(%rip),%rcx
cmp    (%rcx),%eax
jne    1199 <handler+0x79>
lea    0xebb(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handler>:
push   %rbx
mov    %edi,%ebx
mov    0x2ec6(%rip),%rax
cmp    %edi,(%rax)
jne    113a <handler+0x1a>
lea    0xf19(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e9f(%rip),%rax
cmp    %ebx,(%rax)
je     1152 <handler+0x32>
mov    0x2e8c(%rip),%rax
cmp    %ebx,(%rax)
je     115b <handler+0x3b>
pop    %rbx
ret
lea    0xecd(%rip),%rdi
jmp    1162 <handler+0x42>
lea    0xe9e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@SIGBUS = global i32 0
@.str = [28 x i8] c"Now got a bus error signal\0A\00"
@SIGSEGV = global i32 0
@.str.1 = [41 x i8] c"Now got a segmentation violation signal\0A\00"
@SIGILL = global i32 0
@.str.2 = [39 x i8] c"Now got an illegal instruction signal\0A\00"
define void @handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGBUS
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = load i32, i32* %2
%10 = load i32, i32* @SIGSEGV
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %8
%16 = load i32, i32* %2
%17 = load i32, i32* @SIGILL
%18 = icmp eq i32 %16, %17
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %15
ret void
}

LLVM IR (-O2):
@SIGBUS = global i32 0
@SIGSEGV = global i32 0
@SIGILL = global i32 0
@str = [38 x i8] c"Now got an illegal instruction signal\00"
@str.3 = [40 x i8] c"Now got a segmentation violation signal\00"
@str.4 = [27 x i8] c"Now got a bus error signal\00"
define void @handler(i32 %0) {
%2 = load i32, i32* @SIGBUS
%3 = icmp eq i32 %2, %0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.4, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = load i32, i32* @SIGSEGV
%8 = icmp eq i32 %7, %0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.3, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %6
%13 = load i32, i32* @SIGILL
%14 = icmp eq i32 %13, %0
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %12
ret void
}