#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*/ cleanExit(int);
int /*<<< orphan*/ printf(char *, ...);
void signalHandler(int signum) {
  switch (signum) {
  case SIGHUP:
    printf("Exiting on SIGHUP\n");
    break;
  case SIGINT:
    printf("Exiting on SIGINT\n");
    break;
  case SIGTERM:
    printf("Exiting on SIGTERM\n");
    break;
  default:
    printf("Exiting on signal %d\n", signum);
  }
  cleanExit(1);
}


x86 assembly (clang, -O0):
<signalHandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x80,%eax
je     118d <signalHandler+0x6d>
jmp    1141 <signalHandler+0x21>
mov    -0x8(%rbp),%eax
sub    $0x81,%eax
je     117a <signalHandler+0x5a>
jmp    1154 <signalHandler+0x34>
mov    -0x8(%rbp),%eax
sub    $0x82,%eax
jne    11a0 <signalHandler+0x80>
jmp    1167 <signalHandler+0x47>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b1 <signalHandler+0x91>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b1 <signalHandler+0x91>
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11b1 <signalHandler+0x91>
mov    -0x4(%rbp),%esi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1040 <cleanExit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signalHandler>:
push   %rax
cmp    $0x80,%edi
je     1159 <signalHandler+0x29>
mov    %edi,%esi
cmp    $0x81,%edi
je     1167 <signalHandler+0x37>
cmp    $0x82,%esi
jne    1175 <signalHandler+0x45>
lea    0xee9(%rip),%rdi
call   1030 <puts@plt>
jmp    1183 <signalHandler+0x53>
lea    0xeb6(%rip),%rdi
call   1030 <puts@plt>
jmp    1183 <signalHandler+0x53>
lea    0xebb(%rip),%rdi
call   1030 <puts@plt>
jmp    1183 <signalHandler+0x53>
lea    0xe84(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
pop    %rax
jmp    1050 <cleanExit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Exiting on SIGHUP\0A\00"
@.str.1 = [19 x i8] c"Exiting on SIGINT\0A\00"
@.str.2 = [20 x i8] c"Exiting on SIGTERM\0A\00"
@.str.3 = [22 x i8] c"Exiting on signal %d\0A\00"
define void @signalHandler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %10 [
i32 130, label %4
i32 129, label %6
i32 128, label %8
]
4: ; preds = %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %13
6: ; preds = %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
br label %13
8: ; preds = %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
br label %13
10: ; preds = %1
%11 = load i32, i32* %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %10, %8, %6, %4
%14 = call i32 @cleanExit(i32 1)
ret void
}

LLVM IR (-O2):
@.str.3 = [22 x i8] c"Exiting on signal %d\0A\00"
@str = [19 x i8] c"Exiting on SIGTERM\00"
@str.4 = [18 x i8] c"Exiting on SIGINT\00"
@str.5 = [18 x i8] c"Exiting on SIGHUP\00"
define void @signalHandler(i32 %0) {
switch i32 %0, label %8 [
i32 130, label %2
i32 129, label %4
i32 128, label %6
]
2: ; preds = %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.5, i64 0, i64 0))
br label %10
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.4, i64 0, i64 0))
br label %10
6: ; preds = %1
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %10
8: ; preds = %1
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %10
10: ; preds = %8, %6, %4, %2
%11 = tail call i32 @cleanExit(i32 1)
ret void
}