#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ WIFSTOPPED(int);
int /*<<< orphan*/ WUNTRACED;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ explain_wait_status(scalar_t__, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, long);
int /*<<< orphan*/ stderr;
scalar_t__ waitpid(int, int *, int /*<<< orphan*/);
void wait_for_ready_children(int cnt) {
  int i;
  pid_t p;
  int status;
  for (i = 0; i < cnt; i++) {
    p = waitpid(-1, &status, WUNTRACED);
    explain_wait_status(p, status);
    if (!WIFSTOPPED(status)) {
      fprintf(stderr, "Parent: Child with PID %ld has died unexpectedly!\n",
              (long)p);
      exit(1);
    }
  }
}


x86 assembly (clang, -O0):
<wait_for_ready_children>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11dc <wait_for_ready_children+0x8c>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%edi
lea    -0x14(%rbp),%rsi
call   1050 <waitpid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1070 <explain_wait_status@plt>
mov    -0x14(%rbp),%edi
call   1040 <WIFSTOPPED@plt>
cmp    $0x0,%eax
jne    11c9 <wait_for_ready_children+0x79>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe46(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    11ce <wait_for_ready_children+0x7e>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1162 <wait_for_ready_children+0x12>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_ready_children>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    11a2 <wait_for_ready_children+0x52>
mov    %edi,%ebx
mov    0x2e7b(%rip),%r12
lea    0x4(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    (%r12),%edx
mov    $0xffffffff,%edi
mov    %r14,%rsi
call   1050 <waitpid@plt>
mov    %rax,%r15
mov    0x4(%rsp),%esi
mov    %rax,%rdi
call   1070 <explain_wait_status@plt>
mov    0x4(%rsp),%edi
call   1040 <WIFSTOPPED@plt>
test   %eax,%eax
je     11ae <wait_for_ready_children+0x5e>
add    $0xffffffff,%ebx
jne    1170 <wait_for_ready_children+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xe42(%rip),%rsi
mov    %r15,%rdx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@WUNTRACED = global i32 0
@stderr = global i32 0
@.str = [51 x i8] c"Parent: Child with PID %ld has died unexpectedly!\0A\00"
define void @wait_for_ready_children(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i32
store i32 %0, i32* %2
store i32 0, i32* %3
br label %6
6: ; preds = %25, %1
%7 = load i32, i32* %3
%8 = load i32, i32* %2
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %28
10: ; preds = %6
%11 = load i32, i32* @WUNTRACED
%12 = call i64 @waitpid(i32 -1, i32* %5, i32 %11)
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = load i32, i32* %5
%15 = call i32 @explain_wait_status(i64 %13, i32 %14)
%16 = load i32, i32* %5
%17 = call i32 @WIFSTOPPED(i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %10
%20 = load i32, i32* @stderr
%21 = load i64, i64* %4
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %10
br label %25
25: ; preds = %24
%26 = load i32, i32* %3
%27 = add nsw i32 %26, 1
store i32 %27, i32* %3
br label %6
28: ; preds = %6
ret void
}

LLVM IR (-O2):
@WUNTRACED = global i32 0
@stderr = global i32 0
@.str = [51 x i8] c"Parent: Child with PID %ld has died unexpectedly!\0A\00"
define void @wait_for_ready_children(i32 %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = icmp sgt i32 %0, 0
br i1 %4, label %7, label %21
5: ; preds = %7
%6 = icmp eq i32 %16, %0
br i1 %6, label %21, label %7
7: ; preds = %1, %5
%8 = phi i32 [ %16, %5 ], [ 0, %1 ]
%9 = load i32, i32* @WUNTRACED
%10 = call i64 @waitpid(i32 -1, i32* %2, i32 %9)
%11 = load i32, i32* %2
%12 = call i32 @explain_wait_status(i64 %10, i32 %11)
%13 = load i32, i32* %2
%14 = call i32 @WIFSTOPPED(i32 %13)
%15 = icmp eq i32 %14, 0
%16 = add nuw nsw i32 %8, 1
br i1 %15, label %17, label %5
17: ; preds = %7
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i64 %10)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %5, %1
ret void
}