#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 SIGHUP;
int SIGINT;
int SIGKILL;
int SIGQUIT;
int SIGSEGV;
int /*<<< orphan*/ dumpstack();
int /*<<< orphan*/ panic(char *, ...);
void signal_handler(int sig) {
  if (sig == SIGHUP)
    panic("FATAL: Program hanged up\n");
  if (sig == SIGSEGV || sig == SIGBUS) {
    dumpstack();
    panic("FATAL: %s Fault. Logged StackTrace\n",
          (sig == SIGSEGV) ? "Segmentation"
                           : ((sig == SIGBUS) ? "Bus" : "Unknown"));
  }
  if (sig == SIGQUIT)
    panic("QUIT signal ended program\n");
  if (sig == SIGKILL)
    panic("KILL signal ended program\n");
  if (sig == SIGINT)
    ;
}


x86 assembly (clang, -O0):
<signal_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    114b <signal_handler+0x2b>
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <panic@plt>
mov    -0x4(%rbp),%eax
mov    0x2e83(%rip),%rcx
cmp    (%rcx),%eax
je     116f <signal_handler+0x4f>
mov    -0x4(%rbp),%eax
mov    0x2e81(%rip),%rcx
cmp    (%rcx),%eax
jne    11ce <signal_handler+0xae>
mov    $0x0,%al
call   1040 <dumpstack@plt>
mov    -0x4(%rbp),%eax
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%eax
jne    1198 <signal_handler+0x78>
lea    0xeaf(%rip),%rax
mov    %rax,-0x10(%rbp)
jmp    11bc <signal_handler+0x9c>
mov    -0x4(%rbp),%edx
mov    0x2e46(%rip),%rax
mov    (%rax),%esi
lea    0xea4(%rip),%rax
lea    0xe99(%rip),%rcx
cmp    %esi,%edx
cmove  %rcx,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <panic@plt>
mov    -0x4(%rbp),%eax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%eax
jne    11ee <signal_handler+0xce>
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1030 <panic@plt>
mov    -0x4(%rbp),%eax
mov    0x2dc0(%rip),%rcx
cmp    (%rcx),%eax
jne    120e <signal_handler+0xee>
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <panic@plt>
mov    -0x4(%rbp),%eax
mov    0x2db8(%rip),%rcx
cmp    (%rcx),%eax
jne    1225 <signal_handler+0x105>
jmp    1225 <signal_handler+0x105>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %r15
push   %r14
push   %rbx
mov    %edi,%ebx
mov    0x2ec2(%rip),%rax
cmp    %edi,(%rax)
jne    1140 <signal_handler+0x20>
lea    0xec7(%rip),%rdi
xor    %eax,%eax
call   1030 <panic@plt>
mov    0x2e91(%rip),%r14
mov    0x2e9a(%rip),%r15
cmp    %ebx,(%r14)
je     1158 <signal_handler+0x38>
cmp    %ebx,(%r15)
jne    1190 <signal_handler+0x70>
xor    %eax,%eax
call   1040 <dumpstack@plt>
cmp    %ebx,(%r15)
lea    0xee2(%rip),%rax
lea    0xedf(%rip),%rcx
cmove  %rax,%rcx
cmp    %ebx,(%r14)
lea    0xec0(%rip),%rsi
cmovne %rcx,%rsi
lea    0xe91(%rip),%rdi
xor    %eax,%eax
call   1030 <panic@plt>
mov    0x2e39(%rip),%rax
cmp    %ebx,(%rax)
jne    11a9 <signal_handler+0x89>
lea    0xeb5(%rip),%rdi
xor    %eax,%eax
call   1030 <panic@plt>
mov    0x2e10(%rip),%rax
cmp    %ebx,(%rax)
jne    11c7 <signal_handler+0xa7>
lea    0xeb7(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <panic@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@SIGHUP = global i32 0
@.str = [26 x i8] c"FATAL: Program hanged up\0A\00"
@SIGSEGV = global i32 0
@SIGBUS = global i32 0
@.str.1 = [36 x i8] c"FATAL: %s Fault. Logged StackTrace\0A\00"
@.str.2 = [13 x i8] c"Segmentation\00"
@.str.3 = [4 x i8] c"Bus\00"
@.str.4 = [8 x i8] c"Unknown\00"
@SIGQUIT = global i32 0
@.str.5 = [27 x i8] c"QUIT signal ended program\0A\00"
@SIGKILL = global i32 0
@.str.6 = [27 x i8] c"KILL signal ended program\0A\00"
@SIGINT = global i32 0
define void @signal_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGHUP
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([26 x i8], [26 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 %16, label %12
12: ; preds = %8
%13 = load i32, i32* %2
%14 = load i32, i32* @SIGBUS
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %31
16: ; preds = %12, %8
%17 = call i32 (...) @dumpstack()
%18 = load i32, i32* %2
%19 = load i32, i32* @SIGSEGV
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %22
21: ; preds = %16
br label %28
22: ; preds = %16
%23 = load i32, i32* %2
%24 = load i32, i32* @SIGBUS
%25 = icmp eq i32 %23, %24
%26 = zext i1 %25 to i64
%27 = select i1 %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0)
br label %28
28: ; preds = %22, %21
%29 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %21 ], [ %27, %22 ]
%30 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %28, %12
%32 = load i32, i32* %2
%33 = load i32, i32* @SIGQUIT
%34 = icmp eq i32 %32, %33
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = load i32, i32* %2
%39 = load i32, i32* @SIGKILL
%40 = icmp eq i32 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %43
43: ; preds = %41, %37
%44 = load i32, i32* %2
%45 = load i32, i32* @SIGINT
%46 = icmp eq i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %43
br label %48
48: ; preds = %47, %43
ret void
}

