#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 /*<<< orphan*/ SIGKILL;
int /*<<< orphan*/ WNOHANG;
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int);
int waitpid(int, int *, int /*<<< orphan*/);
void traitement_signal(int sig) {
  int pid;
  int status;
  while ((pid = waitpid(-1, &status, WNOHANG)) != -1)
    kill(pid, SIGKILL);
  printf("Signal %d reçu \n", sig);
}


x86 assembly (clang, -O0):
<traitement_signal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
lea    -0xc(%rbp),%rsi
call   1050 <waitpid@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     1174 <traitement_signal+0x44>
mov    -0x8(%rbp),%edi
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
call   1040 <kill@plt>
jmp    113b <traitement_signal+0xb>
mov    -0x4(%rbp),%esi
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<traitement_signal>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%r14d
mov    0x2ea7(%rip),%r15
mov    (%r15),%edx
lea    0x4(%rsp),%rsi
mov    $0xffffffff,%edi
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
je     118f <traitement_signal+0x5f>
mov    0x2e79(%rip),%rbp
lea    0x4(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%rbp),%esi
mov    %eax,%edi
call   1040 <kill@plt>
mov    (%r15),%edx
mov    $0xffffffff,%edi
mov    %rbx,%rsi
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    1170 <traitement_signal+0x40>
lea    0xe6a(%rip),%rdi
mov    %r14d,%esi
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@WNOHANG = global i32 0
@SIGKILL = global i32 0
@.str = [18 x i8] c"Signal %d re\C3\A7u \0A\00"
define void @traitement_signal(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 %0, i32* %2
br label %5
5: ; preds = %9, %1
%6 = load i32, i32* @WNOHANG
%7 = call i32 @waitpid(i32 -1, i32* %4, i32 %6)
store i32 %7, i32* %3
%8 = icmp ne i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %5
%10 = load i32, i32* %3
%11 = load i32, i32* @SIGKILL
%12 = call i32 @kill(i32 %10, i32 %11)
br label %5
13: ; preds = %5
%14 = load i32, i32* %2
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %14)
ret void
}

LLVM IR (-O2):
@WNOHANG = global i32 0
@SIGKILL = global i32 0
@.str = [18 x i8] c"Signal %d re\C3\A7u \0A\00"
define void @traitement_signal(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @WNOHANG
%5 = call i32 @waitpid(i32 -1, i32* %2, i32 %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %14, label %7
7: ; preds = %1, %7
%8 = phi i32 [ %12, %7 ], [ %5, %1 ]
%9 = load i32, i32* @SIGKILL
%10 = call i32 @kill(i32 %8, i32 %9)
%11 = load i32, i32* @WNOHANG
%12 = call i32 @waitpid(i32 -1, i32* %2, i32 %11)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %7
14: ; preds = %7, %1
%15 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %0)
ret void
}