#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 */
scalar_t__ ECHILD;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ poll(int /*<<< orphan*/ *, int /*<<< orphan*/, int);
int wait(int *);
void waitall(void) {
  int pid;
  int status;
  for (;;) {
    pid = wait(&status);
    if (pid == -1) {
      if (errno == ECHILD)
        break;
      perror("wait");
      exit(-1);
    }
    poll(NULL, 0, 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)
cmpl   $0xffffffff,-0x4(%rbp)
jne    1193 <waitall+0x53>
mov    0x2e7b(%rip),%rax
mov    (%rax),%rax
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
jne    117d <waitall+0x3d>
jmp    11a8 <waitall+0x68>
lea    0xe7c(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <poll@plt>
jmp    1148 <waitall+0x8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitall>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
call   1060 <wait@plt>
cmp    $0xffffffff,%eax
je     117b <waitall+0x3b>
lea    0xc(%rsp),%rbx
nopl   0x0(%rax)
xor    %edi,%edi
xor    %esi,%esi
mov    $0x1,%edx
call   1030 <poll@plt>
mov    %rbx,%rdi
call   1060 <wait@plt>
cmp    $0xffffffff,%eax
jne    1160 <waitall+0x20>
mov    0x2e5e(%rip),%rax
mov    (%rax),%rax
mov    0x2e4c(%rip),%rcx
cmp    (%rcx),%rax
jne    1197 <waitall+0x57>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe62(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

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

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