#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 /*<<< orphan*/ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, int);
int getpid();
int getppid();
int /*<<< orphan*/ stdout;
int main() {
  fprintf(stdout, "#1: PID=%d; My parent PID=%d\n", getpid(), getppid());
  fork();
  fprintf(stdout, "#2: PID=%d; My parent PID=%d\n", getpid(), getppid());
  return (1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%edx
mov    %eax,%ecx
lea    0xe85(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%edx
mov    %eax,%ecx
lea    0xe6b(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e95(%rip),%r14
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe9b(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
mov    (%r14),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe8d(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %eax,%ecx
call   1040 <fprintf@plt>
mov    $0x1,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [30 x i8] c": PID=%d; My parent PID=%d\0A\00"
@.str.1 = [30 x i8] c": PID=%d; My parent PID=%d\0A\00"
define i32 @main() {
%1 = alloca i32
store i32 0, i32* %1
%2 = load i32, i32* @stdout
%3 = call i32 (...) @getpid()
%4 = call i32 (...) @getppid()
%5 = call i32 @fprintf(i32 %2, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %4)
%6 = call i32 (...) @fork()
%7 = load i32, i32* @stdout
%8 = call i32 (...) @getpid()
%9 = call i32 (...) @getppid()
%10 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %9)
ret i32 1
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [30 x i8] c": PID=%d; My parent PID=%d\0A\00"
@.str.1 = [30 x i8] c": PID=%d; My parent PID=%d\0A\00"
define i32 @main() {
%1 = load i32, i32* @stdout
%2 = tail call i32 (...) @getpid()
%3 = tail call i32 (...) @getppid()
%4 = tail call i32 @fprintf(i32 %1, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %2, i32 %3)
%5 = tail call i32 (...) @fork()
%6 = load i32, i32* @stdout
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (...) @getppid()
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %8)
ret i32 1
}