#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_left_branch() {
  pid_t pid;
  fprintf(stdout, "P2: %d\n", getpid());
  pid = fork();
  if (pid) {
    fprintf(stdout, "P4: %d\n", getpid());
    while (wait(NULL) != pid)
      ;
    fprintf(stdout, "P7: %d\n", getpid());
  } else {
    fprintf(stdout, "P5: %d\n", getpid());
    exit(0);
  }
  return;
}


x86 assembly (clang, -O0):
<fork_left_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     11f7 <fork_left_branch+0xa7>
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_left_branch+0x7e>
jmp    11b6 <fork_left_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>
jmp    1222 <fork_left_branch+0xd2>
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    -0x18(%rbp),%edi
mov    %eax,%edx
lea    0xe02(%rip),%rsi
call   1040 <fprintf@plt>
xor    %edi,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fork_left_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>
mov    %rax,%rbx
mov    (%r14),%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
test   %rbx,%rbx
je     11ca <fork_left_branch+0x7a>
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_left_branch+0x50>
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe53(%rip),%rsi
mov    %ebx,%edi
mov    %eax,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <fprintf@plt>
lea    0xe47(%rip),%rsi
mov    %ebp,%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"P2: %d\0A\00"
@.str.1 = [8 x i8] c"P4: %d\0A\00"
@.str.2 = [8 x i8] c"P7: %d\0A\00"
@.str.3 = [8 x i8] c"P5: %d\0A\00"
define void @fork_left_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 %26
21: ; preds = %0
%22 = load i32, i32* @stdout
%23 = call i32 (...) @getpid()
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %23)
%25 = call i32 @exit(i32 0)
unreachable
26: ; preds = %17
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [8 x i8] c"P2: %d\0A\00"
@.str.1 = [8 x i8] c"P4: %d\0A\00"
@.str.2 = [8 x i8] c"P7: %d\0A\00"
@.str.3 = [8 x i8] c"P5: %d\0A\00"
define void @fork_left_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
%6 = load i32, i32* @stdout
%7 = tail call i32 (...) @getpid()
br i1 %5, label %17, label %8
8: ; preds = %0
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32 %7)
br label %10
10: ; preds = %10, %8
%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)
ret void
17: ; preds = %0
%18 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %7)
%19 = tail call i32 @exit(i32 0)
unreachable
}