#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;
#define SIGINT 133
#define SIGKILL 132
#define SIGQUIT 131
#define SIGSTOP 130
#define SIGTERM 129
#define SIGTSTP 128
int /*<<< orphan*/ clean_garbage();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
char *getcurrenttime();
int /*<<< orphan*/ printf(char *, char *, ...);
void sig_handler(int s) {
  switch (s) {
  case SIGINT:
  case SIGKILL:
  case SIGQUIT:
  case SIGSTOP:
  case SIGTERM:
  case SIGTSTP:
    printf("[%s] Exiting process\n", getcurrenttime());
    clean_garbage();
    exit(EXIT_SUCCESS);
    break;
  default:
    printf("[%s] Caught unused signal: %d\n", getcurrenttime(), s);
    break;
  }
}


x86 assembly (clang, -O0):
<sig_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffff80,%eax
sub    $0x5,%eax
ja     118c <sig_handler+0x4c>
jmp    115f <sig_handler+0x1f>
mov    $0x0,%al
call   1040 <getcurrenttime@plt>
mov    %rax,%rsi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <clean_garbage@plt>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1040 <getcurrenttime@plt>
mov    %rax,%rsi
mov    -0x4(%rbp),%edx
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sig_handler>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebx
lea    -0x80(%rbx),%ebp
xor    %eax,%eax
call   1040 <getcurrenttime@plt>
cmp    $0x5,%ebp
jbe    116d <sig_handler+0x2d>
lea    0xebb(%rip),%rdi
mov    %rax,%rsi
mov    %ebx,%edx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <printf@plt>
lea    0xe8c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1050 <clean_garbage@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [22 x i8] c"[%s] Exiting process\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [31 x i8] c"[%s] Caught unused signal: %d\0A\00"
define void @sig_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %10 [
i32 133, label %4
i32 132, label %4
i32 131, label %4
i32 130, label %4
i32 129, label %4
i32 128, label %4
]
4: ; preds = %1, %1, %1, %1, %1, %1
%5 = call i8* (...) @getcurrenttime()
%6 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = call i32 (...) @clean_garbage()
%8 = load i32, i32* @EXIT_SUCCESS
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = call i8* (...) @getcurrenttime()
%12 = load i32, i32* %2
%13 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %11, i32 %12)
br label %14
14: ; preds = %10
ret void
}

LLVM IR (-O2):
@.str = [22 x i8] c"[%s] Exiting process\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.1 = [31 x i8] c"[%s] Caught unused signal: %d\0A\00"
define void @sig_handler(i32 %0) {
%2 = add i32 %0, -128
%3 = icmp ult i32 %2, 6
%4 = tail call i8* (...) @getcurrenttime()
br i1 %3, label %5, label %10
5: ; preds = %1
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %4)
%7 = tail call i32 (...) @clean_garbage()
%8 = load i32, i32* @EXIT_SUCCESS
%9 = tail call i32 @exit(i32 %8)
unreachable
10: ; preds = %1
%11 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 %0)
ret void
}