#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 */
scalar_t__ fork();
int /*<<< orphan*/ fork_left_branch();
int /*<<< orphan*/ fork_right_branch();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int getpid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
scalar_t__ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  pid_t main_pid;
  main_pid = fork();
  if (main_pid) {
    fprintf(stdout, "P1: %d\n", getpid());
    fork_left_branch();
    while (wait(NULL) != main_pid)
      ;
    fprintf(stdout, "P9: %d\n", getpid());
  } else {
    sleep(2);
    fork_right_branch();
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1208 <main+0x98>
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%edx
lea    0xe45(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x0,%al
call   1050 <fork_left_branch@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1080 <wait@plt>
cmp    -0x18(%rbp),%rax
je     11df <main+0x6f>
jmp    11c7 <main+0x57>
mov    0x2dfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%edx
lea    0xe0a(%rip),%rsi
call   1060 <fprintf@plt>
jmp    1219 <main+0xa9>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    $0x0,%al
call   1040 <fork_right_branch@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11d8 <main+0x68>
mov    %rax,%rbx
mov    0x2e56(%rip),%r14
mov    (%r14),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe65(%rip),%rsi
mov    %ebp,%edi
mov    %eax,%edx
call   1060 <fprintf@plt>
xor    %eax,%eax
call   1050 <fork_left_branch@plt>
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
call   1080 <wait@plt>
cmp    %rbx,%rax
jne    11b0 <main+0x40>
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe3b(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
call   1060 <fprintf@plt>
jmp    11e9 <main+0x79>
mov    $0x2,%edi
call   1070 <sleep@plt>
xor    %eax,%eax
call   1040 <fork_right_branch@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
@stdout = global i32 0
@.str = [8 x i8] c"P1: %d\0A\00"
@.str.1 = [8 x i8] c"P9: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = load i32, i32* @stdout
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = tail call i32 (...) @fork_left_branch()
br label %10
10: ; preds = %10, %5
%11 = tail call i64 @wait(i32* null)
%12 = icmp eq i64 %11, %3
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.1, i64 0, i64 0), i32 %15)
br label %20
17: ; preds = %2
%18 = tail call i32 @sleep(i32 2)
%19 = tail call i32 (...) @fork_right_branch()
br label %20
20: ; preds = %17, %13
ret i32 0
}