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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0x8(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11c5 <main+0x85>
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    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0xc8,-0xc(%rbp)
jge    11c0 <main+0x80>
mov    -0xc(%rbp),%esi
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1194 <main+0x54>
jmp    123a <main+0xfa>
cmpl   $0x0,-0x10(%rbp)
jne    1227 <main+0xe7>
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    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     1222 <main+0xe2>
mov    -0xc(%rbp),%esi
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    11f9 <main+0xb9>
jmp    1235 <main+0xf5>
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    123a <main+0xfa>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
jle    1199 <main+0x59>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe9a(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x64,%ebx
lea    0xea7(%rip),%r14
nopl   (%rax)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebx
cmp    $0xc8,%ebx
jne    1180 <main+0x40>
jmp    11f1 <main+0xb1>
je     11ab <main+0x6b>
lea    0xeb6(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11f1 <main+0xb1>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe6b(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x64,%ebx
lea    0xe77(%rip),%r14
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0xffffffff,%ebx
jb     11e0 <main+0xa0>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [36 x i8] c"je suis le p\C3\A8re pid= %d, ppid= %d\0A\00"
@.str.1 = [9 x i8] c"p\C3\A8re %d\00"
@.str.2 = [35 x i8] c"je suis le fils pid= %d, ppid= %d\0A\00"
@.str.3 = [8 x i8] c"fils %d\00"
@.str.4 = [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 %12
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)
br label %7
7: ; preds = %3, %7
%8 = phi i32 [ 100, %3 ], [ %10, %7 ]
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = add nuw nsw i32 %8, 1
%11 = icmp eq i32 %10, 200
br i1 %11, label %25, label %7
12: ; preds = %0
%13 = icmp eq i32 %1, 0
br i1 %13, label %14, label %23
14: ; preds = %12
%15 = tail call i32 (...) @getpid()
%16 = tail call i32 (...) @getppid()
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %15, i32 %16)
br label %18
18: ; preds = %14, %18
%19 = phi i32 [ 100, %14 ], [ %21, %18 ]
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%21 = add nsw i32 %19, -1
%22 = icmp eq i32 %19, 0
br i1 %22, label %25, label %18
23: ; preds = %12
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
br label %25
25: ; preds = %18, %7, %23
ret i32 0
}