#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 */
int WEXITSTATUS(int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ slight_delay();
int /*<<< orphan*/ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
int wait_for_child_processes(int allocated_cores, int verbose) {
  int retval = 0;
  while (allocated_cores > 0) {
    int status = 0;
    (void)waitpid(0, &status, 0);
    --allocated_cores;
    retval |= WEXITSTATUS(status);
  }
  slight_delay();
  if (-1 == verbose) {
    puts("");
  }
  return retval;
}


x86 assembly (clang, -O0):
<wait_for_child_processes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x0,-0x4(%rbp)
jle    118f <wait_for_child_processes+0x4f>
movl   $0x0,-0x10(%rbp)
xor    %edx,%edx
lea    -0x10(%rbp),%rsi
mov    %edx,%edi
call   1050 <waitpid@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
or     -0xc(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    1155 <wait_for_child_processes+0x15>
mov    $0x0,%al
call   1060 <slight_delay@plt>
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    11b0 <wait_for_child_processes+0x70>
lea    0xe55(%rip),%rdi
call   1030 <puts@plt>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_child_processes>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
test   %edi,%edi
jle    1189 <wait_for_child_processes+0x49>
mov    %edi,%ebp
add    $0x1,%ebp
xor    %ebx,%ebx
lea    0x4(%rsp),%r15
nopw   0x0(%rax,%rax,1)
movl   $0x0,0x4(%rsp)
xor    %edi,%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
or     %eax,%ebx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1160 <wait_for_child_processes+0x20>
jmp    118b <wait_for_child_processes+0x4b>
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <slight_delay@plt>
cmp    $0xffffffff,%r14d
jne    11a2 <wait_for_child_processes+0x62>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i32 @wait_for_child_processes(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %10, %2
%8 = load i32, i32* %3
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %7
store i32 0, i32* %6
%11 = call i32 @waitpid(i32 0, i32* %6, i32 0)
%12 = load i32, i32* %3
%13 = add nsw i32 %12, -1
store i32 %13, i32* %3
%14 = load i32, i32* %6
%15 = call i32 @WEXITSTATUS(i32 %14)
%16 = load i32, i32* %5
%17 = or i32 %16, %15
store i32 %17, i32* %5
br label %7
18: ; preds = %7
%19 = call i32 (...) @slight_delay()
%20 = load i32, i32* %4
%21 = icmp eq i32 -1, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 @puts(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %18
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
define i32 @wait_for_child_processes(i32 %0, i32 %1) {
%3 = alloca i32
%4 = icmp sgt i32 %0, 0
br i1 %4, label %5, label %16
5: ; preds = %2
%6 = bitcast i32* %3 to i8*
br label %7
7: ; preds = %5, %7
%8 = phi i32 [ 0, %5 ], [ %14, %7 ]
%9 = phi i32 [ %0, %5 ], [ %11, %7 ]
store i32 0, i32* %3
%10 = call i32 @waitpid(i32 0, i32* %3, i32 0)
%11 = add nsw i32 %9, -1
%12 = load i32, i32* %3
%13 = call i32 @WEXITSTATUS(i32 %12)
%14 = or i32 %13, %8
%15 = icmp ugt i32 %9, 1
br i1 %15, label %7, label %16
16: ; preds = %7, %2
%17 = phi i32 [ 0, %2 ], [ %14, %7 ]
%18 = call i32 (...) @slight_delay()
%19 = icmp eq i32 %1, -1
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @putchar(i32 10)
br label %22
22: ; preds = %20, %16
ret i32 %17
}