#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_NOTICE;
int SIGTERM;
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ psignal(int, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
void signal_handler(int signum) {
  psignal(signum, "caught signal");
  if (signum == SIGTERM) {
    syslog(LOG_NOTICE, "Daemon caught a SIGTERM, exiting");
    closelog();
    exit(EXIT_SUCCESS);
  }
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    0xeab(%rip),%rsi
call   1060 <psignal@plt>
mov    -0x4(%rbp),%eax
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%eax
jne    1196 <signal_handler+0x56>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1040 <syslog@plt>
mov    $0x0,%al
call   1030 <closelog@plt>
mov    0x2e41(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %rbx
mov    %edi,%ebx
lea    0xeb6(%rip),%rsi
call   1060 <psignal@plt>
mov    0x2e92(%rip),%rax
cmp    %ebx,(%rax)
je     115c <signal_handler+0x1c>
pop    %rbx
ret
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xea2(%rip),%rsi
call   1040 <syslog@plt>
xor    %eax,%eax
call   1030 <closelog@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"caught signal\00"
@SIGTERM = global i32 0
@LOG_NOTICE = global i32 0
@.str.1 = [33 x i8] c"Daemon caught a SIGTERM, exiting\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
%4 = call i32 @psignal(i32 %3, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* %2
%6 = load i32, i32* @SIGTERM
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i32, i32* @LOG_NOTICE
%10 = call i32 @syslog(i32 %9, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (...) @closelog()
%12 = load i32, i32* @EXIT_SUCCESS
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"caught signal\00"
@SIGTERM = global i32 0
@LOG_NOTICE = global i32 0
@.str.1 = [33 x i8] c"Daemon caught a SIGTERM, exiting\00"
@EXIT_SUCCESS = global i32 0
define void @signal_handler(i32 %0) {
%2 = tail call i32 @psignal(i32 %0, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = load i32, i32* @SIGTERM
%4 = icmp eq i32 %3, %0
br i1 %4, label %5, label %11
5: ; preds = %1
%6 = load i32, i32* @LOG_NOTICE
%7 = tail call i32 @syslog(i32 %6, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 (...) @closelog()
%9 = load i32, i32* @EXIT_SUCCESS
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
ret void
}