LLVM IR (-O2):
@SIGHUP = global i32 0
@.str = [26 x i8] c"FATAL: Program hanged up\0A\00"
@SIGSEGV = global i32 0
@SIGBUS = global i32 0
@.str.1 = [36 x i8] c"FATAL: %s Fault. Logged StackTrace\0A\00"
@.str.2 = [13 x i8] c"Segmentation\00"
@.str.3 = [4 x i8] c"Bus\00"
@.str.4 = [8 x i8] c"Unknown\00"
@SIGQUIT = global i32 0
@.str.5 = [27 x i8] c"QUIT signal ended program\0A\00"
@SIGKILL = global i32 0
@.str.6 = [27 x i8] c"KILL signal ended program\0A\00"
@SIGINT = global i32 0
define void @signal_handler(i32 %0) {
%2 = load i32, i32* @SIGHUP
%3 = icmp eq i32 %2, %0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %1
%7 = load i32, i32* @SIGSEGV
%8 = icmp eq i32 %7, %0
%9 = load i32, i32* @SIGBUS
%10 = icmp eq i32 %9, %0
%11 = select i1 %8, i1 true, i1 %10
br i1 %11, label %12, label %21
12: ; preds = %6
%13 = tail call i32 (...) @dumpstack()
%14 = load i32, i32* @SIGSEGV
%15 = icmp eq i32 %14, %0
%16 = load i32, i32* @SIGBUS
%17 = icmp eq i32 %16, %0
%18 = select i1 %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0)
%19 = select i1 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %18
%20 = tail call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %21
21: ; preds = %6, %12
%22 = load i32, i32* @SIGQUIT
%23 = icmp eq i32 %22, %0
br i1 %23, label %24, label %26
24: ; preds = %21
%25 = tail call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0))
br label %26
26: ; preds = %24, %21
%27 = load i32, i32* @SIGKILL
%28 = icmp eq i32 %27, %0
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = tail call i32 (i8*, ...) @panic(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0))
br label %31
31: ; preds = %29, %26
ret void
}