#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 SIGUSR1 129
#define SIGUSR2 128
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stderr;
void handle_signal(int signal) {
  switch (signal) {
  case SIGUSR1:
    printf("Got SIGUSR1, continuing...\n");
    break;
  case SIGUSR2:
    printf("Caught SIGUSR2, exiting now...\n");
    exit(0);
  default:
    fprintf(stderr, "Caught wrong signal: %d\n", signal);
    return;
  }
}


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     1175 <handle_signal+0x45>
jmp    1151 <handle_signal+0x21>
mov    -0x8(%rbp),%eax
sub    $0x81,%eax
jne    1188 <handle_signal+0x58>
jmp    1164 <handle_signal+0x34>
lea    0xe95(%rip),%rdi
call   1030 <printf@plt>
jmp    11a0 <handle_signal+0x70>
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xea1(%rip),%rsi
call   1040 <fprintf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_signal>:
push   %rax
cmp    $0x81,%edi
je     1159 <handle_signal+0x29>
mov    %edi,%edx
cmp    $0x80,%edi
je     1166 <handle_signal+0x36>
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
lea    0xead(%rip),%rsi
pop    %rax
jmp    1040 <fprintf@plt>
lea    0xed8(%rip),%rdi
pop    %rax
jmp    1030 <puts@plt>
lea    0xeac(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [28 x i8] c"Got SIGUSR1, continuing...\0A\00"
@.str.1 = [32 x i8] c"Caught SIGUSR2, exiting now...\0A\00"
@stderr = global i32 0
@.str.2 = [25 x i8] c"Caught wrong signal: %d\0A\00"
define void @handle_signal(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
switch i32 %3, label %9 [
i32 129, label %4
i32 128, label %6
]
4: ; preds = %1
%5 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
br label %13
6: ; preds = %1
%7 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @exit(i32 0)
unreachable
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* %2
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %11)
br label %13
13: ; preds = %9, %4
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str.2 = [25 x i8] c"Caught wrong signal: %d\0A\00"
@str = [31 x i8] c"Caught SIGUSR2, exiting now...\00"
@str.3 = [27 x i8] c"Got SIGUSR1, continuing...\00"
define void @handle_signal(i32 %0) {
switch i32 %0, label %7 [
i32 129, label %2
i32 128, label %4
]
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 %10
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i32 %0)
br label %10
10: ; preds = %7, %2
ret void
}