#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*/ exit(int);
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  printf("Je suis le processus %d et mon père est le processus %d \n", getpid(),
         getppid());
  int pid1 = fork();
  if (pid1 == 0) {
    printf("Je suis le processus %d et mon père est le processus %d \n",
           getpid(), getppid());
    int pid3 = fork();
    if (pid3 == 0) {
      printf("Je suis le processus %d et mon père est le processus %d \n",
             getpid(), getppid());
    } else if (pid3 < 0) {
      exit(-1);
    }
    wait(NULL);
  }
  if (pid1 > 0) {
    int pid2 = fork();
    if (pid2 == 0) {
      printf("Je suis le processus %d et mon père est le processus %d \n",
             getpid(), getppid());
    } else if (pid2 < 0) {
      exit(-1);
    }
    wait(NULL);
  } else {
    exit(-1);
  }
  wait(NULL);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe74(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    1224 <main+0xc4>
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    0xe3e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1202 <main+0xa2>
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    0xe08(%rip),%rdi
call   1040 <printf@plt>
jmp    121b <main+0xbb>
cmpl   $0x0,-0xc(%rbp)
jge    1216 <main+0xb6>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    121b <main+0xbb>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
cmpl   $0x0,-0x8(%rbp)
jle    1290 <main+0x130>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    1269 <main+0x109>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x20(%rbp),%esi
mov    %eax,%edx
lea    0xda1(%rip),%rdi
call   1040 <printf@plt>
jmp    1282 <main+0x122>
cmpl   $0x0,-0x10(%rbp)
jge    127d <main+0x11d>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
jmp    1282 <main+0x122>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
jmp    129a <main+0x13a>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe88(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
jne    11d9 <main+0x79>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe5d(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
jne    1208 <main+0xa8>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe32(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
jmp    120a <main+0xaa>
jle    1211 <main+0xb1>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
jne    121b <main+0xbb>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe03(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
jmp    121d <main+0xbd>
js     1211 <main+0xb1>
xor    %edi,%edi
call   1070 <wait@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
js     1211 <main+0xb1>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [59 x i8] c"Je suis le processus %d et mon p\C3\A8re est le processus %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 (...) @getpid()
%6 = call i32 (...) @getppid()
%7 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = call i32 (...) @fork()
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %30
11: ; preds = %0
%12 = call i32 (...) @getpid()
%13 = call i32 (...) @getppid()
%14 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%15 = call i32 (...) @fork()
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %11
%19 = call i32 (...) @getpid()
%20 = call i32 (...) @getppid()
%21 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %19, i32 %20)
br label %28
22: ; preds = %11
%23 = load i32, i32* %3
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %22
br label %28
28: ; preds = %27, %18
%29 = call i32 @wait(i32* null)
br label %30
30: ; preds = %28, %0
%31 = load i32, i32* %2
%32 = icmp sgt i32 %31, 0
br i1 %32, label %33, label %49
33: ; preds = %30
%34 = call i32 (...) @fork()
store i32 %34, i32* %4
%35 = load i32, i32* %4
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %33
%38 = call i32 (...) @getpid()
%39 = call i32 (...) @getppid()
%40 = call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %38, i32 %39)
br label %47
41: ; preds = %33
%42 = load i32, i32* %4
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = call i32 @exit(i32 -1)
unreachable
46: ; preds = %41
br label %47
47: ; preds = %46, %37
%48 = call i32 @wait(i32* null)
br label %51
49: ; preds = %30
%50 = call i32 @exit(i32 -1)
unreachable
51: ; preds = %47
%52 = call i32 @wait(i32* null)
%53 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [59 x i8] c"Je suis le processus %d et mon p\C3\A8re est le processus %d \0A\00"
define i32 @main() {
%1 = tail call i32 (...) @getpid()
%2 = tail call i32 (...) @getppid()
%3 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %2)
%4 = tail call i32 (...) @fork()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %22
6: ; preds = %0
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (...) @getppid()
%9 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = tail call i32 (...) @fork()
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = tail call i32 (...) @getpid()
%14 = tail call i32 (...) @getppid()
%15 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %13, i32 %14)
br label %20
16: ; preds = %6
%17 = icmp slt i32 %10, 0
br i1 %17, label %18, label %20
18: ; preds = %16
%19 = tail call i32 @exit(i32 -1)
unreachable
20: ; preds = %12, %16
%21 = tail call i32 @wait(i32* null)
br label %39
22: ; preds = %0
%23 = icmp sgt i32 %4, 0
br i1 %23, label %24, label %39
24: ; preds = %22
%25 = tail call i32 (...) @fork()
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %31
27: ; preds = %24
%28 = tail call i32 (...) @getpid()
%29 = tail call i32 (...) @getppid()
%30 = tail call i32 @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29)
br label %35
31: ; preds = %24
%32 = icmp slt i32 %25, 0
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = tail call i32 @exit(i32 -1)
unreachable
35: ; preds = %31, %27
%36 = tail call i32 @wait(i32* null)
%37 = tail call i32 @wait(i32* null)
%38 = tail call i32 @exit(i32 0)
unreachable
39: ; preds = %20, %22
%40 = tail call i32 @exit(i32 -1)
unreachable
}