#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();
char *getpid();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main() {
  int pid = fork();
  int nbr1 = 0;
  int nbr2 = 0;
  switch (fork()) {
  case 0: {
    for (nbr1; nbr1 < 5; nbr1++) {
      printf("JE SUIS LE FILS DE PID %s \n", getpid());
      sleep(1);
    }
  }
  case -1: {
  }
  default: {
    switch (fork()) {
    case 0: {
      for (nbr2; nbr2 < 5; nbr2++) {
        printf("JE SUIS LE FILS DE PID %s \n", getpid());
        sleep(1);
      }
    }
    case -1: {
    }
    default: {
      wait(NULL);
      wait(NULL);
    }
    }
  }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %al,-0x15(%rbp)
call   1070 <fork@plt>
mov    %eax,%ecx
mov    -0x15(%rbp),%al
mov    %ecx,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
call   1070 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0xffffffff,%eax
je     11e4 <main+0x94>
jmp    1197 <main+0x47>
mov    -0x14(%rbp),%eax
test   %eax,%eax
jne    11e9 <main+0x99>
jmp    11a7 <main+0x57>
cmpl   $0x5,-0xc(%rbp)
jge    11df <main+0x8f>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
lea    0xe3e(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11a7 <main+0x57>
jmp    11e4 <main+0x94>
jmp    11e9 <main+0x99>
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     1250 <main+0x100>
jmp    1203 <main+0xb3>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
jne    1255 <main+0x105>
jmp    1213 <main+0xc3>
cmpl   $0x5,-0x10(%rbp)
jge    124b <main+0xfb>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %rax,%rsi
lea    0xdd2(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1213 <main+0xc3>
jmp    1250 <main+0x100>
jmp    1255 <main+0x105>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <wait@plt>
jmp    126c <main+0x11c>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    11fa <main+0xaa>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe8b(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    129c <main+0x14c>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xde9(%rip),%rbx
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <sleep@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %edi,%edi
call   1060 <wait@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [28 x i8] c"JE SUIS LE FILS DE PID %s \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 (...) @fork()
store i32 %5, i32* %2
store i32 0, i32* %3
store i32 0, i32* %4
%6 = call i32 (...) @fork()
switch i32 %6, label %21 [
i32 0, label %7
i32 -1, label %20
]
7: ; preds = %0
%8 = load i32, i32* %3
br label %9
9: ; preds = %16, %7
%10 = load i32, i32* %3
%11 = icmp slt i32 %10, 5
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = call i8* (...) @getpid()
%14 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @sleep(i32 1)
br label %16
16: ; preds = %12
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %9
19: ; preds = %9
br label %20
20: ; preds = %0, %19
br label %21
21: ; preds = %0, %20
%22 = call i32 (...) @fork()
switch i32 %22, label %37 [
i32 0, label %23
i32 -1, label %36
]
23: ; preds = %21
%24 = load i32, i32* %4
br label %25
25: ; preds = %32, %23
%26 = load i32, i32* %4
%27 = icmp slt i32 %26, 5
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = call i8* (...) @getpid()
%30 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %29)
%31 = call i32 @sleep(i32 1)
br label %32
32: ; preds = %28
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %25
35: ; preds = %25
br label %36
36: ; preds = %21, %35
br label %37
37: ; preds = %21, %36
%38 = call i32 @wait(i32* null)
%39 = call i32 @wait(i32* null)
br label %40
40: ; preds = %37
br label %41
41: ; preds = %40
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [28 x i8] c"JE SUIS LE FILS DE PID %s \0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = tail call i32 (...) @fork()
%3 = icmp eq i32 %2, 0
br i1 %3, label %4, label %20
4: ; preds = %0
%5 = tail call i8* (...) @getpid()
%6 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @sleep(i32 1)
%8 = tail call i8* (...) @getpid()
%9 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @sleep(i32 1)
%11 = tail call i8* (...) @getpid()
%12 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @sleep(i32 1)
%14 = tail call i8* (...) @getpid()
%15 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = tail call i32 @sleep(i32 1)
%17 = tail call i8* (...) @getpid()
%18 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = tail call i32 @sleep(i32 1)
br label %20
20: ; preds = %4, %0
%21 = tail call i32 (...) @fork()
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %39
23: ; preds = %20
%24 = tail call i8* (...) @getpid()
%25 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = tail call i32 @sleep(i32 1)
%27 = tail call i8* (...) @getpid()
%28 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = tail call i32 @sleep(i32 1)
%30 = tail call i8* (...) @getpid()
%31 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %30)
%32 = tail call i32 @sleep(i32 1)
%33 = tail call i8* (...) @getpid()
%34 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %33)
%35 = tail call i32 @sleep(i32 1)
%36 = tail call i8* (...) @getpid()
%37 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %36)
%38 = tail call i32 @sleep(i32 1)
br label %39
39: ; preds = %23, %20
%40 = tail call i32 @wait(i32* null)
%41 = tail call i32 @wait(i32* null)
ret i32 0
}