#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 */
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, int, ...);
int main(int argc, char **argv) {
  int pid = fork();
  if (pid == 0) {
    printf("CHILD// PID: %d PPID: %d\n", getpid(), getppid());
  } else {
    printf("FATHER// PID: %d PPID: %d CHILD_PID: %d\n", getpid(), getppid(),
           pid);
  }
  return 1;
}


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   1060 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1193 <main+0x53>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x18(%rbp),%esi
mov    %eax,%edx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ba <main+0x7a>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x1c(%rbp),%esi
mov    %eax,%edx
mov    -0x14(%rbp),%ecx
lea    0xe67(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getppid@plt>
test   %ebx,%ebx
je     1176 <main+0x36>
lea    0xeb3(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %ebx,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1188 <main+0x48>
lea    0xe83(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"CHILD// PID: %d PPID: %d\0A\00"
@.str.1 = [41 x i8] c"FATHER// PID: %d PPID: %d CHILD_PID: %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i32 (...) @fork()
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = call i32 (...) @getpid()
%12 = call i32 (...) @getppid()
%13 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
br label %19
14: ; preds = %2
%15 = call i32 (...) @getpid()
%16 = call i32 (...) @getppid()
%17 = load i32, i32* %6
%18 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %15, i32 %16, i32 %17)
br label %19
19: ; preds = %14, %10
ret i32 1
}

LLVM IR (-O2):
@.str = [26 x i8] c"CHILD// PID: %d PPID: %d\0A\00"
@.str.1 = [41 x i8] c"FATHER// PID: %d PPID: %d CHILD_PID: %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @fork()
%4 = icmp eq i32 %3, 0
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 (...) @getppid()
br i1 %4, label %7, label %9
7: ; preds = %2
%8 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
br label %11
9: ; preds = %2
%10 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %6, i32 %3)
br label %11
11: ; preds = %9, %7
ret i32 1
}