#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 */
struct rusage {
  int dummy;
};
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int get_pid_max();
int /*<<< orphan*/ wait4(int, int *, int, struct rusage *);
int main() {
  pid_t epid = get_pid_max() + 1;
  pid_t child;
  wait4(epid, NULL, 0, NULL);
  wait4(-1, NULL, 0, NULL);
  child = fork();
  if (!child) {
    int i = 0xfffff;
    while (i > 0)
      i--;
    exit(0);
  }
  wait4(child, (int *)-1, 0, NULL);
  wait4(child, 0, 0, NULL);
  child = fork();
  if (!child) {
    int i = 0xfffff;
    while (i > 0)
      i--;
    exit(0);
  }
  wait4(child, NULL, -1, NULL);
  wait4(child, 0, 0, NULL);
  child = fork();
  if (!child) {
    int i = 0xfffff;
    while (i > 0)
      i--;
    exit(0);
  }
  wait4(child, NULL, 0, (struct rusage *)-1);
  wait4(child, 0, 0, NULL);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <get_pid_max@plt>
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1040 <wait4@plt>
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1040 <wait4@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11ba <main+0x7a>
movl   $0xfffff,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11b3 <main+0x73>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    119b <main+0x5b>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
xor    %edx,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1040 <wait4@plt>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1040 <wait4@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    121a <main+0xda>
movl   $0xfffff,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1213 <main+0xd3>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11fb <main+0xbb>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%ecx
mov    $0xffffffff,%edx
mov    %rcx,%rsi
call   1040 <wait4@plt>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1040 <wait4@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1279 <main+0x139>
movl   $0xfffff,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jle    1272 <main+0x132>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    125a <main+0x11a>
xor    %edi,%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
mov    $0xffffffffffffffff,%rcx
call   1040 <wait4@plt>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%ecx
xor    %edx,%edx
mov    %rcx,%rsi
call   1040 <wait4@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <get_pid_max@plt>
lea    0x1(%rax),%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <wait4@plt>
mov    $0xffffffff,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <wait4@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11e8 <main+0xa8>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0xffffffffffffffff,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <wait4@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <wait4@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11e8 <main+0xa8>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1040 <wait4@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <wait4@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     11e8 <main+0xa8>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
xor    %edx,%edx
mov    $0xffffffffffffffff,%rcx
call   1040 <wait4@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <wait4@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.rusage = type { i32 }
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (...) @get_pid_max()
%8 = add nsw i32 %7, 1
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = call i32 @wait4(i32 %9, i32* null, i32 0, %struct.rusage* null)
%11 = call i32 @wait4(i32 -1, i32* null, i32 0, %struct.rusage* null)
%12 = call i32 (...) @fork()
store i32 %12, i32* %3
%13 = load i32, i32* %3
%14 = icmp ne i32 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %0
store i32 1048575, i32* %4
br label %16
16: ; preds = %19, %15
%17 = load i32, i32* %4
%18 = icmp sgt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* %4
%21 = add nsw i32 %20, -1
store i32 %21, i32* %4
br label %16
22: ; preds = %16
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %0
%25 = load i32, i32* %3
%26 = call i32 @wait4(i32 %25, i32* inttoptr (i64 -1 to i32*), i32 0, %struct.rusage* null)
%27 = load i32, i32* %3
%28 = call i32 @wait4(i32 %27, i32* null, i32 0, %struct.rusage* null)
%29 = call i32 (...) @fork()
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = icmp ne i32 %30, 0
br i1 %31, label %41, label %32
32: ; preds = %24
store i32 1048575, i32* %5
br label %33
33: ; preds = %36, %32
%34 = load i32, i32* %5
%35 = icmp sgt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* %5
%38 = add nsw i32 %37, -1
store i32 %38, i32* %5
br label %33
39: ; preds = %33
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %24
%42 = load i32, i32* %3
%43 = call i32 @wait4(i32 %42, i32* null, i32 -1, %struct.rusage* null)
%44 = load i32, i32* %3
%45 = call i32 @wait4(i32 %44, i32* null, i32 0, %struct.rusage* null)
%46 = call i32 (...) @fork()
store i32 %46, i32* %3
%47 = load i32, i32* %3
%48 = icmp ne i32 %47, 0
br i1 %48, label %58, label %49
49: ; preds = %41
store i32 1048575, i32* %6
br label %50
50: ; preds = %53, %49
%51 = load i32, i32* %6
%52 = icmp sgt i32 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %50
%54 = load i32, i32* %6
%55 = add nsw i32 %54, -1
store i32 %55, i32* %6
br label %50
56: ; preds = %50
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %41
%59 = load i32, i32* %3
%60 = call i32 @wait4(i32 %59, i32* null, i32 0, %struct.rusage* inttoptr (i64 -1 to %struct.rusage*))
%61 = load i32, i32* %3
%62 = call i32 @wait4(i32 %61, i32* null, i32 0, %struct.rusage* null)
%63 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.rusage = type { i32 }
define i32 @main() {
%1 = tail call i32 (...) @get_pid_max()
%2 = add nsw i32 %1, 1
%3 = tail call i32 @wait4(i32 %2, i32* null, i32 0, %struct.rusage* null)
%4 = tail call i32 @wait4(i32 -1, i32* null, i32 0, %struct.rusage* null)
%5 = tail call i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %0
%10 = tail call i32 @wait4(i32 %5, i32* inttoptr (i64 -1 to i32*), i32 0, %struct.rusage* null)
%11 = tail call i32 @wait4(i32 %5, i32* null, i32 0, %struct.rusage* null)
%12 = tail call i32 (...) @fork()
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %9
%17 = tail call i32 @wait4(i32 %12, i32* null, i32 -1, %struct.rusage* null)
%18 = tail call i32 @wait4(i32 %12, i32* null, i32 0, %struct.rusage* null)
%19 = tail call i32 (...) @fork()
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @exit(i32 0)
unreachable
23: ; preds = %16
%24 = tail call i32 @wait4(i32 %19, i32* null, i32 0, %struct.rusage* inttoptr (i64 -1 to %struct.rusage*))
%25 = tail call i32 @wait4(i32 %19, i32* null, i32 0, %struct.rusage* null)
%26 = tail call i32 @exit(i32 0)
unreachable
}