#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 ECHILD;
scalar_t__ WEXITSTATUS(int const);
scalar_t__ WIFCONTINUED(int const);
scalar_t__ WIFEXITED(int const);
scalar_t__ WIFSIGNALED(int const);
scalar_t__ WIFSTOPPED(int const);
int WSTOPSIG(int const);
int WTERMSIG(int const);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
scalar_t__ getpid();
int /*<<< orphan*/ stderr;
void waitpid_err(const pid_t pid, const int status) {
  if (pid == -1 && errno == ECHILD) {
    return;
  } else if (pid == -1) {
    const int err = errno;
    fprintf(stderr, "[%d] waitpid error: (code: %d).\n", (int)getpid(), err);
  }
  if (WIFEXITED(status)) {
    fprintf(stderr, "[%d] child (%d) exited normally (code: %d).\n",
            (int)getpid(), (int)pid, WEXITSTATUS(status));
    if (WEXITSTATUS(status) != 0) {
      fprintf(stderr, "[%d] bailing due to child failure.\n", (int)getpid());
      exit(1);
    }
  }
  if (pid != 0 && WIFSIGNALED(status)) {
    fprintf(stderr, "[%d] child (%d) terminated by signal (%d)\n",
            (int)getpid(), (int)pid, WTERMSIG(status));
  }
  if (pid != 0 && WIFSTOPPED(status)) {
    fprintf(stderr, "[%d] child (%d) was stopped (sig: %d)\n", (int)getpid(),
            (int)pid, WSTOPSIG(status));
  }
  if (pid != 0 && WIFCONTINUED(status)) {
    fprintf(stderr, "[%d] child (%d) continued.\n", (int)getpid(), (int)pid);
  }
}


