#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 */
typedef int /*<<< orphan*/ time_t;
struct tm {
  int dummy;
};
typedef int /*<<< orphan*/ siginfo_t;

/* Variables and functions */
int /*<<< orphan*/ LOG_NOTICE;
#define SIGHUP 131
#define SIGINT 130
#define SIGQUIT 129
#define SIGTERM 128
int asctime(struct tm *);
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct tm *localtime(int /*<<< orphan*/ *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
void signal_hdl(int sig, siginfo_t *siginfo, void *context) {
  struct tm *newtime;
  struct tm tim;
  time_t ltime;
  switch (sig) {
  case SIGTERM:
  case SIGINT:
  case SIGQUIT:
  case SIGHUP:
    time(&ltime);
    newtime = localtime(&ltime);
    tim = *newtime;
    syslog(LOG_NOTICE, "stopped on signal at %s", asctime(newtime));
    closelog();
    exit(0);
    break;
  default:
    syslog(LOG_NOTICE, "got signal %d. ignore...", sig);
    break;
  }
}


x86 assembly (clang, -O0):
<signal_hdl>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x3,%eax
ja     11da <signal_hdl+0x7a>
jmp    1187 <signal_hdl+0x27>
lea    -0x2c(%rbp),%rdi
call   1060 <time@plt>
lea    -0x2c(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <asctime@plt>
mov    -0x30(%rbp),%edi
mov    %eax,%edx
lea    0xe39(%rip),%rsi
call   1070 <syslog@plt>
mov    $0x0,%al
call   1030 <closelog@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe2b(%rip),%rsi
call   1070 <syslog@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_hdl>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%eax
and    $0xfffffffc,%eax
cmp    $0x80,%eax
je     118d <signal_hdl+0x2d>
mov    %edi,%edx
mov    0x2e66(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
add    $0x10,%rsp
pop    %rbx
jmp    1070 <syslog@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <time@plt>
mov    %rbx,%rdi
call   1040 <localtime@plt>
mov    0x2e37(%rip),%rcx
mov    (%rcx),%ebx
mov    %rax,%rdi
call   1050 <asctime@plt>
lea    0xe46(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1070 <syslog@plt>
xor    %eax,%eax
call   1030 <closelog@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@LOG_NOTICE = global i32 0
@.str = [24 x i8] c"stopped on signal at %s\00"
@.str.1 = [25 x i8] c"got signal %d. ignore...\00"
define void @signal_hdl(i32 %0, i32* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca %struct.tm*
%8 = alloca %struct.tm
%9 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%10 = load i32, i32* %4
switch i32 %10, label %23 [
i32 128, label %11
i32 130, label %11
i32 129, label %11
i32 131, label %11
]
11: ; preds = %3, %3, %3, %3
%12 = call i32 @time(i32* %9)
%13 = call %struct.tm* @localtime(i32* %9)
store %struct.tm* %13, %struct.tm** %7
%14 = load %struct.tm*, %struct.tm** %7
%15 = bitcast %struct.tm* %8 to i8*
%16 = bitcast %struct.tm* %14 to i8*
%17 = load i32, i32* @LOG_NOTICE
%18 = load %struct.tm*, %struct.tm** %7
%19 = call i32 @asctime(%struct.tm* %18)
%20 = call i32 @syslog(i32 %17, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = call i32 (...) @closelog()
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %3
%24 = load i32, i32* @LOG_NOTICE
%25 = load i32, i32* %4
%26 = call i32 @syslog(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %25)
br label %27
27: ; preds = %23
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@LOG_NOTICE = global i32 0
@.str = [24 x i8] c"stopped on signal at %s\00"
@.str.1 = [25 x i8] c"got signal %d. ignore...\00"
define void @signal_hdl(i32 %0, i32* nocapture readnone %1, i8* nocapture readnone %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = and i32 %0, -4
%7 = icmp eq i32 %6, 128
br i1 %7, label %8, label %16
8: ; preds = %3
%9 = call i32 @time(i32* %4)
%10 = call %struct.tm* @localtime(i32* %4)
%11 = load i32, i32* @LOG_NOTICE
%12 = call i32 @asctime(%struct.tm* %10)
%13 = call i32 @syslog(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 (...) @closelog()
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %3
%17 = load i32, i32* @LOG_NOTICE
%18 = tail call i32 @syslog(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %0)
ret void
}