#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*/ execl(char *, char *, char *, char *, int /*<<< orphan*/ *);
scalar_t__ fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ wait(int *);
void main(int argc, char **argv) {
  int x;
  int i;
  printf("pid=%d,ppid=%d\n", getpid(), getppid());
  for (i = 0; i < 5; i++) {
    if (fork() == 0) {
      printf("Avant appel apres fork pid=%d,ppid=%d\n", getpid(), getppid());
      execl("/home/pascalfares/nsy103/PratiqueNSY103/exec/plus", "I catch you",
            "3", "4", NULL);
    }
  }
  wait(&x);
  printf("Mom fils est mort!!! %d", x);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%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    0xe8b(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    1212 <main+0xb2>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    11ff <main+0x9f>
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    0xe2e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe47(%rip),%rdi
lea    0xe72(%rip),%rsi
lea    0xe77(%rip),%rdx
lea    0xe72(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <execl@plt>
jmp    1204 <main+0xa4>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    119a <main+0x3a>
lea    -0x14(%rbp),%rdi
call   1070 <wait@plt>
mov    -0x14(%rbp),%esi
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe9b(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    11d9 <main+0x79>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe56(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe6b(%rip),%rdi
lea    0xe96(%rip),%rsi
lea    0xe9b(%rip),%rdx
lea    0xe96(%rip),%rcx
xor    %r8d,%r8d
call   1060 <execl@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    122b <main+0xcb>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe04(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe19(%rip),%rdi
lea    0xe44(%rip),%rsi
lea    0xe49(%rip),%rdx
lea    0xe44(%rip),%rcx
xor    %r8d,%r8d
call   1060 <execl@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    127d <main+0x11d>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xdb2(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdc7(%rip),%rdi
lea    0xdf2(%rip),%rsi
lea    0xdf7(%rip),%rdx
lea    0xdf2(%rip),%rcx
xor    %r8d,%r8d
call   1060 <execl@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    12cf <main+0x16f>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xd60(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd75(%rip),%rdi
lea    0xda0(%rip),%rsi
lea    0xda5(%rip),%rdx
lea    0xda0(%rip),%rcx
xor    %r8d,%r8d
call   1060 <execl@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    1321 <main+0x1c1>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xd0e(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd23(%rip),%rdi
lea    0xd4e(%rip),%rsi
lea    0xd53(%rip),%rdx
lea    0xd4e(%rip),%rcx
xor    %r8d,%r8d
call   1060 <execl@plt>
lea    0xc(%rsp),%rdi
call   1070 <wait@plt>
mov    0xc(%rsp),%esi
lea    0xd33(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [16 x i8] c"pid=%d,ppid=%d\0A\00"
@.str.1 = [39 x i8] c"Avant appel apres fork pid=%d,ppid=%d\0A\00"
@.str.2 = [50 x i8] c"/home/pascalfares/nsy103/PratiqueNSY103/exec/plus\00"
@.str.3 = [12 x i8] c"I catch you\00"
@.str.4 = [2 x i8] c"3\00"
@.str.5 = [2 x i8] c"4\00"
@.str.6 = [24 x i8] c"Mom fils est mort!!! %d\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%7 = call i32 (...) @getpid()
%8 = call i32 (...) @getppid()
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
store i32 0, i32* %6
br label %10
10: ; preds = %22, %2
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 5
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = call i64 (...) @fork()
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = call i32 (...) @getpid()
%18 = call i32 (...) @getppid()
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18)
%20 = call i32 @execl(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* null)
br label %21
21: ; preds = %16, %13
br label %22
22: ; preds = %21
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %10
25: ; preds = %10
%26 = call i32 @wait(i32* %5)
%27 = load i32, i32* %5
%28 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %27)
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"pid=%d,ppid=%d\0A\00"
@.str.1 = [39 x i8] c"Avant appel apres fork pid=%d,ppid=%d\0A\00"
@.str.2 = [50 x i8] c"/home/pascalfares/nsy103/PratiqueNSY103/exec/plus\00"
@.str.3 = [12 x i8] c"I catch you\00"
@.str.4 = [2 x i8] c"3\00"
@.str.5 = [2 x i8] c"4\00"
@.str.6 = [24 x i8] c"Mom fils est mort!!! %d\00"
define void @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = tail call i32 (...) @getpid()
%6 = tail call i32 (...) @getppid()
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %6)
%8 = tail call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = tail call i32 (...) @getpid()
%12 = tail call i32 (...) @getppid()
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %11, i32 %12)
%14 = tail call i32 @execl(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* null)
br label %15
15: ; preds = %2, %10
%16 = tail call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = tail call i32 (...) @getpid()
%20 = tail call i32 (...) @getppid()
%21 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %19, i32 %20)
%22 = tail call i32 @execl(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* null)
br label %23
23: ; preds = %18, %15
%24 = tail call i64 (...) @fork()
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = tail call i32 (...) @getpid()
%28 = tail call i32 (...) @getppid()
%29 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %27, i32 %28)
%30 = tail call i32 @execl(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* null)
br label %31
31: ; preds = %26, %23
%32 = tail call i64 (...) @fork()
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %31
%35 = tail call i32 (...) @getpid()
%36 = tail call i32 (...) @getppid()
%37 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %35, i32 %36)
%38 = tail call i32 @execl(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* null)
br label %39
39: ; preds = %34, %31
%40 = tail call i64 (...) @fork()
%41 = icmp eq i64 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %39
%43 = tail call i32 (...) @getpid()
%44 = tail call i32 (...) @getppid()
%45 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i32 %43, i32 %44)
%46 = tail call i32 @execl(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32* null)
br label %47
47: ; preds = %42, %39
%48 = call i32 @wait(i32* %3)
%49 = load i32, i32* %3
%50 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i32 %49)
ret void
}