#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();
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ printf(char *, int, ...);
void main(void) {
  int valeur, valeur1;
  printf(" print 1 - Je suis le processus pere num=%d \n", (int)getpid());
  valeur = fork();
  printf(" print 2 - retour fork: %d - processus num= %d -num pere=%d \n",
         valeur, (int)getpid(), (int)getppid());
  valeur1 = fork();
  printf(" print 3 - retour fork: %d - processus num= %d -num pere=%d \n",
         valeur1, (int)getpid(), (int)getppid());
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xea8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x14(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x18(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    %eax,%ecx
lea    0xe9f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    %eax,%ecx
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xeaf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xeb3(%rip),%rdi
mov    %ebp,%esi
mov    %ebx,%edx
mov    %eax,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %rax,%rbp
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xec3(%rip),%rdi
mov    %ebx,%esi
mov    %ebp,%edx
mov    %eax,%ecx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [46 x i8] c" print 1 - Je suis le processus pere num=%d \0A\00"
@.str.1 = [62 x i8] c" print 2 - retour fork: %d - processus num= %d -num pere=%d \0A\00"
@.str.2 = [62 x i8] c" print 3 - retour fork: %d - processus num= %d -num pere=%d \0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = call i64 (...) @getpid()
%4 = trunc i64 %3 to i32
%5 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i32 (...) @fork()
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = call i64 (...) @getpid()
%9 = trunc i64 %8 to i32
%10 = call i64 (...) @getppid()
%11 = trunc i64 %10 to i32
%12 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %9, i32 %11)
%13 = call i32 (...) @fork()
store i32 %13, i32* %2
%14 = load i32, i32* %2
%15 = call i64 (...) @getpid()
%16 = trunc i64 %15 to i32
%17 = call i64 (...) @getppid()
%18 = trunc i64 %17 to i32
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %16, i32 %18)
ret void
}

LLVM IR (-O2):
@.str = [46 x i8] c" print 1 - Je suis le processus pere num=%d \0A\00"
@.str.1 = [62 x i8] c" print 2 - retour fork: %d - processus num= %d -num pere=%d \0A\00"
@.str.2 = [62 x i8] c" print 3 - retour fork: %d - processus num= %d -num pere=%d \0A\00"
define void @main() {
%1 = tail call i64 (...) @getpid()
%2 = trunc i64 %1 to i32
%3 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call i32 (...) @fork()
%5 = tail call i64 (...) @getpid()
%6 = trunc i64 %5 to i32
%7 = tail call i64 (...) @getppid()
%8 = trunc i64 %7 to i32
%9 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0), i32 %4, i32 %6, i32 %8)
%10 = tail call i32 (...) @fork()
%11 = tail call i64 (...) @getpid()
%12 = trunc i64 %11 to i32
%13 = tail call i64 (...) @getppid()
%14 = trunc i64 %13 to i32
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.2, i64 0, i64 0), i32 %10, i32 %12, i32 %14)
ret void
}