#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 *, int);
int getpid();
int /*<<< orphan*/ stdout;
scalar_t__ wait(int /*<<< orphan*/ *);
void fork_right_branch() {
  pid_t pid;
  fprintf(stdout, "P3: %d\n", getpid());
  pid = fork();
  if (pid) {
    fprintf(stdout, "P6: %d\n", getpid());
    while (wait(NULL) != pid)
      ;
    fprintf(stdout, "P8: %d\n", getpid());
  }
  exit(0);
}


x86 assembly (clang, -O0):
<fork_right_branch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0xc(%rbp),%edi
mov    %eax,%edx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11f2 <fork_right_branch+0xa2>
mov    0x2e47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x10(%rbp),%edi
mov    %eax,%edx
lea    0xe57(%rip),%rsi
call   1040 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
cmp    -0x8(%rbp),%rax
je     11ce <fork_right_branch+0x7e>
jmp    11b6 <fork_right_branch+0x66>
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x14(%rbp),%edi
mov    %eax,%edx
lea    0xe23(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<fork_right_branch>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e85(%rip),%r14
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe94(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11c6 <fork_right_branch+0x76>
mov    %rax,%rbx
mov    (%r14),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe73(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
call   1040 <fprintf@plt>
xchg   %ax,%ax
xor    %edi,%edi
call   1060 <wait@plt>
cmp    %rbx,%rax
jne    11a0 <fork_right_branch+0x50>
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe53(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

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

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