#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 /*<<< orphan*/ sleep(int);
main() {
  int i;
  int pid, ppid;
  int resFork;
  int x = 100;
  printf("PRINCIPAL : %d <- %d\n", getpid(), getppid());
  resFork = fork();
  if (resFork == 0) {
    x = 10;
    printf("\nFILS : fork=%d %d <- %d x=%d\n", resFork, getpid(), getppid(), x);
  } else {
    printf("\nPERE : fork=%d %d <- %d x=%d\n", resFork, getpid(), getppid(), x);
    sleep(60);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x18(%rbp)
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
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11db <main+0x8b>
movl   $0xa,-0x18(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    %eax,%ecx
mov    -0x18(%rbp),%r8d
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1216 <main+0xc6>
mov    -0x14(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    %eax,%ecx
mov    -0x18(%rbp),%r8d
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x3c,%edi
call   1060 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe96(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
test   %ebp,%ebp
je     11b8 <main+0x68>
lea    0xe9c(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
mov    $0x64,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x3c,%edi
call   1060 <sleep@plt>
jmp    11d2 <main+0x82>
lea    0xe57(%rip),%rdi
xor    %esi,%esi
mov    %ebx,%edx
mov    %eax,%ecx
mov    $0xa,%r8d
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"PRINCIPAL : %d <- %d\0A\00"
@.str.1 = [31 x i8] c"\0AFILS : fork=%d %d <- %d x=%d\0A\00"
@.str.2 = [31 x i8] c"\0APERE : fork=%d %d <- %d x=%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 100, i32* %6
%7 = call i32 (...) @getpid()
%8 = call i32 (...) @getppid()
%9 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = call i32 (...) @fork()
store i32 %10, i32* %5
%11 = load i32, i32* %5
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %0
store i32 10, i32* %6
%14 = load i32, i32* %5
%15 = call i32 (...) @getpid()
%16 = call i32 (...) @getppid()
%17 = load i32, i32* %6
%18 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %15, i32 %16, i32 %17)
br label %26
19: ; preds = %0
%20 = load i32, i32* %5
%21 = call i32 (...) @getpid()
%22 = call i32 (...) @getppid()
%23 = load i32, i32* %6
%24 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %21, i32 %22, i32 %23)
%25 = call i32 @sleep(i32 60)
br label %26
26: ; preds = %19, %13
%27 = load i32, i32* %1
ret i32 %27
}

LLVM IR (-O2):
@.str = [22 x i8] c"PRINCIPAL : %d <- %d\0A\00"
@.str.1 = [31 x i8] c"\0AFILS : fork=%d %d <- %d x=%d\0A\00"
@.str.2 = [31 x i8] c"\0APERE : fork=%d %d <- %d x=%d\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (...) @getppid()
%3 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%4 = tail call i32 (...) @fork()
%5 = icmp eq i32 %4, 0
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 (...) @getppid()
br i1 %5, label %8, label %10
8: ; preds = %0
%9 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %6, i32 %7, i32 10)
br label %13
10: ; preds = %0
%11 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %6, i32 %7, i32 100)
%12 = tail call i32 @sleep(i32 60)
br label %13
13: ; preds = %10, %8
ret i32 0
}