#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*/ err_sys(char *);
int /*<<< orphan*/ execlp(char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ printf(char *, int, scalar_t__);
int /*<<< orphan*/ waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  pid_t pids[4], pid;
  int i, status;
  for (i = 0; i < 4; i++) {
    if ((pid = fork()) == 0) {
      execlp("xlogo", "xlogo", (char *)0);
    } else if (pid > 0) {
      pids[i] = pid;
      printf("pids[%d] is %d\n", i, pids[i]);
    } else {
      err_sys("fork error");
    }
  }
  for (i = 0; i < 3; i++)
    waitpid(-1, &status, 0);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x4,-0x3c(%rbp)
jge    120d <main+0xad>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11b4 <main+0x54>
lea    0xe5d(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   1070 <execlp@plt>
jmp    11fa <main+0x9a>
cmpq   $0x0,-0x38(%rbp)
jle    11e9 <main+0x89>
mov    -0x38(%rbp),%rcx
movslq -0x3c(%rbp),%rax
mov    %rcx,-0x30(%rbp,%rax,8)
mov    -0x3c(%rbp),%esi
movslq -0x3c(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdx
lea    0xe27(%rip),%rdi
call   1040 <printf@plt>
jmp    11f5 <main+0x95>
lea    0xe26(%rip),%rdi
call   1030 <err_sys@plt>
jmp    11fa <main+0x9a>
jmp    11ff <main+0x9f>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    117d <main+0x1d>
movl   $0x0,-0x3c(%rbp)
cmpl   $0x3,-0x3c(%rbp)
jge    123c <main+0xdc>
mov    $0xffffffff,%edi
lea    -0x40(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    1214 <main+0xb4>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    1184 <main+0x24>
lea    0xe88(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1070 <execlp@plt>
jmp    11a5 <main+0x45>
jle    1199 <main+0x39>
lea    0xe79(%rip),%rdi
xor    %esi,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
jmp    11a5 <main+0x45>
lea    0xe76(%rip),%rdi
call   1030 <err_sys@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    11c4 <main+0x64>
lea    0xe48(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1070 <execlp@plt>
jmp    11e8 <main+0x88>
jle    11dc <main+0x7c>
lea    0xe39(%rip),%rdi
mov    $0x1,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
jmp    11e8 <main+0x88>
lea    0xe33(%rip),%rdi
call   1030 <err_sys@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    1207 <main+0xa7>
lea    0xe05(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1070 <execlp@plt>
jmp    122b <main+0xcb>
jle    121f <main+0xbf>
lea    0xdf6(%rip),%rdi
mov    $0x2,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
jmp    122b <main+0xcb>
lea    0xdf0(%rip),%rdi
call   1030 <err_sys@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    124a <main+0xea>
lea    0xdc2(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1070 <execlp@plt>
jmp    126e <main+0x10e>
jle    1262 <main+0x102>
lea    0xdb3(%rip),%rdi
mov    $0x3,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
jmp    126e <main+0x10e>
lea    0xdad(%rip),%rdi
call   1030 <err_sys@plt>
lea    0xc(%rsp),%rbx
mov    $0xffffffff,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    $0xffffffff,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    $0xffffffff,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"xlogo\00"
@.str.1 = [16 x i8] c"pids[%d] is %d\0A\00"
@.str.2 = [11 x i8] c"fork error\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i64]
%7 = alloca i64
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %10
10: ; preds = %36, %2
%11 = load i32, i32* %8
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %39
13: ; preds = %10
%14 = call i64 (...) @fork()
store i64 %14, i64* %7
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* null)
br label %35
18: ; preds = %13
%19 = load i64, i64* %7
%20 = icmp sgt i64 %19, 0
br i1 %20, label %21, label %32
21: ; preds = %18
%22 = load i64, i64* %7
%23 = load i32, i32* %8
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [4 x i64], [4 x i64]* %6, i64 0, i64 %24
store i64 %22, i64* %25
%26 = load i32, i32* %8
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [4 x i64], [4 x i64]* %6, i64 0, i64 %28
%30 = load i64, i64* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %26, i64 %30)
br label %34
32: ; preds = %18
%33 = call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %21
br label %35
35: ; preds = %34, %16
br label %36
36: ; preds = %35
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %10
39: ; preds = %10
store i32 0, i32* %8
br label %40
40: ; preds = %45, %39
%41 = load i32, i32* %8
%42 = icmp slt i32 %41, 3
br i1 %42, label %43, label %48
43: ; preds = %40
%44 = call i32 @waitpid(i32 -1, i32* %9, i32 0)
br label %45
45: ; preds = %43
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %40
48: ; preds = %40
%49 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [6 x i8] c"xlogo\00"
@.str.1 = [16 x i8] c"pids[%d] is %d\0A\00"
@.str.2 = [11 x i8] c"fork error\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* null)
br label %15
9: ; preds = %2
%10 = icmp sgt i64 %5, 0
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 0, i64 %5)
br label %15
13: ; preds = %9
%14 = tail call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %15
15: ; preds = %7, %13, %11
%16 = tail call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %15
%19 = icmp sgt i64 %16, 0
br i1 %19, label %22, label %20
20: ; preds = %18
%21 = tail call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %26
22: ; preds = %18
%23 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 1, i64 %16)
br label %26
24: ; preds = %15
%25 = tail call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* null)
br label %26
26: ; preds = %24, %22, %20
%27 = tail call i64 (...) @fork()
%28 = icmp eq i64 %27, 0
br i1 %28, label %35, label %29
29: ; preds = %26
%30 = icmp sgt i64 %27, 0
br i1 %30, label %33, label %31
31: ; preds = %29
%32 = tail call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %37
33: ; preds = %29
%34 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 2, i64 %27)
br label %37
35: ; preds = %26
%36 = tail call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* null)
br label %37
37: ; preds = %35, %33, %31
%38 = tail call i64 (...) @fork()
%39 = icmp eq i64 %38, 0
br i1 %39, label %46, label %40
40: ; preds = %37
%41 = icmp sgt i64 %38, 0
br i1 %41, label %44, label %42
42: ; preds = %40
%43 = tail call i32 @err_sys(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %48
44: ; preds = %40
%45 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 3, i64 %38)
br label %48
46: ; preds = %37
%47 = tail call i32 @execlp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* null)
br label %48
48: ; preds = %46, %44, %42
%49 = call i32 @waitpid(i32 -1, i32* %3, i32 0)
%50 = call i32 @waitpid(i32 -1, i32* %3, i32 0)
%51 = call i32 @waitpid(i32 -1, i32* %3, i32 0)
%52 = call i32 @exit(i32 0)
unreachable
}