#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_FAILURE;
#define SIGINT 128
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ SIG_ERR;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ mrsh_exit(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ raise(int);
int /*<<< orphan*/ signal(int, int /*<<< orphan*/);
void sighandler(int sig) {
  switch (sig) {
  case SIGINT:
    mrsh_exit(NULL);
    break;
  default:
    printf("caught sig %d, re-raising\n", sig);
    if (signal(sig, SIG_DFL) == SIG_ERR) {
      exit(EXIT_FAILURE);
    }
    raise(sig);
  }
}


x86 assembly (clang, -O0):
<sighandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
sub    $0x80,%eax
jne    117c <sighandler+0x2c>
jmp    116e <sighandler+0x1e>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <mrsh_exit@plt>
jmp    11c1 <sighandler+0x71>
mov    -0x4(%rbp),%esi
lea    0xe7a(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%eax
jne    11b9 <sighandler+0x69>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x4(%rbp),%edi
call   1030 <raise@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sighandler>:
push   %rbx
cmp    $0x80,%edi
jne    1161 <sighandler+0x11>
xor    %edi,%edi
pop    %rbx
jmp    1060 <mrsh_exit@plt>
mov    %edi,%ebx
lea    0xe96(%rip),%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1050 <signal@plt>
mov    0x2e58(%rip),%rcx
cmp    (%rcx),%eax
je     1194 <sighandler+0x44>
mov    %ebx,%edi
pop    %rbx
jmp    1030 <raise@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [27 x i8] c"caught sig %d, re-raising\0A\00"
@SIG_DFL = global i32 0
@SIG_ERR = global i32 0
@EXIT_FAILURE = global i32 0
define void @sighandler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %6 [
i32 128, label %4
]
4: ; preds = %1
%5 = call i32 @mrsh_exit(i32* null)
br label %20
6: ; preds = %1
%7 = load i32, i32* %2
%8 = call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* %2
%10 = load i32, i32* @SIG_DFL
%11 = call i32 @signal(i32 %9, i32 %10)
%12 = load i32, i32* @SIG_ERR
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %6
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %6
%18 = load i32, i32* %2
%19 = call i32 @raise(i32 %18)
br label %20
20: ; preds = %17, %4
ret void
}

LLVM IR (-O2):
@.str = [27 x i8] c"caught sig %d, re-raising\0A\00"
@SIG_DFL = global i32 0
@SIG_ERR = global i32 0
@EXIT_FAILURE = global i32 0
define void @sighandler(i32 %0) {
%2 = icmp eq i32 %0, 128
br i1 %2, label %3, label %5
3: ; preds = %1
%4 = tail call i32 @mrsh_exit(i32* null)
br label %16
5: ; preds = %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %0)
%7 = load i32, i32* @SIG_DFL
%8 = tail call i32 @signal(i32 %0, i32 %7)
%9 = load i32, i32* @SIG_ERR
%10 = icmp eq i32 %8, %9
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %5
%15 = tail call i32 @raise(i32 %0)
br label %16
16: ; preds = %14, %3
ret void
}