#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*/ 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.");
    break;
  case SIGINT:
  case SIGTERM:
    syslog(LOG_INFO, "Exiting.");
    daemonShutdown();
    exit(0);
    break;
  default:
    syslog(LOG_WARNING, "Unhandled signal %s", strsignal(sig));
  }
}


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    11b6 <signal_handler+0x76>
jmp    1175 <signal_handler+0x35>
mov    0x2e6c(%rip),%rax
mov    (%rax),%edi
lea    0xe7b(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
jmp    11dd <signal_handler+0x9d>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1040 <syslog@plt>
mov    $0x0,%al
call   1030 <daemonShutdown@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x2e2b(%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    0xe44(%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    0xeb4(%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    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe77(%rip),%rsi
xor    %eax,%eax
call   1040 <syslog@plt>
xor    %eax,%eax
call   1030 <daemonShutdown@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@LOG_WARNING = global i32 0
@.str = [17 x i8] c"Received SIGHUP.\00"
@LOG_INFO = global i32 0
@.str.1 = [9 x i8] c"Exiting.\00"
@.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 %12 [
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 ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %17
7: ; preds = %1, %1
%8 = load i32, i32* @LOG_INFO
%9 = call i32 (i32, i8*, ...) @syslog(i32 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (...) @daemonShutdown()
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %1
%13 = load i32, i32* @LOG_WARNING
%14 = load i32, i32* %2
%15 = call i32 @strsignal(i32 %14)
%16 = call i32 (i32, i8*, ...) @syslog(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %15)
br label %17
17: ; preds = %12, %4
ret void
}

LLVM IR (-O2):
@LOG_WARNING = global i32 0
@.str = [17 x i8] c"Received SIGHUP.\00"
@LOG_INFO = global i32 0
@.str.1 = [9 x i8] c"Exiting.\00"
@.str.2 = [20 x i8] c"Unhandled signal %s\00"
define void @signal_handler(i32 %0) {
switch i32 %0, label %10 [
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 ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %14
5: ; preds = %1, %1
%6 = load i32, i32* @LOG_INFO
%7 = tail call i32 (i32, i8*, ...) @syslog(i32 %6, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (...) @daemonShutdown()
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %1
%11 = load i32, i32* @LOG_WARNING
%12 = tail call i32 @strsignal(i32 %0)
%13 = tail call i32 (i32, i8*, ...) @syslog(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %10, %2
ret void
}