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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, ...);
int sched_getpid();
int sched_gettick();
int sched_wait(int *);
int /*<<< orphan*/ stderr;
void parent_fcn() {
  int i, childpid, retval;
  for (i = -2; i < 3; ++i) {
    if ((childpid = sched_wait(&retval)) != -1)
      fprintf(stderr,
              "Parent pid: %d received retval of %d from child pid: %d\n",
              sched_getpid(), retval, childpid);
    else
      fprintf(stderr, "Parent pid: %d has no children to wait for\n",
              sched_getpid());
  }
  fprintf(stderr, "Total ticks: %d\n", sched_gettick());
  exit(0);
}


x86 assembly (clang, -O0):
<parent_fcn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0xfffffffe,-0x4(%rbp)
cmpl   $0x3,-0x4(%rbp)
jge    11e9 <parent_fcn+0x99>
lea    -0xc(%rbp),%rdi
call   1050 <sched_wait@plt>
mov    %eax,-0x8(%rbp)
cmp    $0xffffffff,%eax
je     11b0 <parent_fcn+0x60>
mov    0x2e5b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <sched_getpid@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%edx
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%r8d
lea    0xe5c(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11d6 <parent_fcn+0x86>
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <sched_getpid@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%edx
lea    0xe6a(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
jmp    11db <parent_fcn+0x8b>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    115f <parent_fcn+0xf>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <sched_gettick@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%edx
lea    0xe5d(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<parent_fcn>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
call   1050 <sched_wait@plt>
mov    %eax,%ebx
mov    0x2e75(%rip),%r14
mov    (%r14),%ebp
xor    %eax,%eax
call   1060 <sched_getpid@plt>
cmp    $0xffffffff,%ebx
jne    118e <parent_fcn+0x3e>
lea    0xeb8(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11a7 <parent_fcn+0x57>
mov    0xc(%rsp),%ecx
lea    0xe67(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
mov    %ebx,%r8d
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xc(%rsp),%rdi
call   1050 <sched_wait@plt>
mov    %eax,%ebp
mov    (%r14),%ebx
xor    %eax,%eax
call   1060 <sched_getpid@plt>
cmp    $0xffffffff,%ebp
jne    11d6 <parent_fcn+0x86>
lea    0xe70(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    11ef <parent_fcn+0x9f>
mov    0xc(%rsp),%ecx
lea    0xe1f(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
mov    %ebp,%r8d
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xc(%rsp),%rdi
call   1050 <sched_wait@plt>
mov    %eax,%ebp
mov    (%r14),%ebx
xor    %eax,%eax
call   1060 <sched_getpid@plt>
cmp    $0xffffffff,%ebp
jne    121e <parent_fcn+0xce>
lea    0xe28(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1237 <parent_fcn+0xe7>
mov    0xc(%rsp),%ecx
lea    0xdd7(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
mov    %ebp,%r8d
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xc(%rsp),%rdi
call   1050 <sched_wait@plt>
mov    %eax,%ebp
mov    (%r14),%ebx
xor    %eax,%eax
call   1060 <sched_getpid@plt>
cmp    $0xffffffff,%ebp
jne    1266 <parent_fcn+0x116>
lea    0xde0(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    127f <parent_fcn+0x12f>
mov    0xc(%rsp),%ecx
lea    0xd8f(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
mov    %ebp,%r8d
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xc(%rsp),%rdi
call   1050 <sched_wait@plt>
mov    %eax,%ebp
mov    (%r14),%ebx
xor    %eax,%eax
call   1060 <sched_getpid@plt>
cmp    $0xffffffff,%ebp
jne    12ae <parent_fcn+0x15e>
lea    0xd98(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    12c7 <parent_fcn+0x177>
mov    0xc(%rsp),%ecx
lea    0xd47(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
mov    %ebp,%r8d
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    (%r14),%ebx
xor    %eax,%eax
call   1040 <sched_gettick@plt>
lea    0xd8d(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [57 x i8] c"Parent pid: %d received retval of %d from child pid: %d\0A\00"
@.str.1 = [44 x i8] c"Parent pid: %d has no children to wait for\0A\00"
@.str.2 = [17 x i8] c"Total ticks: %d\0A\00"
define void @parent_fcn() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 -2, i32* %1
br label %4
4: ; preds = %21, %0
%5 = load i32, i32* %1
%6 = icmp slt i32 %5, 3
br i1 %6, label %7, label %24
7: ; preds = %4
%8 = call i32 @sched_wait(i32* %3)
store i32 %8, i32* %2
%9 = icmp ne i32 %8, -1
br i1 %9, label %10, label %16
10: ; preds = %7
%11 = load i32, i32* @stderr
%12 = call i32 (...) @sched_getpid()
%13 = load i32, i32* %3
%14 = load i32, i32* %2
%15 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13, i32 %14)
br label %20
16: ; preds = %7
%17 = load i32, i32* @stderr
%18 = call i32 (...) @sched_getpid()
%19 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %16, %10
br label %21
21: ; preds = %20
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1
store i32 %23, i32* %1
br label %4
24: ; preds = %4
%25 = load i32, i32* @stderr
%26 = call i32 (...) @sched_gettick()
%27 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %26)
%28 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [57 x i8] c"Parent pid: %d received retval of %d from child pid: %d\0A\00"
@.str.1 = [44 x i8] c"Parent pid: %d has no children to wait for\0A\00"
@.str.2 = [17 x i8] c"Total ticks: %d\0A\00"
define void @parent_fcn() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @sched_wait(i32* %1)
%4 = icmp eq i32 %3, -1
%5 = load i32, i32* @stderr
%6 = call i32 (...) @sched_getpid()
br i1 %4, label %10, label %7
7: ; preds = %0
%8 = load i32, i32* %1
%9 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %8, i32 %3)
br label %12
10: ; preds = %0
%11 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %12
12: ; preds = %7, %10
%13 = call i32 @sched_wait(i32* %1)
%14 = icmp eq i32 %13, -1
%15 = load i32, i32* @stderr
%16 = call i32 (...) @sched_getpid()
br i1 %14, label %20, label %17
17: ; preds = %12
%18 = load i32, i32* %1
%19 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18, i32 %13)
br label %22
20: ; preds = %12
%21 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %16)
br label %22
22: ; preds = %20, %17
%23 = call i32 @sched_wait(i32* %1)
%24 = icmp eq i32 %23, -1
%25 = load i32, i32* @stderr
%26 = call i32 (...) @sched_getpid()
br i1 %24, label %30, label %27
27: ; preds = %22
%28 = load i32, i32* %1
%29 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %26, i32 %28, i32 %23)
br label %32
30: ; preds = %22
%31 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %32
32: ; preds = %30, %27
%33 = call i32 @sched_wait(i32* %1)
%34 = icmp eq i32 %33, -1
%35 = load i32, i32* @stderr
%36 = call i32 (...) @sched_getpid()
br i1 %34, label %40, label %37
37: ; preds = %32
%38 = load i32, i32* %1
%39 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %36, i32 %38, i32 %33)
br label %42
40: ; preds = %32
%41 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %36)
br label %42
42: ; preds = %40, %37
%43 = call i32 @sched_wait(i32* %1)
%44 = icmp eq i32 %43, -1
%45 = load i32, i32* @stderr
%46 = call i32 (...) @sched_getpid()
br i1 %44, label %50, label %47
47: ; preds = %42
%48 = load i32, i32* %1
%49 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %46, i32 %48, i32 %43)
br label %52
50: ; preds = %42
%51 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %46)
br label %52
52: ; preds = %50, %47
%53 = load i32, i32* @stderr
%54 = call i32 (...) @sched_gettick()
%55 = call i32 (i32, i8*, i32, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = call i32 @exit(i32 0)
unreachable
}