#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 *, ...);
main() {
  int res = fork();
  if (res > 0) {
    printf("je suis le père pid= %d, ppid= %d\n", getpid(), getppid());
    res = fork();
    if (res > 0) {
      printf("je suis le père pid= %d, ppid= %d\n", getpid(), getppid());
    } else if (res == 0) {
      printf("je suis le fils pid= %d, ppid= %d\n", getpid(), getppid());
    } else {
      printf("Erreure :(");
    }
  } else if (res == 0) {
    printf("je suis le fils pid= %d, ppid= %d\n", getpid(), getppid());
  } else {
    printf("Erreure :(");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    120f <main+0xcf>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe80(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jle    11c4 <main+0x84>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120a <main+0xca>
cmpl   $0x0,-0x8(%rbp)
jne    11f7 <main+0xb7>
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    0xe39(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1205 <main+0xc5>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    120a <main+0xca>
jmp    1255 <main+0x115>
cmpl   $0x0,-0x8(%rbp)
jne    1242 <main+0x102>
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    0xdee(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1250 <main+0x110>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1255 <main+0x115>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
jle    1192 <main+0x52>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe9d(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
jle    1192 <main+0x52>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe70(%rip),%rdi
jmp    11bb <main+0x7b>
je     11a4 <main+0x64>
lea    0xeac(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11c6 <main+0x86>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe69(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [36 x i8] c"je suis le p\C3\A8re pid= %d, ppid= %d\0A\00"
@.str.1 = [35 x i8] c"je suis le fils pid= %d, ppid= %d\0A\00"
@.str.2 = [11 x i8] c"Erreure :(\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp sgt i32 %4, 0
br i1 %5, label %6, label %28
6: ; preds = %0
%7 = call i32 (...) @getpid()
%8 = call i32 (...) @getppid()
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %8)
%10 = call i32 (...) @fork()
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %6
%14 = call i32 (...) @getpid()
%15 = call i32 (...) @getppid()
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15)
br label %27
17: ; preds = %6
%18 = load i32, i32* %2
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = call i32 (...) @getpid()
%22 = call i32 (...) @getppid()
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22)
br label %26
24: ; preds = %17
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
br label %27
27: ; preds = %26, %13
br label %38
28: ; preds = %0
%29 = load i32, i32* %2
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = call i32 (...) @getpid()
%33 = call i32 (...) @getppid()
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %32, i32 %33)
br label %37
35: ; preds = %28
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
br label %38
38: ; preds = %37, %27
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@.str = [36 x i8] c"je suis le p\C3\A8re pid= %d, ppid= %d\0A\00"
@.str.1 = [35 x i8] c"je suis le fils pid= %d, ppid= %d\0A\00"
@.str.2 = [11 x i8] c"Erreure :(\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp sgt i32 %1, 0
br i1 %2, label %3, label %21
3: ; preds = %0
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 (...) @getppid()
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
%7 = tail call i32 (...) @fork()
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 (...) @getppid()
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %10, i32 %11)
br label %29
13: ; preds = %3
%14 = icmp eq i32 %7, 0
br i1 %14, label %15, label %19
15: ; preds = %13
%16 = tail call i32 (...) @getpid()
%17 = tail call i32 (...) @getppid()
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %16, i32 %17)
br label %29
19: ; preds = %13
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %29
21: ; preds = %0
%22 = icmp eq i32 %1, 0
br i1 %22, label %23, label %27
23: ; preds = %21
%24 = tail call i32 (...) @getpid()
%25 = tail call i32 (...) @getppid()
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %24, i32 %25)
br label %29
27: ; preds = %21
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %23, %27, %9, %19, %15
ret i32 0
}