#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 SIGINT;
int SIGTERM;
int /*<<< orphan*/ eprint(char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perf_close();
int /*<<< orphan*/ remove_pidfile();
int /*<<< orphan*/ remove_sock();
void signalhandler(int sig) {
  if (sig == SIGTERM)
    eprint("Caught signal SIGTERM, terminating...\n");
  else if (sig == SIGINT)
    eprint("Caught signal SIGINT, terminating...\n");
  else
    eprint("Caught signal %d, terminating...\n", sig);
  remove_sock();
  perf_close();
  remove_pidfile();
  exit(0);
}


x86 assembly (clang, -O0):
<signalhandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
jne    1180 <signalhandler+0x30>
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1070 <eprint@plt>
jmp    11bb <signalhandler+0x6b>
mov    -0x4(%rbp),%eax
mov    0x2e5e(%rip),%rcx
cmp    (%rcx),%eax
jne    11a5 <signalhandler+0x55>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1070 <eprint@plt>
jmp    11b6 <signalhandler+0x66>
mov    -0x4(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1070 <eprint@plt>
jmp    11bb <signalhandler+0x6b>
mov    $0x0,%al
call   1040 <remove_sock@plt>
mov    $0x0,%al
call   1030 <perf_close@plt>
mov    $0x0,%al
call   1050 <remove_pidfile@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<signalhandler>:
push   %rax
mov    0x2e88(%rip),%rax
cmp    %edi,(%rax)
jne    1165 <signalhandler+0x15>
lea    0xe9d(%rip),%rdi
jmp    1179 <signalhandler+0x29>
mov    %edi,%esi
mov    0x2e7a(%rip),%rax
cmp    %edi,(%rax)
jne    1182 <signalhandler+0x32>
lea    0xeae(%rip),%rdi
xor    %eax,%eax
call   1070 <eprint@plt>
jmp    1190 <signalhandler+0x40>
lea    0xec4(%rip),%rdi
xor    %eax,%eax
call   1070 <eprint@plt>
xor    %eax,%eax
call   1040 <remove_sock@plt>
xor    %eax,%eax
call   1030 <perf_close@plt>
xor    %eax,%eax
call   1050 <remove_pidfile@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@SIGTERM = global i32 0
@.str = [39 x i8] c"Caught signal SIGTERM, terminating...\0A\00"
@SIGINT = global i32 0
@.str.1 = [38 x i8] c"Caught signal SIGINT, terminating...\0A\00"
@.str.2 = [34 x i8] c"Caught signal %d, terminating...\0A\00"
define void @signalhandler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGTERM
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 (i8*, ...) @eprint(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %18
8: ; preds = %1
%9 = load i32, i32* %2
%10 = load i32, i32* @SIGINT
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %14
12: ; preds = %8
%13 = call i32 (i8*, ...) @eprint(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %17
14: ; preds = %8
%15 = load i32, i32* %2
%16 = call i32 (i8*, ...) @eprint(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %14, %12
br label %18
18: ; preds = %17, %6
%19 = call i32 (...) @remove_sock()
%20 = call i32 (...) @perf_close()
%21 = call i32 (...) @remove_pidfile()
%22 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@SIGTERM = global i32 0
@.str = [39 x i8] c"Caught signal SIGTERM, terminating...\0A\00"
@SIGINT = global i32 0
@.str.1 = [38 x i8] c"Caught signal SIGINT, terminating...\0A\00"
@.str.2 = [34 x i8] c"Caught signal %d, terminating...\0A\00"
define void @signalhandler(i32 %0) {
%2 = load i32, i32* @SIGTERM
%3 = icmp eq i32 %2, %0
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 (i8*, ...) @eprint(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
br label %13
6: ; preds = %1
%7 = load i32, i32* @SIGINT
%8 = icmp eq i32 %7, %0
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = tail call i32 (i8*, ...) @eprint(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
br label %13
11: ; preds = %6
%12 = tail call i32 (i8*, ...) @eprint(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %13
13: ; preds = %9, %11, %4
%14 = tail call i32 (...) @remove_sock()
%15 = tail call i32 (...) @perf_close()
%16 = tail call i32 (...) @remove_pidfile()
%17 = tail call i32 @exit(i32 0)
unreachable
}