#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 /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, char *);
char *getpid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int *);
void pRight() {
  pid_t pid;
  fprintf(stdout, "%s%d%s", "P3 (pid=", getpid(), ")\n");
  pid = fork();
  if (pid == 0) {
    sleep(1);
    fprintf(stdout, "%s%d%s", "P6 (pid=", getpid(), ")\n");
    exit(0);
  } else {
    wait((int *)0);
    sleep(1);
    fprintf(stdout, "%s%d%s", "P8 (pid=", getpid(), ")\n");
    exit(0);
  }
}


x86 assembly (clang, -O0):
<pRight>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0xc(%rbp),%edi
mov    %rax,%rcx
lea    0xe78(%rip),%rsi
lea    0xe78(%rip),%rdx
lea    0xe7a(%rip),%r8
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11f5 <pRight+0x95>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rcx
lea    0xe25(%rip),%rsi
lea    0xe31(%rip),%rdx
lea    0xe27(%rip),%r8
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rcx
lea    0xdd8(%rip),%rsi
lea    0xded(%rip),%rdx
lea    0xdda(%rip),%r8
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<pRight>:
push   %r14
push   %rbx
push   %rax
mov    0x2e75(%rip),%r14
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe84(%rip),%rsi
lea    0xe84(%rip),%rdx
lea    0xe86(%rip),%r8
mov    %ebx,%edi
mov    %rax,%rcx
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    11c4 <pRight+0x64>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe45(%rip),%rsi
lea    0xe51(%rip),%rdx
jmp    11ed <pRight+0x8d>
xor    %edi,%edi
call   1070 <wait@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe1a(%rip),%rsi
lea    0xe2f(%rip),%rdx
lea    0xe1c(%rip),%r8
mov    %ebx,%edi
mov    %rax,%rcx
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [7 x i8] c"%s%d%s\00"
@.str.1 = [9 x i8] c"P3 (pid=\00"
@.str.2 = [3 x i8] c")\0A\00"
@.str.3 = [9 x i8] c"P6 (pid=\00"
@.str.4 = [9 x i8] c"P8 (pid=\00"
define void @pRight() {
%1 = alloca i64
%2 = load i32, i32* @stdout
%3 = call i8* (...) @getpid()
%4 = call i32 @fprintf(i32 %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%5 = call i64 (...) @fork()
store i64 %5, i64* %1
%6 = load i64, i64* %1
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %0
%9 = call i32 @sleep(i32 1)
%10 = load i32, i32* @stdout
%11 = call i8* (...) @getpid()
%12 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %0
%15 = call i32 @wait(i32* null)
%16 = call i32 @sleep(i32 1)
%17 = load i32, i32* @stdout
%18 = call i8* (...) @getpid()
%19 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [7 x i8] c"%s%d%s\00"
@.str.1 = [9 x i8] c"P3 (pid=\00"
@.str.2 = [3 x i8] c")\0A\00"
@.str.3 = [9 x i8] c"P6 (pid=\00"
@.str.4 = [9 x i8] c"P8 (pid=\00"
define void @pRight() {
%1 = load i32, i32* @stdout
%2 = tail call i8* (...) @getpid()
%3 = tail call i32 @fprintf(i32 %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%4 = tail call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %0
%7 = tail call i32 @sleep(i32 1)
%8 = load i32, i32* @stdout
%9 = tail call i8* (...) @getpid()
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %0
%13 = tail call i32 @wait(i32* null)
%14 = tail call i32 @sleep(i32 1)
%15 = load i32, i32* @stdout
%16 = tail call i8* (...) @getpid()
%17 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%18 = tail call i32 @exit(i32 0)
unreachable
}