#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 SIGQUIT;
int SIGTSTP;
int SIGUSR1;
int SIGUSR2;
int /*<<< orphan*/ printf(char *, ...);
void signal_handler(int signal) {
  printf("Caught signal %d\t", signal);
  if (signal == SIGTSTP)
    printf("SIGTSTP (Ctrl-Z)");
  else if (signal == SIGQUIT)
    printf("SIGQUIT (Ctrl-\\)");
  else if (signal == SIGUSR1)
    printf("SIGUSR1");
  else if (signal == SIGUSR2)
    printf("SIGUSR2");
  printf("\n");
}


x86 assembly (clang, -O0):
<signal_handler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xedb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    0x2ea2(%rip),%rcx
cmp    (%rcx),%eax
jne    1151 <signal_handler+0x41>
lea    0xecd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11ca <signal_handler+0xba>
mov    -0x4(%rbp),%eax
mov    0x2e85(%rip),%rcx
cmp    (%rcx),%eax
jne    1176 <signal_handler+0x66>
lea    0xeb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c5 <signal_handler+0xb5>
mov    -0x4(%rbp),%eax
mov    0x2e68(%rip),%rcx
cmp    (%rcx),%eax
jne    119b <signal_handler+0x8b>
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c0 <signal_handler+0xb0>
mov    -0x4(%rbp),%eax
mov    0x2e23(%rip),%rcx
cmp    (%rcx),%eax
jne    11bb <signal_handler+0xab>
lea    0xe88(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c0 <signal_handler+0xb0>
jmp    11c5 <signal_handler+0xb5>
jmp    11ca <signal_handler+0xba>
lea    0xe73(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<signal_handler>:
push   %rbx
mov    %edi,%ebx
lea    0xed6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e9e(%rip),%rax
cmp    %ebx,(%rax)
jne    1147 <signal_handler+0x27>
lea    0xecd(%rip),%rdi
jmp    1181 <signal_handler+0x61>
mov    0x2e92(%rip),%rax
cmp    %ebx,(%rax)
jne    115b <signal_handler+0x3b>
lea    0xeca(%rip),%rdi
jmp    1181 <signal_handler+0x61>
mov    0x2e86(%rip),%rax
cmp    %ebx,(%rax)
jne    116f <signal_handler+0x4f>
lea    0xec7(%rip),%rdi
jmp    1181 <signal_handler+0x61>
mov    0x2e52(%rip),%rax
cmp    %ebx,(%rax)
jne    1188 <signal_handler+0x68>
lea    0xebb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
pop    %rbx
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"Caught signal %d\09\00"
@SIGTSTP = global i32 0
@.str.1 = [17 x i8] c"SIGTSTP (Ctrl-Z)\00"
@SIGQUIT = global i32 0
@.str.2 = [17 x i8] c"SIGQUIT (Ctrl-\\)\00"
@SIGUSR1 = global i32 0
@.str.3 = [8 x i8] c"SIGUSR1\00"
@SIGUSR2 = global i32 0
@.str.4 = [8 x i8] c"SIGUSR2\00"
@.str.5 = [2 x i8] c"\0A\00"
define void @signal_handler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = load i32, i32* %2
%6 = load i32, i32* @SIGTSTP
%7 = icmp eq i32 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %31
10: ; preds = %1
%11 = load i32, i32* %2
%12 = load i32, i32* @SIGQUIT
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %30
16: ; preds = %10
%17 = load i32, i32* %2
%18 = load i32, i32* @SIGUSR1
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %29
22: ; preds = %16
%23 = load i32, i32* %2
%24 = load i32, i32* @SIGUSR2
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
br label %29
29: ; preds = %28, %20
br label %30
30: ; preds = %29, %14
br label %31
31: ; preds = %30, %8
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [18 x i8] c"Caught signal %d\09\00"
@SIGTSTP = global i32 0
@.str.1 = [17 x i8] c"SIGTSTP (Ctrl-Z)\00"
@SIGQUIT = global i32 0
@.str.2 = [17 x i8] c"SIGQUIT (Ctrl-\\)\00"
@SIGUSR1 = global i32 0
@.str.3 = [8 x i8] c"SIGUSR1\00"
@SIGUSR2 = global i32 0
@.str.4 = [8 x i8] c"SIGUSR2\00"
define void @signal_handler(i32 %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = load i32, i32* @SIGTSTP
%4 = icmp eq i32 %3, %0
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = load i32, i32* @SIGQUIT
%7 = icmp eq i32 %6, %0
br i1 %7, label %14, label %8
8: ; preds = %5
%9 = load i32, i32* @SIGUSR1
%10 = icmp eq i32 %9, %0
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = load i32, i32* @SIGUSR2
%13 = icmp eq i32 %12, %0
br i1 %13, label %14, label %17
14: ; preds = %11, %8, %5, %1
%15 = phi i8* [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), %1 ], [ getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), %5 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), %8 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), %11 ]
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %15)
br label %17
17: ; preds = %14, %11
%18 = tail call i32 @putchar(i32 10)
ret void
}