#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;
scalar_t__ WIFSIGNALED(int);
int WTERMSIG(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ wait(int *);
void traitement_signal(int sig) {
  int status;
  printf("Signal %d reçu\n", sig);
  if (sig == SIGCHLD) {
    wait(&status);
    if (WIFSIGNALED(status))
      printf("Fils terminé par signal: %d\n", WTERMSIG(status));
  }
}


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    11a2 <traitement_signal+0x62>
lea    -0x8(%rbp),%rdi
call   1060 <wait@plt>
mov    -0x8(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     119d <traitement_signal+0x5d>
mov    -0x8(%rbp),%edi
call   1050 <WTERMSIG@plt>
mov    %eax,%esi
lea    0xe79(%rip),%rdi
call   1030 <printf@plt>
jmp    11a2 <traitement_signal+0x62>
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    118f <traitement_signal+0x4f>
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
mov    0xc(%rsp),%edi
call   1040 <WIFSIGNALED@plt>
test   %rax,%rax
je     118f <traitement_signal+0x4f>
mov    0xc(%rsp),%edi
call   1050 <WTERMSIG@plt>
lea    0xe89(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Signal %d re\C3\A7u\0A\00"
@SIGCHLD = global i32 0
@.str.1 = [30 x i8] c"Fils termin\C3\A9 par signal: %d\0A\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 %19
9: ; preds = %1
%10 = call i32 @wait(i32* %3)
%11 = load i32, i32* %3
%12 = call i64 @WIFSIGNALED(i32 %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %9
%15 = load i32, i32* %3
%16 = call i32 @WTERMSIG(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %14, %9
br label %19
19: ; preds = %18, %1
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Signal %d re\C3\A7u\0A\00"
@SIGCHLD = global i32 0
@.str.1 = [30 x i8] c"Fils termin\C3\A9 par signal: %d\0A\00"
define void @traitement_signal(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %0)
%5 = load i32, i32* @SIGCHLD
%6 = icmp eq i32 %5, %0
br i1 %6, label %7, label %16
7: ; preds = %1
%8 = call i32 @wait(i32* %2)
%9 = load i32, i32* %2
%10 = call i64 @WIFSIGNALED(i32 %9)
%11 = icmp eq i64 %10, 0
br i1 %11, label %16, label %12
12: ; preds = %7
%13 = load i32, i32* %2
%14 = call i32 @WTERMSIG(i32 %13)
%15 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %7, %12, %1
ret void
}