#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
scalar_t__ getpid();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ sleep(int);
int wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  int i;
  for (i = 0; i < 5; i++) {
    pid_t proc_id = fork();
    if (proc_id == -1) {
      perror("fork");
      exit(EXIT_FAILURE);
    }
    if (proc_id == 0) {
      printf("start %ld\n", (long)getpid());
      sleep(3);
      printf("exit %ld\n", (long)getpid());
      exit(EXIT_SUCCESS);
    }
  }
  while (wait(NULL) != -1)
    ;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x5,-0x14(%rbp)
jge    1226 <main+0xb6>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11c5 <main+0x55>
lea    0xe4e(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1213 <main+0xa3>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
lea    0xe25(%rip),%rdi
call   1040 <printf@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
lea    0xe10(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    1218 <main+0xa8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118d <main+0x1d>
jmp    122b <main+0xbb>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
cmp    $0xffffffff,%eax
je     1242 <main+0xd2>
jmp    122b <main+0xbb>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     11fa <main+0x8a>
cmp    $0xffffffff,%eax
je     11e0 <main+0x70>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11e0 <main+0x70>
test   %eax,%eax
je     11fa <main+0x8a>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11e0 <main+0x70>
test   %eax,%eax
je     11fa <main+0x8a>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11e0 <main+0x70>
test   %eax,%eax
je     11fa <main+0x8a>
xor    %eax,%eax
call   1090 <fork@plt>
cmp    $0xffffffff,%eax
je     11e0 <main+0x70>
test   %eax,%eax
je     11fa <main+0x8a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
call   1080 <wait@plt>
cmp    $0xffffffff,%eax
jne    11d0 <main+0x60>
xor    %eax,%eax
pop    %rcx
ret
lea    0xe19(%rip),%rdi
call   1050 <perror@plt>
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xdfd(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xde8(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x2da1(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [11 x i8] c"start %ld\0A\00"
@.str.2 = [10 x i8] c"exit %ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
br label %8
8: ; preds = %31, %2
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 5
br i1 %10, label %11, label %34
11: ; preds = %8
%12 = call i32 (...) @fork()
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %11
%20 = load i32, i32* %7
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %30
22: ; preds = %19
%23 = call i64 (...) @getpid()
%24 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 %23)
%25 = call i32 @sleep(i32 3)
%26 = call i64 (...) @getpid()
%27 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %26)
%28 = load i32, i32* @EXIT_SUCCESS
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %19
br label %31
31: ; preds = %30
%32 = load i32, i32* %6
%33 = add nsw i32 %32, 1
store i32 %33, i32* %6
br label %8
34: ; preds = %8
br label %35
35: ; preds = %38, %34
%36 = call i32 @wait(i32* null)
%37 = icmp ne i32 %36, -1
br i1 %37, label %38, label %39
38: ; preds = %35
br label %35
39: ; preds = %35
%40 = load i32, i32* %3
ret i32 %40
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [11 x i8] c"start %ld\0A\00"
@.str.2 = [10 x i8] c"exit %ld\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %16 [
i32 -1, label %4
i32 0, label %8
]
4: ; preds = %22, %20, %18, %16, %2
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%6 = load i32, i32* @EXIT_FAILURE
%7 = tail call i32 @exit(i32 %6)
unreachable
8: ; preds = %22, %20, %18, %16, %2
%9 = tail call i64 (...) @getpid()
%10 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i64 %9)
%11 = tail call i32 @sleep(i32 3)
%12 = tail call i64 (...) @getpid()
%13 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i64 %12)
%14 = load i32, i32* @EXIT_SUCCESS
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = tail call i32 (...) @fork()
switch i32 %17, label %18 [
i32 -1, label %4
i32 0, label %8
]
18: ; preds = %16
%19 = tail call i32 (...) @fork()
switch i32 %19, label %20 [
i32 -1, label %4
i32 0, label %8
]
20: ; preds = %18
%21 = tail call i32 (...) @fork()
switch i32 %21, label %22 [
i32 -1, label %4
i32 0, label %8
]
22: ; preds = %20
%23 = tail call i32 (...) @fork()
switch i32 %23, label %24 [
i32 -1, label %4
i32 0, label %8
]
24: ; preds = %22, %24
%25 = tail call i32 @wait(i32* null)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %24
27: ; preds = %24
ret i32 0
}