#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 scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
main() {
  pid_t pidFils = fork();
  if (pidFils != 0) {
    printf("je suis le pere, mon numero est %d", getpid());
    printf(", celui de mon fils est %d\n", pidFils);
    printf(", et celui de mon pere est %d\n", getppid());
    sleep(15);
  } else {
    sleep(1);
    printf("je suis le fils, mon numero est %d", getpid());
    printf(", celui de mon pere est %d\n", getppid());
    printf(", et celui de mon pere est %d\n", getppid());
    sleep(15);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11c0 <main+0x70>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe7b(%rip),%rdi
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,%esi
lea    0xe93(%rip),%rdi
call   1040 <printf@plt>
mov    $0xf,%edi
call   1060 <sleep@plt>
jmp    1213 <main+0xc3>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,%esi
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1050 <getppid@plt>
mov    %eax,%esi
lea    0xe3b(%rip),%rdi
call   1040 <printf@plt>
mov    $0xf,%edi
call   1060 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1180 <main+0x30>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xe92(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
lea    0xea7(%rip),%rdi
mov    %ebx,%esi
jmp    11af <main+0x5f>
mov    $0x1,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xec6(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xed4(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe7d(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0xf,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"je suis le pere, mon numero est %d\00"
@.str.1 = [28 x i8] c", celui de mon fils est %d\0A\00"
@.str.2 = [31 x i8] c", et celui de mon pere est %d\0A\00"
@.str.3 = [35 x i8] c"je suis le fils, mon numero est %d\00"
@.str.4 = [28 x i8] c", celui de mon pere est %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %15
6: ; preds = %0
%7 = call i32 (...) @getpid()
%8 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i64, i64* %2
%10 = trunc i64 %9 to i32
%11 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = call i32 (...) @getppid()
%13 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = call i32 @sleep(i32 15)
br label %24
15: ; preds = %0
%16 = call i32 @sleep(i32 1)
%17 = call i32 (...) @getpid()
%18 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %17)
%19 = call i32 (...) @getppid()
%20 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = call i32 (...) @getppid()
%22 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = call i32 @sleep(i32 15)
br label %24
24: ; preds = %15, %6
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [35 x i8] c"je suis le pere, mon numero est %d\00"
@.str.1 = [28 x i8] c", celui de mon fils est %d\0A\00"
@.str.2 = [31 x i8] c", et celui de mon pere est %d\0A\00"
@.str.3 = [35 x i8] c"je suis le fils, mon numero est %d\00"
@.str.4 = [28 x i8] c", celui de mon pere est %d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %8, label %3
3: ; preds = %0
%4 = tail call i32 (...) @getpid()
%5 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = trunc i64 %1 to i32
%7 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %6)
br label %14
8: ; preds = %0
%9 = tail call i32 @sleep(i32 1)
%10 = tail call i32 (...) @getpid()
%11 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = tail call i32 (...) @getppid()
%13 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0), i32 %12)
br label %14
14: ; preds = %8, %3
%15 = tail call i32 (...) @getppid()
%16 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = tail call i32 @sleep(i32 15)
ret i32 0
}