#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 */
int /*<<< orphan*/ printf(char *, int);
int wait(int /*<<< orphan*/ *);
void wait_tasks() {
  pid_t pid;
  for (size_t i = 0; i < (6); i++) {
    pid = wait(NULL);
    printf("Process #%d exited.\n", pid);
  }
}


x86 assembly (clang, -O0):
<wait_tasks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movq   $0x0,-0x10(%rbp)
cmpq   $0x6,-0x10(%rbp)
jae    1167 <wait_tasks+0x47>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <wait@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%esi
lea    0xeaf(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <wait_tasks+0x10>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_tasks>:
push   %rbx
xor    %edi,%edi
call   1040 <wait@plt>
lea    0xed1(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <wait@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <wait@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <wait@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <wait@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1040 <wait@plt>
mov    %rbx,%rdi
mov    %eax,%esi
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [21 x i8] c"Process #%d exited.\0A\00"
define void @wait_tasks() {
%1 = alloca i32
%2 = alloca i64
store i64 0, i64* %2
br label %3
3: ; preds = %10, %0
%4 = load i64, i64* %2
%5 = icmp ult i64 %4, 6
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = call i32 @wait(i32* null)
store i32 %7, i32* %1
%8 = load i32, i32* %1
%9 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %10
10: ; preds = %6
%11 = load i64, i64* %2
%12 = add i64 %11, 1
store i64 %12, i64* %2
br label %3
13: ; preds = %3
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"Process #%d exited.\0A\00"
define void @wait_tasks() {
%1 = tail call i32 @wait(i32* null)
%2 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i32 @wait(i32* null)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @wait(i32* null)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 @wait(i32* null)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 @wait(i32* null)
%10 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = tail call i32 @wait(i32* null)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i32 %11)
ret void
}