#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 SIGINT 131
#define SIGKILL 130
#define SIGSTOP 129
#define SIGUSR1 128
int /*<<< orphan*/ printf(char *, ...);
void signal_handler(int signo) {
  switch (signo) {
  case SIGUSR1:
    printf("signal SIGUSR1 is received\n");
    break;
  case SIGINT:
    printf("signal SIGINT is received\n");
    break;
  case SIGKILL:
  case SIGSTOP:
    break;
  default:
    printf("unknown signal %i is received\n", signo);
    break;
  }
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
sub    $0x80,%eax
je     115a <signal_handler+0x4a>
jmp    1131 <signal_handler+0x21>
mov    -0x8(%rbp),%eax
add    $0xffffff7f,%eax
sub    $0x2,%eax
jb     1180 <signal_handler+0x70>
jmp    1147 <signal_handler+0x37>
mov    -0x8(%rbp),%eax
sub    $0x83,%eax
je     116d <signal_handler+0x5d>
jmp    1185 <signal_handler+0x75>
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1196 <signal_handler+0x86>
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1196 <signal_handler+0x86>
jmp    1196 <signal_handler+0x86>
mov    -0x4(%rbp),%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
mov    %edi,%esi
lea    -0x81(%rsi),%eax
cmp    $0x2,%eax
jb     1149 <signal_handler+0x29>
cmp    $0x83,%esi
je     114a <signal_handler+0x2a>
cmp    $0x80,%esi
jne    1156 <signal_handler+0x36>
lea    0xef5(%rip),%rdi
jmp    1030 <puts@plt>
ret
lea    0xece(%rip),%rdi
jmp    1030 <puts@plt>
lea    0xea3(%rip),%rdi
xor    %eax,%eax
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"signal SIGUSR1 is received\0A\00"
@.str.1 = [27 x i8] c"signal SIGINT is received\0A\00"
@.str.2 = [31 x i8] c"unknown signal %i is received\0A\00"
define void @signal_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %9 [
i32 128, label %4
i32 131, label %6
i32 130, label %8
i32 129, label %8
]
4: ; preds = %1
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %12
6: ; preds = %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %12
8: ; preds = %1, %1
br label %12
9: ; preds = %1
%10 = load i32, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %10)
br label %12
12: ; preds = %9, %8, %6, %4
ret void
}

LLVM IR (-O2):
@.str.2 = [31 x i8] c"unknown signal %i is received\0A\00"
@str = [26 x i8] c"signal SIGINT is received\00"
@str.3 = [27 x i8] c"signal SIGUSR1 is received\00"
define void @signal_handler(i32 %0) {
switch i32 %0, label %6 [
i32 128, label %2
i32 131, label %4
i32 130, label %8
i32 129, label %8
]
2: ; preds = %1
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.3, i64 0, i64 0))
br label %8
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
br label %8
6: ; preds = %1
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %8
8: ; preds = %1, %1, %6, %4, %2
ret void
}