#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*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ stdout;
scalar_t__ waitpid(int /*<<< orphan*/, int *, int /*<<< orphan*/);
void printExitCodes(pid_t child1, pid_t child2) {
  int child1Status = -1;
  if (waitpid(child1, &child1Status, 0) < 0)
    perror("WAITPID FAILED!");
  printf("Child 1 exited with exit code: %d\n", child1Status);
  int child2Status = -1;
  if (waitpid(child2, &child2Status, 0) < 0)
    perror("WAITPID FAILED!");
  printf("Child 2 exited with exit code: %d\n", child2Status);
  fflush(stdout);
}


x86 assembly (clang, -O0):
<printExitCodes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    -0x4(%rbp),%edi
lea    -0xc(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0x0,%rax
jge    1179 <printExitCodes+0x39>
lea    0xe8c(%rip),%rdi
call   1060 <perror@plt>
mov    -0xc(%rbp),%esi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0x0,%rax
jge    11b3 <printExitCodes+0x73>
lea    0xe52(%rip),%rdi
call   1060 <perror@plt>
mov    -0x10(%rbp),%esi
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printExitCodes>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
movl   $0xffffffff,0xc(%rsp)
ff
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
test   %rax,%rax
js     11af <printExitCodes+0x6f>
mov    0xc(%rsp),%esi
lea    0xea5(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,0x8(%rsp)
ff
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
test   %rax,%rax
js     11bd <printExitCodes+0x7d>
mov    0x8(%rsp),%esi
lea    0xe9d(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1040 <fflush@plt>
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe4a(%rip),%rdi
call   1060 <perror@plt>
jmp    1160 <printExitCodes+0x20>
lea    0xe3c(%rip),%rdi
call   1060 <perror@plt>
jmp    118b <printExitCodes+0x4b>

LLVM IR (-O0):
@.str = [16 x i8] c"WAITPID FAILED!\00"
@.str.1 = [35 x i8] c"Child 1 exited with exit code: %d\0A\00"
@.str.2 = [35 x i8] c"Child 2 exited with exit code: %d\0A\00"
@stdout = global i32 0
define void @printExitCodes(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 -1, i32* %5
%7 = load i32, i32* %3
%8 = call i64 @waitpid(i32 %7, i32* %5, i32 0)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i32, i32* %5
%14 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %13)
store i32 -1, i32* %6
%15 = load i32, i32* %4
%16 = call i64 @waitpid(i32 %15, i32* %6, i32 0)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
%21 = load i32, i32* %6
%22 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @stdout
%24 = call i32 @fflush(i32 %23)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"WAITPID FAILED!\00"
@.str.1 = [35 x i8] c"Child 1 exited with exit code: %d\0A\00"
@.str.2 = [35 x i8] c"Child 2 exited with exit code: %d\0A\00"
@stdout = global i32 0
define void @printExitCodes(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%6 = call i64 @waitpid(i32 %0, i32* %3, i32 0)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %2
%11 = load i32, i32* %3
%12 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = bitcast i32* %4 to i8*
store i32 -1, i32* %4
%14 = call i64 @waitpid(i32 %1, i32* %4, i32 0)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = load i32, i32* %4
%20 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @stdout
%22 = call i32 @fflush(i32 %21)
ret void
}