#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;
int /*<<< orphan*/ EXIT_SUCCESS;
int SIGINT;
int SIGTERM;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
void signal_handler(int signo) {
  if (signo == SIGINT) {
    printf("Caught SIGINT\n");
  } else if (signo == SIGTERM) {
    printf("Caught SIGTERM\n");
  } else {
    fprintf(stderr, "Unexpected signal");
    exit(EXIT_FAILURE);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2ea3(%rip),%rcx
cmp    (%rcx),%eax
jne    115e <signal_handler+0x2e>
lea    0xeac(%rip),%rdi
call   1030 <printf@plt>
jmp    11a9 <signal_handler+0x79>
mov    -0x4(%rbp),%eax
mov    0x2e78(%rip),%rcx
cmp    (%rcx),%eax
jne    1181 <signal_handler+0x51>
lea    0xe98(%rip),%rdi
call   1030 <printf@plt>
jmp    11a4 <signal_handler+0x74>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
lea    0xe8e(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
jmp    11a9 <signal_handler+0x79>
mov    0x2e10(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<signal_handler>:
push   %rax
mov    0x2eb0(%rip),%rax
cmp    %edi,(%rax)
jne    1145 <signal_handler+0x15>
lea    0xede(%rip),%rdi
jmp    1157 <signal_handler+0x27>
mov    0x2e94(%rip),%rax
cmp    %edi,(%rax)
jne    116a <signal_handler+0x3a>
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@SIGINT = global i32 0
@.str = [15 x i8] c"Caught SIGINT\0A\00"
@SIGTERM = global i32 0
@.str.1 = [16 x i8] c"Caught SIGTERM\0A\00"
@stderr = global i32 0
@.str.2 = [18 x i8] c"Unexpected signal\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = 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* @SIGINT
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %20
8: ; preds = %1
%9 = load i32, i32* %2
%10 = load i32, i32* @SIGTERM
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
br label %19
14: ; preds = %8
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %12
br label %20
20: ; preds = %19, %6
%21 = load i32, i32* @EXIT_SUCCESS
%22 = call i32 @exit(i32 %21)
unreachable
}

LLVM IR (-O2):
@SIGINT = global i32 0
@SIGTERM = global i32 0
@stderr = global i32 0
@.str.2 = [18 x i8] c"Unexpected signal\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [15 x i8] c"Caught SIGTERM\00"
@str.3 = [14 x i8] c"Caught SIGINT\00"
define void @signal_handler(i32 %0) {
%2 = load i32, i32* @SIGINT
%3 = icmp eq i32 %2, %0
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = load i32, i32* @SIGTERM
%6 = icmp eq i32 %5, %0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %4, %1
%13 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.3, i64 0, i64 0), %1 ], [ getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0), %4 ]
%14 = tail call i32 @puts(i8* dereferenceable(1) %13)
%15 = load i32, i32* @EXIT_SUCCESS
%16 = tail call i32 @exit(i32 %15)
unreachable
}