#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;
#define SIGHUP 129
#define SIGTERM 128
int /*<<< orphan*/ cleanup();
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
void signal_handler(int sig) {
  switch (sig) {
  case SIGHUP:
    syslog(LOG_INFO, "received SIGHUP.");
    break;
  case SIGTERM:
    syslog(LOG_INFO, "received SIGTERM.");
    cleanup();
    closelog();
    exit(EXIT_SUCCESS);
    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)
sub    $0x80,%eax
je     118e <signal_handler+0x4e>
jmp    1161 <signal_handler+0x21>
mov    -0x8(%rbp),%eax
sub    $0x81,%eax
jne    11bf <signal_handler+0x7f>
jmp    1174 <signal_handler+0x34>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1040 <syslog@plt>
jmp    11bf <signal_handler+0x7f>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe73(%rip),%rsi
call   1040 <syslog@plt>
mov    $0x0,%al
call   1050 <cleanup@plt>
mov    $0x0,%al
call   1030 <closelog@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %rax
cmp    $0x81,%edi
je     1153 <signal_handler+0x13>
cmp    $0x80,%edi
je     1169 <signal_handler+0x29>
pop    %rax
ret
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
lea    0xe9d(%rip),%rsi
pop    %rax
jmp    1040 <syslog@plt>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe98(%rip),%rsi
call   1040 <syslog@plt>
xor    %eax,%eax
call   1050 <cleanup@plt>
xor    %eax,%eax
call   1030 <closelog@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@LOG_INFO = global i32 0
@.str = [17 x i8] c"received SIGHUP.\00"
@.str.1 = [18 x i8] c"received SIGTERM.\00"
@EXIT_SUCCESS = global i32 0
define void @signal_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %14 [
i32 129, label %4
i32 128, label %7
]
4: ; preds = %1
%5 = load i32, i32* @LOG_INFO
%6 = call i32 @syslog(i32 %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %14
7: ; preds = %1
%8 = load i32, i32* @LOG_INFO
%9 = call i32 @syslog(i32 %8, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (...) @cleanup()
%11 = call i32 (...) @closelog()
%12 = load i32, i32* @EXIT_SUCCESS
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1, %4
ret void
}

LLVM IR (-O2):
@LOG_INFO = global i32 0
@.str = [17 x i8] c"received SIGHUP.\00"
@.str.1 = [18 x i8] c"received SIGTERM.\00"
@EXIT_SUCCESS = global i32 0
define void @signal_handler(i32 %0) {
switch i32 %0, label %12 [
i32 129, label %2
i32 128, label %5
]
2: ; preds = %1
%3 = load i32, i32* @LOG_INFO
%4 = tail call i32 @syslog(i32 %3, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
br label %12
5: ; preds = %1
%6 = load i32, i32* @LOG_INFO
%7 = tail call i32 @syslog(i32 %6, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (...) @cleanup()
%9 = tail call i32 (...) @closelog()
%10 = load i32, i32* @EXIT_SUCCESS
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %1, %2
ret void
}