#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 SIGCONT;
int SIGTTIN;
int /*<<< orphan*/ SIG_DFL;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ raise(int);
int /*<<< orphan*/ signal(int, int /*<<< orphan*/);
void sighandler(int signo) {
  if (signo == SIGTTIN)
    printf("Handler executed for signal %d (SIGTTIN)\n", signo);
  else if (signo == SIGCONT)
    printf("Handler executed for signal %d (SIGCONT)\n", signo);
  else
    printf("Handler executed for signal %d\n", signo);
  printf("Executing default signal handler for signal.\n");
  signal(signo, SIG_DFL);
  raise(signo);
}


x86 assembly (clang, -O0):
<sighandler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e9b(%rip),%rcx
cmp    (%rcx),%eax
jne    1163 <sighandler+0x33>
mov    -0x4(%rbp),%esi
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a1 <sighandler+0x71>
mov    -0x4(%rbp),%eax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
jne    118b <sighandler+0x5b>
mov    -0x4(%rbp),%esi
lea    0xeab(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    119c <sighandler+0x6c>
mov    -0x4(%rbp),%esi
lea    0xebf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11a1 <sighandler+0x71>
lea    0xecc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
call   1050 <signal@plt>
mov    -0x4(%rbp),%edi
call   1030 <raise@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sighandler>:
push   %rbx
mov    %edi,%ebx
mov    0x2e96(%rip),%rax
mov    0x2e97(%rip),%rcx
cmp    %edi,(%rcx)
lea    0xed0(%rip),%rcx
lea    0xef3(%rip),%rdx
cmove  %rcx,%rdx
cmp    %edi,(%rax)
lea    0xe92(%rip),%rdi
cmovne %rdx,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xef2(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1060 <signal@plt>
mov    %ebx,%edi
pop    %rbx
jmp    1030 <raise@plt>

LLVM IR (-O0):
@SIGTTIN = global i32 0
@.str = [42 x i8] c"Handler executed for signal %d (SIGTTIN)\0A\00"
@SIGCONT = global i32 0
@.str.1 = [42 x i8] c"Handler executed for signal %d (SIGCONT)\0A\00"
@.str.2 = [32 x i8] c"Handler executed for signal %d\0A\00"
@.str.3 = [46 x i8] c"Executing default signal handler for signal.\0A\00"
@SIG_DFL = global i32 0
define void @sighandler(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = load i32, i32* %2
%4 = load i32, i32* @SIGTTIN
%5 = icmp eq i32 %3, %4
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %20
9: ; preds = %1
%10 = load i32, i32* %2
%11 = load i32, i32* @SIGCONT
%12 = icmp eq i32 %10, %11
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %19
16: ; preds = %9
%17 = load i32, i32* %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %16, %13
br label %20
20: ; preds = %19, %6
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.3, i64 0, i64 0))
%22 = load i32, i32* %2
%23 = load i32, i32* @SIG_DFL
%24 = call i32 @signal(i32 %22, i32 %23)
%25 = load i32, i32* %2
%26 = call i32 @raise(i32 %25)
ret void
}

LLVM IR (-O2):
@SIGTTIN = global i32 0
@.str = [42 x i8] c"Handler executed for signal %d (SIGTTIN)\0A\00"
@SIGCONT = global i32 0
@.str.1 = [42 x i8] c"Handler executed for signal %d (SIGCONT)\0A\00"
@.str.2 = [32 x i8] c"Handler executed for signal %d\0A\00"
@SIG_DFL = global i32 0
@str = [45 x i8] c"Executing default signal handler for signal.\00"
define void @sighandler(i32 %0) {
%2 = load i32, i32* @SIGTTIN
%3 = icmp eq i32 %2, %0
%4 = load i32, i32* @SIGCONT
%5 = icmp eq i32 %4, %0
%6 = select i1 %5, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0)
%7 = select i1 %3, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %7, i32 %0)
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str, i64 0, i64 0))
%10 = load i32, i32* @SIG_DFL
%11 = tail call i32 @signal(i32 %0, i32 %10)
%12 = tail call i32 @raise(i32 %0)
ret void
}