#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 SIGCHLD;
int SIGPIPE;
scalar_t__ SIG_ERR;
int /*<<< orphan*/ SIG_IGN;
int /*<<< orphan*/ WUNTRACED;
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ signal(int, int /*<<< orphan*/);
int waitpid(int, int *, int /*<<< orphan*/);
void traitement_signal(int sig) {
  printf("Signal %d reçu\n", sig);
  int status;
  if (sig == SIGCHLD) {
    if (waitpid(-1, &status, WUNTRACED) == -1)
      perror("waitpid");
  } else if (sig == SIGPIPE)
    if (signal(sig, SIG_IGN) == SIG_ERR)
      perror("signal(SIGPIPE, SIG_IGN)");
}


x86 assembly (clang, -O0):
<traitement_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xeab(%rip),%rdi
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
mov    0x2e84(%rip),%rcx
cmp    (%rcx),%eax
jne    119d <traitement_signal+0x5d>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
lea    -0x8(%rbp),%rsi
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    1198 <traitement_signal+0x58>
lea    0xe7e(%rip),%rdi
call   1060 <perror@plt>
jmp    11e6 <traitement_signal+0xa6>
mov    -0x4(%rbp),%eax
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%eax
jne    11e1 <traitement_signal+0xa1>
mov    -0x4(%rbp),%edi
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
call   1040 <signal@plt>
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%rax
jne    11dc <traitement_signal+0x9c>
lea    0xe42(%rip),%rdi
call   1060 <perror@plt>
jmp    11e1 <traitement_signal+0xa1>
jmp    11e6 <traitement_signal+0xa6>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<traitement_signal>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xeb2(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    0x2e8c(%rip),%rax
cmp    %ebx,(%rax)
jne    118b <traitement_signal+0x4b>
mov    0x2e69(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rsi
mov    $0xffffffff,%edi
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    11b2 <traitement_signal+0x72>
lea    0xe8d(%rip),%rdi
call   1060 <perror@plt>
jmp    11b2 <traitement_signal+0x72>
mov    0x2e2e(%rip),%rax
cmp    %ebx,(%rax)
jne    11b2 <traitement_signal+0x72>
mov    0x2e43(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1040 <signal@plt>
mov    0x2e1b(%rip),%rcx
cmp    (%rcx),%rax
je     11b8 <traitement_signal+0x78>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe5a(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
jmp    1060 <perror@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Signal %d re\C3\A7u\0A\00"
@SIGCHLD = global i32 0
@WUNTRACED = global i32 0
@.str.1 = [8 x i8] c"waitpid\00"
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@SIG_ERR = global i64 0
@.str.2 = [25 x i8] c"signal(SIGPIPE, SIG_IGN)\00"
define void @traitement_signal(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* %2
%5 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* %2
%7 = load i32, i32* @SIGCHLD
%8 = icmp eq i32 %6, %7
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i32, i32* @WUNTRACED
%11 = call i32 @waitpid(i32 -1, i32* %3, i32 %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
br label %30
16: ; preds = %1
%17 = load i32, i32* %2
%18 = load i32, i32* @SIGPIPE
%19 = icmp eq i32 %17, %18
br i1 %19, label %20, label %29
20: ; preds = %16
%21 = load i32, i32* %2
%22 = load i32, i32* @SIG_IGN
%23 = call i64 @signal(i32 %21, i32 %22)
%24 = load i64, i64* @SIG_ERR
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %20
%27 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %28
28: ; preds = %26, %20
br label %29
29: ; preds = %28, %16
br label %30
30: ; preds = %29, %15
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Signal %d re\C3\A7u\0A\00"
@SIGCHLD = global i32 0
@WUNTRACED = global i32 0
@.str.1 = [8 x i8] c"waitpid\00"
@SIGPIPE = global i32 0
@SIG_IGN = global i32 0
@SIG_ERR = global i64 0
@.str.2 = [25 x i8] c"signal(SIGPIPE, SIG_IGN)\00"
define void @traitement_signal(i32 %0) {
%2 = alloca i32
%3 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = bitcast i32* %2 to i8*
%5 = load i32, i32* @SIGCHLD
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = load i32, i32* @WUNTRACED
%9 = call i32 @waitpid(i32 -1, i32* %2, i32 %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %23
11: ; preds = %7
%12 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %23
13: ; preds = %1
%14 = load i32, i32* @SIGPIPE
%15 = icmp eq i32 %14, %0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i32, i32* @SIG_IGN
%18 = tail call i64 @signal(i32 %0, i32 %17)
%19 = load i64, i64* @SIG_ERR
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %13, %21, %16, %7, %11
ret void
}