#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 scalar_t__ pid_t;

/* Variables and functions */
int WEXITSTATUS(int);
int WIFEXITED(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
scalar_t__ wait(int *);
int main() {
  pid_t pid, cpid;
  int status;
  fprintf(stdout, "Starting Process: PID=%d\n", getpid());
  pid = fork();
  if (pid != 0) {
    fprintf(stdout, "Parent: PID=%d; ParentPID=%d; ReturnPID=%d\n", getpid(),
            getppid(), pid);
    status = 0;
    sleep(05);
    cpid = wait(&status);
    fprintf(stdout, "Parent Wait: ChildPID=%d Status=%x ", cpid, status);
    fprintf(stdout, "WIFEXITED=%d WEXITSTATUS=%d\n", WIFEXITED(status),
            WEXITSTATUS(status));
    printf("Parent completed\n");
    exit(25);
  } else {
    fprintf(stdout, "Child : PID=%d; ParentPPID=%d; ReturnPID=%d\n", getpid(),
            getppid(), pid);
    sleep(10);
    fprintf(stdout, "Child completed\n");
    status = 123;
    exit(6);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%edx
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12a9 <main+0x109>
mov    0x2dee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1080 <getppid@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
mov    -0x10(%rbp),%r8
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x0,-0x1c(%rbp)
mov    $0x5,%edi
call   10a0 <sleep@plt>
lea    -0x1c(%rbp),%rdi
call   10b0 <wait@plt>
mov    %rax,-0x18(%rbp)
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xdef(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <WIFEXITED@plt>
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <WEXITSTATUS@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xdde(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
lea    0xded(%rip),%rdi
call   1040 <printf@plt>
mov    $0x19,%edi
call   1090 <exit@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1080 <getppid@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    %eax,%ecx
mov    -0x10(%rbp),%r8
lea    0xdc0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xa,%edi
call   10a0 <sleep@plt>
mov    0x2cef(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x7b,-0x1c(%rbp)
mov    $0x6,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e32(%rip),%r15
mov    (%r15),%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe41(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %rax,%rbx
mov    (%r15),%r14d
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1080 <getppid@plt>
test   %rbx,%rbx
jne    1229 <main+0x89>
lea    0xe94(%rip),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %r8d,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xa,%edi
call   10a0 <sleep@plt>
mov    (%r15),%edi
lea    0xe9c(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x6,%edi
call   1090 <exit@plt>
lea    0xdea(%rip),%rsi
mov    %r14d,%edi
mov    %ebp,%edx
mov    %eax,%ecx
mov    %rbx,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
movl   $0x0,0x4(%rsp)
mov    $0x5,%edi
call   10a0 <sleep@plt>
lea    0x4(%rsp),%rdi
call   10b0 <wait@plt>
mov    (%r15),%edi
mov    0x4(%rsp),%ecx
lea    0xddb(%rip),%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%r15),%ebx
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
mov    %eax,%ebp
mov    0x4(%rsp),%edi
call   1060 <WEXITSTATUS@plt>
lea    0xdd7(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
lea    0xe1e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x19,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [26 x i8] c"Starting Process: PID=%d\0A\00"
@.str.1 = [44 x i8] c"Parent: PID=%d; ParentPID=%d; ReturnPID=%d\0A\00"
@.str.2 = [36 x i8] c"Parent Wait: ChildPID=%d Status=%x \00"
@.str.3 = [29 x i8] c"WIFEXITED=%d WEXITSTATUS=%d\0A\00"
@.str.4 = [18 x i8] c"Parent completed\0A\00"
@.str.5 = [45 x i8] c"Child : PID=%d; ParentPPID=%d; ReturnPID=%d\0A\00"
@.str.6 = [17 x i8] c"Child completed\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @stdout
%6 = call i32 (...) @getpid()
%7 = call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = call i64 (...) @fork()
store i64 %8, i64* %2
%9 = load i64, i64* %2
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %0
%12 = load i32, i32* @stdout
%13 = call i32 (...) @getpid()
%14 = call i32 (...) @getppid()
%15 = load i64, i64* %2
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14, i64 %15)
store i32 0, i32* %4
%17 = call i32 @sleep(i32 5)
%18 = call i64 @wait(i32* %4)
store i64 %18, i64* %3
%19 = load i32, i32* @stdout
%20 = load i64, i64* %3
%21 = load i32, i32* %4
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i64 %20, i32 %21)
%23 = load i32, i32* @stdout
%24 = load i32, i32* %4
%25 = call i32 @WIFEXITED(i32 %24)
%26 = load i32, i32* %4
%27 = call i32 @WEXITSTATUS(i32 %26)
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %25, i32 %27)
%29 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @exit(i32 25)
unreachable
31: ; preds = %0
%32 = load i32, i32* @stdout
%33 = call i32 (...) @getpid()
%34 = call i32 (...) @getppid()
%35 = load i64, i64* %2
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %33, i32 %34, i64 %35)
%37 = call i32 @sleep(i32 10)
%38 = load i32, i32* @stdout
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
store i32 123, i32* %4
%40 = call i32 @exit(i32 6)
unreachable
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [26 x i8] c"Starting Process: PID=%d\0A\00"
@.str.1 = [44 x i8] c"Parent: PID=%d; ParentPID=%d; ReturnPID=%d\0A\00"
@.str.2 = [36 x i8] c"Parent Wait: ChildPID=%d Status=%x \00"
@.str.3 = [29 x i8] c"WIFEXITED=%d WEXITSTATUS=%d\0A\00"
@.str.5 = [45 x i8] c"Child : PID=%d; ParentPPID=%d; ReturnPID=%d\0A\00"
@.str.6 = [17 x i8] c"Child completed\0A\00"
@str = [17 x i8] c"Parent completed\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = load i32, i32* @stdout
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (i32, i8*, ...) @fprintf(i32 %3, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = tail call i64 (...) @fork()
%7 = icmp eq i64 %6, 0
%8 = load i32, i32* @stdout
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (...) @getppid()
br i1 %7, label %26, label %11
11: ; preds = %0
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %10, i64 %6)
store i32 0, i32* %1
%13 = tail call i32 @sleep(i32 5)
%14 = call i64 @wait(i32* %1)
%15 = load i32, i32* @stdout
%16 = load i32, i32* %1
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i64 %14, i32 %16)
%18 = load i32, i32* @stdout
%19 = load i32, i32* %1
%20 = call i32 @WIFEXITED(i32 %19)
%21 = load i32, i32* %1
%22 = call i32 @WEXITSTATUS(i32 %21)
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %22)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
%25 = call i32 @exit(i32 25)
unreachable
26: ; preds = %0
%27 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.5, i64 0, i64 0), i32 %9, i32 %10, i64 0)
%28 = tail call i32 @sleep(i32 10)
%29 = load i32, i32* @stdout
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
%31 = tail call i32 @exit(i32 6)
unreachable
}