#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 */
scalar_t__ ECHILD;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int wait(int *);
void waitall(void) {
  pid_t pid;
  int status;
  while (1) {
    pid = wait(&status);
    printf("--> Son process %d ends now\n", pid);
    if (pid == -1) {
      if (errno == ECHILD)
        break;
      perror("wait");
      exit(-1);
    }
  }
}


x86 assembly (clang, -O0):
<waitall>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
call   1060 <wait@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xea2(%rip),%rdi
call   1030 <printf@plt>
cmpl   $0xffffffff,-0x4(%rbp)
jne    11a2 <waitall+0x62>
mov    0x2e6c(%rip),%rax
mov    (%rax),%rax
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%rax
jne    118c <waitall+0x4c>
jmp    11a7 <waitall+0x67>
lea    0xe8a(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
jmp    1148 <waitall+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitall>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%r14
lea    0xeac(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1060 <wait@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
cmp    $0xffffffff,%ebp
jne    1160 <waitall+0x20>
mov    0x2e60(%rip),%rax
mov    (%rax),%rax
mov    0x2e4e(%rip),%rcx
cmp    (%rcx),%rax
jne    1198 <waitall+0x58>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe7e(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [29 x i8] c"--> Son process %d ends now\0A\00"
@errno = global i64 0
@ECHILD = global i64 0
@.str.1 = [5 x i8] c"wait\00"
define void @waitall() {
%1 = alloca i32
%2 = alloca i32
br label %3
3: ; preds = %0, %17
%4 = call i32 @wait(i32* %2)
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %17
9: ; preds = %3
%10 = load i64, i64* @errno
%11 = load i64, i64* @ECHILD
%12 = icmp eq i64 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %9
br label %18
14: ; preds = %9
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %3
br label %3
18: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"--> Son process %d ends now\0A\00"
@errno = global i64 0
@ECHILD = global i64 0
@.str.1 = [5 x i8] c"wait\00"
define void @waitall() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
br label %3
3: ; preds = %3, %0
%4 = call i32 @wait(i32* %1)
%5 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = icmp eq i32 %4, -1
br i1 %6, label %7, label %3
7: ; preds = %3
%8 = load i64, i64* @errno
%9 = load i64, i64* @ECHILD
%10 = icmp eq i64 %8, %9
br i1 %10, label %14, label %11
11: ; preds = %7
%12 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; preds = %7
ret void
}