x86 assembly (clang, -O0):
<waitpid_err>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11d5 <waitpid_err+0x35>
mov    0x2e19(%rip),%rax
mov    (%rax),%eax
mov    0x2e08(%rip),%rcx
cmp    (%rcx),%eax
jne    11d5 <waitpid_err+0x35>
jmp    13a9 <waitpid_err+0x209>
cmpl   $0xffffffff,-0x4(%rbp)
jne    1214 <waitpid_err+0x74>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%edx
mov    -0xc(%rbp),%ecx
lea    0xdf3(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1219 <waitpid_err+0x79>
mov    -0x8(%rbp),%edi
call   10a0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     12b0 <waitpid_err+0x110>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%edx
mov    -0x14(%rbp),%ecx
mov    %rax,%r8
lea    0xdbf(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     12ab <waitpid_err+0x10b>
mov    0x2d5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%edx
lea    0xdb4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    12b0 <waitpid_err+0x110>
cmpl   $0x0,-0x4(%rbp)
je     130a <waitpid_err+0x16a>
mov    -0x8(%rbp),%edi
call   1040 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     130a <waitpid_err+0x16a>
mov    0x2d0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%edi
call   1080 <WTERMSIG@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%edx
mov    -0x24(%rbp),%ecx
mov    %eax,%r8d
lea    0xd6f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0x4(%rbp)
je     1364 <waitpid_err+0x1c4>
mov    -0x8(%rbp),%edi
call   1070 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     1364 <waitpid_err+0x1c4>
mov    0x2cb3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x34(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%edi
call   10c0 <WSTOPSIG@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    -0x30(%rbp),%ecx
mov    %eax,%r8d
lea    0xd40(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
cmpl   $0x0,-0x4(%rbp)
je     13a9 <waitpid_err+0x209>
mov    -0x8(%rbp),%edi
call   1060 <WIFCONTINUED@plt>
cmp    $0x0,%rax
je     13a9 <waitpid_err+0x209>
mov    0x2c59(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x3c(%rbp),%edi
mov    %eax,%edx
mov    -0x4(%rbp),%ecx
lea    0xd22(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waitpid_err>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%ebp
mov    %edi,%r12d
cmp    $0xffffffff,%edi
jne    11f3 <waitpid_err+0x53>
mov    0x2e1f(%rip),%rax
mov    (%rax),%r14d
mov    0x2e0d(%rip),%rax
cmp    (%rax),%r14d
je     1305 <waitpid_err+0x165>
mov    0x2e0d(%rip),%rax
mov    (%rax),%r15d
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe1c(%rip),%rsi
mov    %r15d,%edi
mov    %eax,%edx
mov    %r14d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   10a0 <WIFEXITED@plt>
test   %rax,%rax
je     1243 <waitpid_err+0xa3>
mov    0x2dda(%rip),%r15
mov    (%r15),%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1090 <WEXITSTATUS@plt>
lea    0xe00(%rip),%rsi
mov    %r14d,%edi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   1090 <WEXITSTATUS@plt>
test   %rax,%rax
jne    130e <waitpid_err+0x16e>
test   %r12d,%r12d
je     1305 <waitpid_err+0x165>
mov    %ebp,%edi
call   1040 <WIFSIGNALED@plt>
test   %rax,%rax
je     128c <waitpid_err+0xec>
mov    0x2d81(%rip),%rax
mov    (%rax),%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1080 <WTERMSIG@plt>
lea    0xdf8(%rip),%rsi
mov    %r14d,%edi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   1070 <WIFSTOPPED@plt>
test   %rax,%rax
je     12cc <waitpid_err+0x12c>
mov    0x2d41(%rip),%rax
mov    (%rax),%r14d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   10c0 <WSTOPSIG@plt>
lea    0xde3(%rip),%rsi
mov    %r14d,%edi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %eax,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   1060 <WIFCONTINUED@plt>
test   %rax,%rax
je     1305 <waitpid_err+0x165>
mov    0x2d01(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xdd5(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
mov    %r12d,%ecx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <fprintf@plt>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%r15),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xd2f(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@ECHILD = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"[%d] waitpid error: (code: %d).\0A\00"
@.str.1 = [45 x i8] c"[%d] child (%d) exited normally (code: %d).\0A\00"
@.str.2 = [36 x i8] c"[%d] bailing due to child failure.\0A\00"
@.str.3 = [43 x i8] c"[%d] child (%d) terminated by signal (%d)\0A\00"
@.str.4 = [39 x i8] c"[%d] child (%d) was stopped (sig: %d)\0A\00"
@.str.5 = [28 x i8] c"[%d] child (%d) continued.\0A\00"
define void @waitpid_err(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = load i32, i32* @ECHILD
%11 = icmp eq i32 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %8
br label %89
13: ; preds = %8, %2
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i32, i32* @errno
store i32 %17, i32* %5
%18 = load i32, i32* @stderr
%19 = call i64 (...) @getpid()
%20 = trunc i64 %19 to i32
%21 = load i32, i32* %5
%22 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21)
br label %23
23: ; preds = %16, %13
br label %24
24: ; preds = %23
%25 = load i32, i32* %4
%26 = call i64 @WIFEXITED(i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %46
28: ; preds = %24
%29 = load i32, i32* @stderr
%30 = call i64 (...) @getpid()
%31 = trunc i64 %30 to i32
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = call i64 @WEXITSTATUS(i32 %33)
%35 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %31, i32 %32, i64 %34)
%36 = load i32, i32* %4
%37 = call i64 @WEXITSTATUS(i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %28
%40 = load i32, i32* @stderr
%41 = call i64 (...) @getpid()
%42 = trunc i64 %41 to i32
%43 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %42)
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %28
br label %46
46: ; preds = %45, %24
%47 = load i32, i32* %3
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %61
49: ; preds = %46
%50 = load i32, i32* %4
%51 = call i64 @WIFSIGNALED(i32 %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %61
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = call i64 (...) @getpid()
%56 = trunc i64 %55 to i32
%57 = load i32, i32* %3
%58 = load i32, i32* %4
%59 = call i32 @WTERMSIG(i32 %58)
%60 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %56, i32 %57, i32 %59)
br label %61
61: ; preds = %53, %49, %46
%62 = load i32, i32* %3
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %76
64: ; preds = %61
%65 = load i32, i32* %4
%66 = call i64 @WIFSTOPPED(i32 %65)
%67 = icmp ne i64 %66, 0
br i1 %67, label %68, label %76
68: ; preds = %64
%69 = load i32, i32* @stderr
%70 = call i64 (...) @getpid()
%71 = trunc i64 %70 to i32
%72 = load i32, i32* %3
%73 = load i32, i32* %4
%74 = call i32 @WSTOPSIG(i32 %73)
%75 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %71, i32 %72, i32 %74)
br label %76
76: ; preds = %68, %64, %61
%77 = load i32, i32* %3
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %89
79: ; preds = %76
%80 = load i32, i32* %4
%81 = call i64 @WIFCONTINUED(i32 %80)
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %89
83: ; preds = %79
%84 = load i32, i32* @stderr
%85 = call i64 (...) @getpid()
%86 = trunc i64 %85 to i32
%87 = load i32, i32* %3
%88 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %86, i32 %87)
br label %89
89: ; preds = %12, %83, %79, %76
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@ECHILD = global i32 0
@stderr = global i32 0
@.str = [33 x i8] c"[%d] waitpid error: (code: %d).\0A\00"
@.str.1 = [45 x i8] c"[%d] child (%d) exited normally (code: %d).\0A\00"
@.str.2 = [36 x i8] c"[%d] bailing due to child failure.\0A\00"
@.str.3 = [43 x i8] c"[%d] child (%d) terminated by signal (%d)\0A\00"
@.str.4 = [39 x i8] c"[%d] child (%d) was stopped (sig: %d)\0A\00"
@.str.5 = [28 x i8] c"[%d] child (%d) continued.\0A\00"
define void @waitpid_err(i32 %0, i32 %1) {
%3 = icmp eq i32 %0, -1
br i1 %3, label %4, label %13
4: ; preds = %2
%5 = load i32, i32* @errno
%6 = load i32, i32* @ECHILD
%7 = icmp eq i32 %5, %6
br i1 %7, label %58, label %8
8: ; preds = %4
%9 = load i32, i32* @stderr
%10 = tail call i64 (...) @getpid()
%11 = trunc i64 %10 to i32
%12 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %5)
br label %13
13: ; preds = %2, %8
%14 = tail call i64 @WIFEXITED(i32 %1)
%15 = icmp eq i64 %14, 0
br i1 %15, label %30, label %16
16: ; preds = %13
%17 = load i32, i32* @stderr
%18 = tail call i64 (...) @getpid()
%19 = trunc i64 %18 to i32
%20 = tail call i64 @WEXITSTATUS(i32 %1)
%21 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %0, i64 %20)
%22 = tail call i64 @WEXITSTATUS(i32 %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %16
%25 = load i32, i32* @stderr
%26 = tail call i64 (...) @getpid()
%27 = trunc i64 %26 to i32
%28 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i32 %27)
%29 = tail call i32 @exit(i32 1)
unreachable
30: ; preds = %16, %13
%31 = icmp eq i32 %0, 0
br i1 %31, label %58, label %32
32: ; preds = %30
%33 = tail call i64 @WIFSIGNALED(i32 %1)
%34 = icmp eq i64 %33, 0
br i1 %34, label %41, label %35
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = tail call i64 (...) @getpid()
%38 = trunc i64 %37 to i32
%39 = tail call i32 @WTERMSIG(i32 %1)
%40 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.3, i64 0, i64 0), i32 %38, i32 %0, i32 %39)
br label %41
41: ; preds = %32, %35
%42 = tail call i64 @WIFSTOPPED(i32 %1)
%43 = icmp eq i64 %42, 0
br i1 %43, label %50, label %44
44: ; preds = %41
%45 = load i32, i32* @stderr
%46 = tail call i64 (...) @getpid()
%47 = trunc i64 %46 to i32
%48 = tail call i32 @WSTOPSIG(i32 %1)
%49 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.4, i64 0, i64 0), i32 %47, i32 %0, i32 %48)
br label %50
50: ; preds = %41, %44
%51 = tail call i64 @WIFCONTINUED(i32 %1)
%52 = icmp eq i64 %51, 0
br i1 %52, label %58, label %53
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = tail call i64 (...) @getpid()
%56 = trunc i64 %55 to i32
%57 = tail call i32 (i32, i8*, i32, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0), i32 %56, i32 %0)
br label %58
58: ; preds = %30, %4, %53, %50
ret void
}