#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ WNOHANG;
int errno;
int /*<<< orphan*/ printf(char *, int);
int waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
void handle_sigchld() {
  pid_t pid;
  int saved_errno = errno;
  while ((pid = waitpid((pid_t)(-1), NULL, WNOHANG)) > 0) {
    printf("Il processo id:%d è terminato con successo.\n", pid);
  }
  errno = saved_errno;
}


x86 assembly (clang, -O0):
<handle_sigchld>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <waitpid@plt>
mov    %eax,-0x4(%rbp)
cmp    $0x0,%eax
jle    116b <handle_sigchld+0x4b>
mov    -0x4(%rbp),%esi
lea    0xe9f(%rip),%rdi
call   1030 <printf@plt>
jmp    1134 <handle_sigchld+0x14>
mov    -0x8(%rbp),%ecx
mov    0x2e63(%rip),%rax
mov    %ecx,(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<handle_sigchld>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2eaa(%rip),%r14
mov    (%r14),%r15d
mov    0x2eb0(%rip),%rbp
mov    0x0(%rbp),%edx
mov    $0xffffffff,%edi
xor    %esi,%esi
call   1040 <waitpid@plt>
test   %eax,%eax
jle    117d <handle_sigchld+0x5d>
lea    0xeae(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
mov    0x0(%rbp),%edx
mov    $0xffffffff,%edi
xor    %esi,%esi
call   1040 <waitpid@plt>
test   %eax,%eax
jg     1160 <handle_sigchld+0x40>
mov    %r15d,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@WNOHANG = global i32 0
@.str = [46 x i8] c"Il processo id:%d \C3\A8 terminato con successo.\0A\00"
define void @handle_sigchld() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @errno
store i32 %3, i32* %2
br label %4
4: ; preds = %8, %0
%5 = load i32, i32* @WNOHANG
%6 = call i32 @waitpid(i32 -1, i32* null, i32 %5)
store i32 %6, i32* %1
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %4
%9 = load i32, i32* %1
%10 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %9)
br label %4
11: ; preds = %4
%12 = load i32, i32* %2
store i32 %12, i32* @errno
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@WNOHANG = global i32 0
@.str = [46 x i8] c"Il processo id:%d \C3\A8 terminato con successo.\0A\00"
define void @handle_sigchld() {
%1 = load i32, i32* @errno
%2 = load i32, i32* @WNOHANG
%3 = tail call i32 @waitpid(i32 -1, i32* null, i32 %2)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %0, %5
%6 = phi i32 [ %9, %5 ], [ %3, %0 ]
%7 = tail call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = load i32, i32* @WNOHANG
%9 = tail call i32 @waitpid(i32 -1, i32* null, i32 %8)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %5, label %11
11: ; preds = %5, %0
store i32 %1, i32* @errno
ret void
}