#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*/ fprintf(int /*<<< orphan*/, char *, long, int);
int /*<<< orphan*/ stderr;
scalar_t__ waitpid(scalar_t__ const, int *, int /*<<< orphan*/);
int await_children(const pid_t pids[], const int size_pids) {
  pid_t pid;
  int status, i;
  for (i = 0; i < size_pids; i++) {
    pid = waitpid(pids[i], &status, 0);
    if (status != 0) {
      fprintf(stderr, "Warning: child %ld exited with status %d\n", (long)pid,
              status);
    }
  }
  return i;
}


x86 assembly (clang, -O0):
<await_children>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1196 <await_children+0x76>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1183 <await_children+0x63>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe82(%rip),%rsi
call   1030 <fprintf@plt>
jmp    1188 <await_children+0x68>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1136 <await_children+0x16>
mov    -0x20(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<await_children>:
test   %esi,%esi
jle    1192 <await_children+0x72>
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r13
mov    %esi,(%rsp)
mov    %esi,%ebp
xor    %ebx,%ebx
lea    0x4(%rsp),%r12
mov    0x2e9b(%rip),%r14
lea    0xeb4(%rip),%r15
jmp    1159 <await_children+0x39>
xchg   %ax,%ax
add    $0x1,%rbx
cmp    %rbx,%rbp
je     1180 <await_children+0x60>
mov    0x0(%r13,%rbx,8),%rdi
mov    %r12,%rsi
xor    %edx,%edx
call   1040 <waitpid@plt>
mov    0x4(%rsp),%ecx
test   %ecx,%ecx
je     1150 <await_children+0x30>
mov    (%r14),%edi
mov    %r15,%rsi
mov    %rax,%rdx
call   1030 <fprintf@plt>
jmp    1150 <await_children+0x30>
mov    (%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [42 x i8] c"Warning: child %ld exited with status %d\0A\00"
define i32 @await_children(i64* %0, i32 %1) {
%3 = alloca i64*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i32
%7 = alloca i32
store i64* %0, i64** %3
store i32 %1, i32* %4
store i32 0, i32* %7
br label %8
8: ; preds = %27, %2
%9 = load i32, i32* %7
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %30
12: ; preds = %8
%13 = load i64*, i64** %3
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i64, i64* %13, i64 %15
%17 = load i64, i64* %16
%18 = call i64 @waitpid(i64 %17, i32* %6, i32 0)
store i64 %18, i64* %5
%19 = load i32, i32* %6
%20 = icmp ne i32 %19, 0
br i1 %20, label %21, label %26
21: ; preds = %12
%22 = load i32, i32* @stderr
%23 = load i64, i64* %5
%24 = load i32, i32* %6
%25 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i64 %23, i32 %24)
br label %26
26: ; preds = %21, %12
br label %27
27: ; preds = %26
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 1
store i32 %29, i32* %7
br label %8
30: ; preds = %8
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [42 x i8] c"Warning: child %ld exited with status %d\0A\00"
define i32 @await_children(i64* nocapture %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %18
%9 = phi i64 [ 0, %6 ], [ %19, %18 ]
%10 = getelementptr inbounds i64, i64* %0, i64 %9
%11 = load i64, i64* %10
%12 = call i64 @waitpid(i64 %11, i32* %3, i32 0)
%13 = load i32, i32* %3
%14 = icmp eq i32 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %8
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i64 %12, i32 %13)
br label %18
18: ; preds = %8, %15
%19 = add nuw nsw i64 %9, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %21, label %8
21: ; preds = %18, %2
%22 = phi i32 [ 0, %2 ], [ %1, %18 ]
ret i32 %22
}