#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 */

/* Variables and functions */
scalar_t__ fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int main() {
  if (fork() == 0) {
    printf("Hello from Parent, pid = %d \t ppid=%d\n", getpid(), getppid());
  } else {
    printf("Hello from child, pid = %d \t ppid=%d\n", getpid(), getppid());
  }
  printf("Common code\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
cmp    $0x0,%rax
jne    1189 <main+0x49>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x8(%rbp),%esi
mov    %eax,%edx
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ad <main+0x6d>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <getppid@plt>
test   %rbx,%rbx
lea    0xe89(%rip),%rcx
lea    0xea9(%rip),%rdi
cmove  %rcx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb9(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [39 x i8] c"Hello from Parent, pid = %d \09 ppid=%d\0A\00"
@.str.1 = [38 x i8] c"Hello from child, pid = %d \09 ppid=%d\0A\00"
@.str.2 = [13 x i8] c"Common code\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i64 (...) @fork()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %8
4: ; preds = %0
%5 = call i32 (...) @getpid()
%6 = call i32 (...) @getppid()
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
br label %12
8: ; preds = %0
%9 = call i32 (...) @getpid()
%10 = call i32 (...) @getppid()
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %10)
br label %12
12: ; preds = %8, %4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [39 x i8] c"Hello from Parent, pid = %d \09 ppid=%d\0A\00"
@.str.1 = [38 x i8] c"Hello from child, pid = %d \09 ppid=%d\0A\00"
@str = [12 x i8] c"Common code\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (...) @getppid()
%5 = select i1 %2, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %5, i32 %3, i32 %4)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
ret i32 0
}