#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*/ *);
char *malloc(int);
char *strsignal(int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ unlink(char *);
void signal_hdl(int sig, siginfo_t *siginfo, void *context) {
  struct tm *newtime;
  char *sig_desc;
  struct tm tim;
  time_t ltime;
  sig_desc = malloc(100);
  sig_desc = strsignal(sig);
  switch (sig) {
  case SIGTERM:
  case SIGINT:
  case SIGQUIT:
  case SIGHUP:
    time(&ltime);
    newtime = localtime(&ltime);
    syslog(LOG_NOTICE, "stopped by terminate signal at: %s", asctime(newtime));
    closelog();
    unlink("/var/run/mapd.pid");
    system("sync");
    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    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x64,%edi
call   1090 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
call   10b0 <strsignal@plt>
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x3,%eax
ja     1243 <signal_hdl+0xa3>
jmp    11e1 <signal_hdl+0x41>
lea    -0x34(%rbp),%rdi
call   1080 <time@plt>
lea    -0x34(%rbp),%rdi
call   1040 <localtime@plt>
mov    %rax,-0x20(%rbp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <asctime@plt>
mov    -0x38(%rbp),%edi
mov    %eax,%edx
lea    0xde8(%rip),%rsi
call   10a0 <syslog@plt>
mov    $0x0,%al
call   1030 <closelog@plt>
lea    0xdf8(%rip),%rdi
call   1050 <unlink@plt>
lea    0xdfe(%rip),%rdi
call   1070 <system@plt>
xor    %edi,%edi
call   10c0 <exit@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xde4(%rip),%rsi
call   10a0 <syslog@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_hdl>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
call   10a0 <strsignal@plt>
mov    %ebx,%eax
and    $0xfffffffc,%eax
cmp    $0x80,%eax
je     11c4 <signal_hdl+0x34>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe82(%rip),%rsi
mov    %ebx,%edx
add    $0x10,%rsp
pop    %rbx
jmp    1090 <syslog@plt>
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
call   1080 <time@plt>
mov    %rbx,%rdi
call   1040 <localtime@plt>
mov    0x2e00(%rip),%rcx
mov    (%rcx),%ebx
mov    %rax,%rdi
call   1060 <asctime@plt>
lea    0xe0f(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1090 <syslog@plt>
xor    %eax,%eax
call   1030 <closelog@plt>
lea    0xe1b(%rip),%rdi
call   1050 <unlink@plt>
lea    0xe21(%rip),%rdi
call   1070 <system@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.tm = type { i32 }
@LOG_NOTICE = global i32 0
@.str = [35 x i8] c"stopped by terminate signal at: %s\00"
@.str.1 = [18 x i8] c"/var/run/mapd.pid\00"
@.str.2 = [5 x i8] c"sync\00"
@.str.3 = [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 i8*
%9 = alloca %struct.tm
%10 = alloca i32
store i32 %0, i32* %4
store i32* %1, i32** %5
store i8* %2, i8** %6
%11 = call i8* @malloc(i32 100)
store i8* %11, i8** %8
%12 = load i32, i32* %4
%13 = call i8* @strsignal(i32 %12)
store i8* %13, i8** %8
%14 = load i32, i32* %4
switch i32 %14, label %26 [
i32 128, label %15
i32 130, label %15
i32 129, label %15
i32 131, label %15
]
15: ; preds = %3, %3, %3, %3
%16 = call i32 @time(i32* %10)
%17 = call %struct.tm* @localtime(i32* %10)
store %struct.tm* %17, %struct.tm** %7
%18 = load i32, i32* @LOG_NOTICE
%19 = load %struct.tm*, %struct.tm** %7
%20 = call i32 @asctime(%struct.tm* %19)
%21 = call i32 @syslog(i32 %18, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = call i32 (...) @closelog()
%23 = call i32 @unlink(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %3
%27 = load i32, i32* @LOG_NOTICE
%28 = load i32, i32* %4
%29 = call i32 @syslog(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %26
ret void
}

LLVM IR (-O2):
%struct.tm = type { i32 }
@LOG_NOTICE = global i32 0
@.str = [35 x i8] c"stopped by terminate signal at: %s\00"
@.str.1 = [18 x i8] c"/var/run/mapd.pid\00"
@.str.2 = [5 x i8] c"sync\00"
@.str.3 = [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 = tail call i8* @strsignal(i32 %0)
%7 = and i32 %0, -4
%8 = icmp eq i32 %7, 128
br i1 %8, label %9, label %19
9: ; preds = %3
%10 = call i32 @time(i32* %4)
%11 = call %struct.tm* @localtime(i32* %4)
%12 = load i32, i32* @LOG_NOTICE
%13 = call i32 @asctime(%struct.tm* %11)
%14 = call i32 @syslog(i32 %12, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = call i32 (...) @closelog()
%16 = call i32 @unlink(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @system(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %3
%20 = load i32, i32* @LOG_NOTICE
%21 = tail call i32 @syslog(i32 %20, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i32 %0)
ret void
}