#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_SUCCESS;
int /*<<< orphan*/ LOG_INFO;
int /*<<< orphan*/ LOG_WARNING;
#define SIGHUP 130
#define SIGINT 129
#define SIGTERM 128
int /*<<< orphan*/ daemonShutdown();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ strsignal(int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, ...);
void signal_handler(int sig) {
  switch (sig) {
  case SIGHUP:
    syslog(LOG_WARNING, "Received SIGHUP signal.");
    break;
  case SIGINT:
  case SIGTERM:
    syslog(LOG_INFO, "Daemon exiting");
    daemonShutdown();
    exit(EXIT_SUCCESS);
    break;
  default:
    syslog(LOG_WARNING, "Unhandled signal %s", strsignal(sig));
    break;
  }
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
add    $0xffffff80,%eax
sub    $0x2,%eax
jb     1191 <signal_handler+0x51>
jmp    1162 <signal_handler+0x22>
mov    -0x8(%rbp),%eax
sub    $0x82,%eax
jne    11bd <signal_handler+0x7d>
jmp    1175 <signal_handler+0x35>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
jmp    11e4 <signal_handler+0xa4>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
mov    $0x0,%al
call   1030 <daemonShutdown@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <strsignal@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%edx
lea    0xe4a(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %rbx
cmp    $0x82,%edi
je     1172 <signal_handler+0x32>
lea    -0x80(%rdi),%eax
cmp    $0x2,%eax
jb     118a <signal_handler+0x4a>
mov    0x2e90(%rip),%rax
mov    (%rax),%ebx
call   1050 <strsignal@plt>
lea    0xec1(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
pop    %rbx
jmp    1040 <syslog@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
xor    %eax,%eax
pop    %rbx
jmp    1040 <syslog@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
xor    %eax,%eax
call   1040 <syslog@plt>
xor    %eax,%eax
call   1030 <daemonShutdown@plt>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@LOG_WARNING = global i32 0
@.str = [24 x i8] c"Received SIGHUP signal.\00"
@LOG_INFO = global i32 0
@.str.1 = [15 x i8] c"Daemon exiting\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [20 x i8] c"Unhandled signal %s\00"
define void @signal_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %13 [
i32 130, label %4
i32 129, label %7
i32 128, label %7
]
4: ; preds = %1
%5 = load i32, i32* @LOG_WARNING
%6 = call i32 (i32, i8*, ...) @syslog(i32 %5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %18
7: ; preds = %1, %1
%8 = load i32, i32* @LOG_INFO
%9 = call i32 (i32, i8*, ...) @syslog(i32 %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (...) @daemonShutdown()
%11 = load i32, i32* @EXIT_SUCCESS
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
%14 = load i32, i32* @LOG_WARNING
%15 = load i32, i32* %2
%16 = call i32 @strsignal(i32 %15)
%17 = call i32 (i32, i8*, ...) @syslog(i32 %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %13, %4
ret void
}

LLVM IR (-O2):
@LOG_WARNING = global i32 0
@.str = [24 x i8] c"Received SIGHUP signal.\00"
@LOG_INFO = global i32 0
@.str.1 = [15 x i8] c"Daemon exiting\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [20 x i8] c"Unhandled signal %s\00"
define void @signal_handler(i32 %0) {
switch i32 %0, label %11 [
i32 130, label %2
i32 129, label %5
i32 128, label %5
]
2: ; preds = %1
%3 = load i32, i32* @LOG_WARNING
%4 = tail call i32 (i32, i8*, ...) @syslog(i32 %3, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
br label %15
5: ; preds = %1, %1
%6 = load i32, i32* @LOG_INFO
%7 = tail call i32 (i32, i8*, ...) @syslog(i32 %6, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (...) @daemonShutdown()
%9 = load i32, i32* @EXIT_SUCCESS
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = load i32, i32* @LOG_WARNING
%13 = tail call i32 @strsignal(i32 %0)
%14 = tail call i32 (i32, i8*, ...) @syslog(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %11, %2
ret void
}