#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 atoi(char *);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int getpid();
int getppid();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int tC, tP;
  pid_t pid;
  tC = atoi(argv[1]);
  tP = atoi(argv[2]);
  fprintf(stdout, "Main  :                  ");
  fprintf(stdout, "PID=%d; My parent PID=%d\n", getpid(), getppid());
  pid = fork();
  if (pid == 0) {
    sleep(tC);
    fprintf(stdout, "Child : PIDreturned=%d    ", pid);
    fprintf(stdout, "PID=%d; My parent PID=%d\n", getpid(), getppid());
  } else {
    sleep(tP);
    fprintf(stdout, "Parent: PIDreturned=%d ", pid);
    fprintf(stdout, "PID=%d; My parent PID=%d\n", getpid(), getppid());
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1050 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
lea    0xe41(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1251 <main+0xf1>
mov    -0x14(%rbp),%edi
call   1070 <sleep@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe22(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    %eax,%ecx
lea    0xdd5(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12a7 <main+0x147>
mov    -0x18(%rbp),%edi
call   1070 <sleep@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x34(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x38(%rbp),%edi
mov    -0x34(%rbp),%edx
mov    %eax,%ecx
lea    0xd7a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   1050 <atoi@plt>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
call   1050 <atoi@plt>
mov    %eax,%r15d
mov    0x2e56(%rip),%r12
mov    (%r12),%edi
lea    0xe6b(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r12),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xe63(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11eb <main+0x8b>
mov    %rax,%rbx
mov    %r15d,%edi
call   1070 <sleep@plt>
mov    (%r12),%edi
lea    0xe69(%rip),%rsi
mov    %rbx,%rdx
jmp    1200 <main+0xa0>
mov    %r14d,%edi
call   1070 <sleep@plt>
mov    (%r12),%edi
lea    0xe36(%rip),%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r12),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xdf8(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [26 x i8] c"Main : \00"
@.str.1 = [26 x i8] c"PID=%d; My parent PID=%d\0A\00"
@.str.2 = [27 x i8] c"Child : PIDreturned=%d \00"
@.str.3 = [24 x i8] c"Parent: PIDreturned=%d \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32 @atoi(i8* %11)
store i32 %12, i32* %6
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* @stdout
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @stdout
%20 = call i32 (...) @getpid()
%21 = call i32 (...) @getppid()
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 %21)
%23 = call i64 (...) @fork()
store i64 %23, i64* %8
%24 = load i64, i64* %8
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %36
26: ; preds = %2
%27 = load i32, i32* %6
%28 = call i32 @sleep(i32 %27)
%29 = load i32, i32* @stdout
%30 = load i64, i64* %8
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 %30)
%32 = load i32, i32* @stdout
%33 = call i32 (...) @getpid()
%34 = call i32 (...) @getppid()
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34)
br label %46
36: ; preds = %2
%37 = load i32, i32* %7
%38 = call i32 @sleep(i32 %37)
%39 = load i32, i32* @stdout
%40 = load i64, i64* %8
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 %40)
%42 = load i32, i32* @stdout
%43 = call i32 (...) @getpid()
%44 = call i32 (...) @getppid()
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %43, i32 %44)
br label %46
46: ; preds = %36, %26
ret i32 0
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [26 x i8] c"Main : \00"
@.str.1 = [26 x i8] c"PID=%d; My parent PID=%d\0A\00"
@.str.2 = [27 x i8] c"Child : PIDreturned=%d \00"
@.str.3 = [24 x i8] c"Parent: PIDreturned=%d \00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32 @atoi(i8* %4)
%6 = getelementptr inbounds i8*, i8** %1, i64 2
%7 = load i8*, i8** %6
%8 = tail call i32 @atoi(i8* %7)
%9 = load i32, i32* @stdout
%10 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stdout
%12 = tail call i32 (...) @getpid()
%13 = tail call i32 (...) @getppid()
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %13)
%15 = tail call i64 (...) @fork()
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %2
%18 = tail call i32 @sleep(i32 %5)
%19 = load i32, i32* @stdout
%20 = tail call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0), i64 0)
br label %25
21: ; preds = %2
%22 = tail call i32 @sleep(i32 %8)
%23 = load i32, i32* @stdout
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i64 %15)
br label %25
25: ; preds = %21, %17
%26 = load i32, i32* @stdout
%27 = tail call i32 (...) @getpid()
%28 = tail call i32 (...) @getppid()
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %28)
ret i32 0
}