#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 /*<<< orphan*/ siginfo_t;
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int P_ALL;
int WEXITED;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ waitid(int, int, int /*<<< orphan*/ *, int);
int main() {
  pid_t child;
  int status;
  siginfo_t info;
  child = fork();
  if (!child) {
    sleep(1);
    exit(0);
  }
  waitid(P_ALL, 0, &info, WEXITED);
  waitid(-1, 0, &info, 0);
  waitid(P_ALL, -1, &info, 0);
  waitid(P_ALL, 0, (siginfo_t *)-1, 0);
  waitid(P_ALL, 0, &info, -1);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1174 <main+0x34>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %edi,%edi
call   1030 <exit@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%edi
mov    0x2e64(%rip),%rax
mov    (%rax),%ecx
xor    %esi,%esi
lea    -0x10(%rbp),%rdx
call   1040 <waitid@plt>
mov    $0xffffffff,%edi
xor    %ecx,%ecx
lea    -0x10(%rbp),%rdx
mov    %ecx,%esi
call   1040 <waitid@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    $0xffffffff,%esi
lea    -0x10(%rbp),%rdx
xor    %ecx,%ecx
call   1040 <waitid@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
xor    %ecx,%ecx
mov    $0xffffffffffffffff,%rdx
mov    %ecx,%esi
call   1040 <waitid@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
xor    %esi,%esi
lea    -0x10(%rbp),%rdx
mov    $0xffffffff,%ecx
call   1040 <waitid@plt>
xor    %edi,%edi
call   1030 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
jne    1160 <main+0x20>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %edi,%edi
call   1030 <exit@plt>
mov    0x2e71(%rip),%r14
mov    (%r14),%edi
mov    0x2e77(%rip),%rax
mov    (%rax),%ecx
lea    0x4(%rsp),%rbx
xor    %esi,%esi
mov    %rbx,%rdx
call   1040 <waitid@plt>
mov    $0xffffffff,%edi
xor    %esi,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1040 <waitid@plt>
mov    (%r14),%edi
mov    $0xffffffff,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1040 <waitid@plt>
mov    (%r14),%edi
xor    %esi,%esi
mov    $0xffffffffffffffff,%rdx
xor    %ecx,%ecx
call   1040 <waitid@plt>
mov    (%r14),%edi
xor    %esi,%esi
mov    %rbx,%rdx
mov    $0xffffffff,%ecx
call   1040 <waitid@plt>
xor    %edi,%edi
call   1030 <exit@plt>

LLVM IR (-O0):
@P_ALL = global i32 0
@WEXITED = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32 @sleep(i32 1)
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %0
%12 = load i32, i32* @P_ALL
%13 = load i32, i32* @WEXITED
%14 = call i32 @waitid(i32 %12, i32 0, i32* %4, i32 %13)
%15 = call i32 @waitid(i32 -1, i32 0, i32* %4, i32 0)
%16 = load i32, i32* @P_ALL
%17 = call i32 @waitid(i32 %16, i32 -1, i32* %4, i32 0)
%18 = load i32, i32* @P_ALL
%19 = call i32 @waitid(i32 %18, i32 0, i32* inttoptr (i64 -1 to i32*), i32 0)
%20 = load i32, i32* @P_ALL
%21 = call i32 @waitid(i32 %20, i32 0, i32* %4, i32 -1)
%22 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@P_ALL = global i32 0
@WEXITED = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = tail call i32 @sleep(i32 1)
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %0
%9 = load i32, i32* @P_ALL
%10 = load i32, i32* @WEXITED
%11 = call i32 @waitid(i32 %9, i32 0, i32* %1, i32 %10)
%12 = call i32 @waitid(i32 -1, i32 0, i32* %1, i32 0)
%13 = load i32, i32* @P_ALL
%14 = call i32 @waitid(i32 %13, i32 -1, i32* %1, i32 0)
%15 = load i32, i32* @P_ALL
%16 = call i32 @waitid(i32 %15, i32 0, i32* inttoptr (i64 -1 to i32*), i32 0)
%17 = load i32, i32* @P_ALL
%18 = call i32 @waitid(i32 %17, i32 0, i32* %1, i32 -1)
%19 = call i32 @exit(i32 0)
unreachable
}