#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 SIGBUS 129
#define SIGSEGV 128
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ clean_and_exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
void zc_signal_handler(int sig) {
  switch (sig) {
  case SIGSEGV:
    fprintf(stderr, "Segmentation violation in ZPL compiler!\n"
                    "Please contact zpl-info@cs.washington.edu.\n");
    break;
  case SIGBUS:
    fprintf(stderr, "Bus error in ZPL compiler!\n"
                    "Please contact zpl-info@cs.washington.edu.\n");
    break;
  default:
    fprintf(stderr, "Signal %d caught -- exiting.\n", sig);
    break;
  }
  kill(0, SIGTERM);
  clean_and_exit(sig);
}


x86 assembly (clang, -O0):
<zc_signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x80,%eax
je     1164 <zc_signal_handler+0x34>
jmp    1151 <zc_signal_handler+0x21>
mov    -0x8(%rbp),%eax
sub    $0x81,%eax
je     1180 <zc_signal_handler+0x50>
jmp    119c <zc_signal_handler+0x6c>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11b6 <zc_signal_handler+0x86>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xec4(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11b6 <zc_signal_handler+0x86>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xeec(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1040 <kill@plt>
mov    -0x4(%rbp),%edi
call   1050 <clean_and_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zc_signal_handler>:
push   %rbx
mov    %edi,%ebx
mov    0x2e9e(%rip),%rax
cmp    $0x81,%edi
je     1155 <zc_signal_handler+0x25>
cmp    $0x80,%ebx
jne    1167 <zc_signal_handler+0x37>
mov    (%rax),%edi
lea    0xead(%rip),%rsi
jmp    115e <zc_signal_handler+0x2e>
mov    (%rax),%edi
lea    0xef6(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1179 <zc_signal_handler+0x49>
mov    (%rax),%edi
lea    0xf2b(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1040 <kill@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1050 <clean_and_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [84 x i8] c"Segmentation violation in ZPL compiler!\0APlease contact zpl-info@cs.washington.edu.\0A\00"
@.str.1 = [71 x i8] c"Bus error in ZPL compiler!\0APlease contact zpl-info@cs.washington.edu.\0A\00"
@.str.2 = [30 x i8] c"Signal %d caught -- exiting.\0A\00"
@SIGTERM = global i32 0
define void @zc_signal_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %10 [
i32 128, label %4
i32 129, label %7
]
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str, i64 0, i64 0))
br label %14
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
br label %14
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i32, i32* %2
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10, %7, %4
%15 = load i32, i32* @SIGTERM
%16 = call i32 @kill(i32 0, i32 %15)
%17 = load i32, i32* %2
%18 = call i32 @clean_and_exit(i32 %17)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [84 x i8] c"Segmentation violation in ZPL compiler!\0APlease contact zpl-info@cs.washington.edu.\0A\00"
@.str.1 = [71 x i8] c"Bus error in ZPL compiler!\0APlease contact zpl-info@cs.washington.edu.\0A\00"
@.str.2 = [30 x i8] c"Signal %d caught -- exiting.\0A\00"
@SIGTERM = global i32 0
define void @zc_signal_handler(i32 %0) {
switch i32 %0, label %8 [
i32 128, label %2
i32 129, label %5
]
2: ; preds = %1
%3 = load i32, i32* @stderr
%4 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str, i64 0, i64 0))
br label %11
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.1, i64 0, i64 0))
br label %11
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %11
11: ; preds = %8, %5, %2
%12 = load i32, i32* @SIGTERM
%13 = tail call i32 @kill(i32 0, i32 %12)
%14 = tail call i32 @clean_and_exit(i32 %0)
ret void
}