#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 */
typedef int pid_t;

/* Variables and functions */
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, ...);
int waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main() {
  pid_t Pid;
  switch (Pid = fork()) {
  case -1: {
    printf("Probleme : echec du fork");
    break;
  }
  case 0: {
    printf("du descendant : valeur de retour de fork() : %d\n", Pid);
    printf("du descendant : je suis %d de parent %d \n", getpid(), getppid());
    break;
  }
  default: {
    printf("du parent : valeur de retour de fork() : %d\n", Pid);
    printf("du parent : je suis %d de parent %d \n", getpid(), getppid());
    pid_t mortAnnoncee = waitpid(Pid, NULL, 0);
    printf("du parent : mort annoncee de : %d \n", mortAnnoncee);
    break;
  }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
sub    $0xffffffff,%eax
je     118c <main+0x3c>
jmp    117c <main+0x2c>
mov    -0x10(%rbp),%eax
test   %eax,%eax
je     119f <main+0x4f>
jmp    11d9 <main+0x89>
lea    0xe6d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1230 <main+0xe0>
mov    -0x8(%rbp),%esi
lea    0xe70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x14(%rbp),%esi
mov    %eax,%edx
lea    0xe7d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1230 <main+0xe0>
mov    -0x8(%rbp),%esi
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1060 <getppid@plt>
mov    -0x18(%rbp),%esi
mov    %eax,%edx
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     1178 <main+0x28>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    11ac <main+0x5c>
lea    0xe94(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f9 <main+0xa9>
lea    0xe9a(%rip),%rdi
xor    %esi,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xeab(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f9 <main+0xa9>
lea    0xec1(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <getppid@plt>
lea    0xece(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <waitpid@plt>
lea    0xed7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"Probleme : echec du fork\00"
@.str.1 = [49 x i8] c"du descendant : valeur de retour de fork() : %d\0A\00"
@.str.2 = [42 x i8] c"du descendant : je suis %d de parent %d \0A\00"
@.str.3 = [45 x i8] c"du parent : valeur de retour de fork() : %d\0A\00"
@.str.4 = [38 x i8] c"du parent : je suis %d de parent %d \0A\00"
@.str.5 = [36 x i8] c"du parent : mort annoncee de : %d \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (...) @fork()
store i32 %4, i32* %2
switch i32 %4, label %13 [
i32 -1, label %5
i32 0, label %7
]
5: ; preds = %0
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %23
7: ; preds = %0
%8 = load i32, i32* %2
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = call i32 (...) @getpid()
%11 = call i32 (...) @getppid()
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %11)
br label %23
13: ; preds = %0
%14 = load i32, i32* %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %14)
%16 = call i32 (...) @getpid()
%17 = call i32 (...) @getppid()
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %16, i32 %17)
%19 = load i32, i32* %2
%20 = call i32 @waitpid(i32 %19, i32* null, i32 0)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %13, %7, %5
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [25 x i8] c"Probleme : echec du fork\00"
@.str.1 = [49 x i8] c"du descendant : valeur de retour de fork() : %d\0A\00"
@.str.2 = [42 x i8] c"du descendant : je suis %d de parent %d \0A\00"
@.str.3 = [45 x i8] c"du parent : valeur de retour de fork() : %d\0A\00"
@.str.4 = [38 x i8] c"du parent : je suis %d de parent %d \0A\00"
@.str.5 = [36 x i8] c"du parent : mort annoncee de : %d \0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fork()
switch i32 %1, label %9 [
i32 -1, label %2
i32 0, label %4
]
2: ; preds = %0
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %16
4: ; preds = %0
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 0)
%6 = tail call i32 (...) @getpid()
%7 = tail call i32 (...) @getppid()
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %6, i32 %7)
br label %16
9: ; preds = %0
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %1)
%11 = tail call i32 (...) @getpid()
%12 = tail call i32 (...) @getppid()
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i32 %11, i32 %12)
%14 = tail call i32 @waitpid(i32 %1, i32* null, i32 0)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0), i32 %14)
br label %16
16: ; preds = %9, %4, %2
ret i32 0
}