#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 */
typedef int /*<<< orphan*/ ucontext_t;
typedef int /*<<< orphan*/ siginfo_t;

/* Variables and functions */
#define SIGSEGV 129
#define SIGUSR1 128
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void signal_handler(int sig, siginfo_t *siginfo, ucontext_t *ucxt) {
  fprintf(stderr, "signal_handler: sig=%d\n", sig);
  switch (sig) {
  case SIGSEGV: {
    fprintf(stderr, "Got SIGSEGV\n");
    break;
  }
  case SIGUSR1: {
    fprintf(stderr, "Got SIGUSR1\n");
    break;
  }
  default:
    assert(0);
  }
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xeba(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x80,%eax
je     1192 <signal_handler+0x72>
jmp    1163 <signal_handler+0x43>
mov    -0x1c(%rbp),%eax
sub    $0x81,%eax
jne    11ae <signal_handler+0x8e>
jmp    1176 <signal_handler+0x56>
mov    0x2e63(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11b5 <signal_handler+0x95>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe83(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    11b5 <signal_handler+0x95>
xor    %edi,%edi
call   1030 <assert@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    0x2eb3(%rip),%r14
mov    (%r14),%edi
lea    0xec9(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
cmp    $0x80,%ebx
je     115c <signal_handler+0x3c>
cmp    $0x81,%ebx
jne    1174 <signal_handler+0x54>
mov    (%r14),%edi
lea    0xebe(%rip),%rsi
jmp    1166 <signal_handler+0x46>
mov    (%r14),%edi
lea    0xebf(%rip),%rsi
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <fprintf@plt>
xor    %edi,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <assert@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"signal_handler: sig=%d\0A\00"
@.str.1 = [13 x i8] c"Got SIGSEGV\0A\00"
@.str.2 = [13 x i8] c"Got SIGUSR1\0A\00"
define void @signal_handler(i32 %0, i32* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32*
store i32 %0, i32* %4
store i32* %1, i32** %5
store i32* %2, i32** %6
%7 = load i32, i32* @stderr
%8 = load i32, i32* %4
%9 = call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = load i32, i32* %4
switch i32 %10, label %17 [
i32 129, label %11
i32 128, label %14
]
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %19
14: ; preds = %3
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %19
17: ; preds = %3
%18 = call i32 @assert(i32 0)
br label %19
19: ; preds = %17, %14, %11
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"signal_handler: sig=%d\0A\00"
@.str.1 = [13 x i8] c"Got SIGSEGV\0A\00"
@.str.2 = [13 x i8] c"Got SIGUSR1\0A\00"
define void @signal_handler(i32 %0, i32* nocapture readnone %1, i32* nocapture readnone %2) {
%4 = load i32, i32* @stderr
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %4, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %0)
switch i32 %0, label %12 [
i32 129, label %6
i32 128, label %9
]
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %14
9: ; preds = %3
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %14
12: ; preds = %3
%13 = tail call i32 @assert(i32 0)
br label %14
14: ; preds = %12, %9, %6
ret void
}