#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 */
#define SIGHUP 130
#define SIGINT 129
#define SIGTERM 128
int /*<<< orphan*/ cleanup();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ loging(char *, int /*<<< orphan*/);
void handle_signal(int sig) {
  switch (sig) {
  case SIGHUP:
    loging("SIGHUP received", 0);
    break;
  case SIGTERM:
    loging("SIGTERM received", 0);
    cleanup();
    exit(0);
    break;
  case SIGINT:
    loging("SIGINT received", 0);
    cleanup();
    exit(0);
  default:
    cleanup();
    exit(0);
  }
}


x86 assembly (clang, -O0):
<handle_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x80,%eax
je     118a <handle_signal+0x5a>
jmp    1151 <handle_signal+0x21>
mov    -0x8(%rbp),%eax
sub    $0x81,%eax
je     11a6 <handle_signal+0x76>
jmp    1164 <handle_signal+0x34>
mov    -0x8(%rbp),%eax
sub    $0x82,%eax
jne    11c2 <handle_signal+0x92>
jmp    1177 <handle_signal+0x47>
lea    0xe82(%rip),%rdi
xor    %esi,%esi
call   1030 <loging@plt>
jmp    11d0 <handle_signal+0xa0>
lea    0xe7f(%rip),%rdi
xor    %esi,%esi
call   1030 <loging@plt>
mov    $0x0,%al
call   1040 <cleanup@plt>
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xe74(%rip),%rdi
xor    %esi,%esi
call   1030 <loging@plt>
mov    $0x0,%al
call   1040 <cleanup@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    $0x0,%al
call   1040 <cleanup@plt>
xor    %edi,%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_signal>:
push   %rax
cmp    $0x82,%edi
jne    1148 <handle_signal+0x18>
lea    0xec0(%rip),%rdi
xor    %esi,%esi
pop    %rax
jmp    1030 <loging@plt>
cmp    $0x80,%edi
je     1161 <handle_signal+0x31>
cmp    $0x81,%edi
jne    116f <handle_signal+0x3f>
lea    0xec2(%rip),%rdi
jmp    1168 <handle_signal+0x38>
lea    0xea8(%rip),%rdi
xor    %esi,%esi
call   1030 <loging@plt>
xor    %eax,%eax
call   1040 <cleanup@plt>
xor    %edi,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@.str = [16 x i8] c"SIGHUP received\00"
@.str.1 = [17 x i8] c"SIGTERM received\00"
@.str.2 = [16 x i8] c"SIGINT received\00"
define void @handle_signal(i32 %0) {
switch i32 %0, label %12 [
i32 130, label %2
i32 128, label %4
i32 129, label %8
]
2: ; preds = %1
%3 = tail call i32 @loging(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 0)
ret void
4: ; preds = %1
%5 = tail call i32 @loging(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 0)
%6 = tail call i32 (...) @cleanup()
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %1
%9 = tail call i32 @loging(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 0)
%10 = tail call i32 (...) @cleanup()
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %1
%13 = tail call i32 (...) @cleanup()
%14 = tail call i32 @exit(i32 0)
unreachable
}