#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*/ pLeft();
int /*<<< orphan*/ pRight();
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ wait(int *);
int main() {
  pid_t pid;
  fprintf(stdout, "%s%d%s", "P1 (pid=", getpid(), ")\n");
  pid = fork();
  if (pid == 0) {
    pRight();
    exit(0);
  } else {
    pLeft();
    wait((int *)0);
    fprintf(stdout, "%s%d%s", "P9 (pid=", getpid(), ")\n");
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rcx
lea    0xe61(%rip),%rsi
lea    0xe61(%rip),%rdx
lea    0xe63(%rip),%r8
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d6 <main+0x66>
mov    $0x0,%al
call   1030 <pRight@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1060 <pLeft@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rcx
lea    0xdfa(%rip),%rsi
lea    0xe06(%rip),%rdx
lea    0xdfc(%rip),%r8
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e65(%rip),%r14
mov    (%r14),%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe74(%rip),%rsi
lea    0xe74(%rip),%rdx
lea    0xe76(%rip),%r8
mov    %ebx,%edi
mov    %rax,%rcx
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11f1 <main+0x81>
xor    %eax,%eax
call   1060 <pLeft@plt>
xor    %edi,%edi
call   1080 <wait@plt>
mov    (%r14),%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xe31(%rip),%rsi
lea    0xe3d(%rip),%rdx
lea    0xe33(%rip),%r8
mov    %ebx,%edi
mov    %rax,%rcx
call   1050 <fprintf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1030 <pRight@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [7 x i8] c"%s%d%s\00"
@.str.1 = [9 x i8] c"P1 (pid=\00"
@.str.2 = [3 x i8] c")\0A\00"
@.str.3 = [9 x i8] c"P9 (pid=\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = load i32, i32* @stdout
%4 = call i8* (...) @getpid()
%5 = call i32 @fprintf(i32 %3, 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* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%6 = call i64 (...) @fork()
store i64 %6, i64* %2
%7 = load i64, i64* %2
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %0
%10 = call i32 (...) @pRight()
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %0
%13 = call i32 (...) @pLeft()
%14 = call i32 @wait(i32* null)
%15 = load i32, i32* @stdout
%16 = call i8* (...) @getpid()
%17 = 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.3, i64 0, i64 0), i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [7 x i8] c"%s%d%s\00"
@.str.1 = [9 x i8] c"P1 (pid=\00"
@.str.2 = [3 x i8] c")\0A\00"
@.str.3 = [9 x i8] c"P9 (pid=\00"
define i32 @main() {
%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 %9
6: ; preds = %0
%7 = tail call i32 (...) @pRight()
%8 = tail call i32 @exit(i32 0)
unreachable
9: ; preds = %0
%10 = tail call i32 (...) @pLeft()
%11 = tail call i32 @wait(i32* null)
%12 = load i32, i32* @stdout
%13 = tail call i8* (...) @getpid()
%14 = tail call i32 @fprintf(i32 %12, 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* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}