#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 /*<<< orphan*/ exit(int);
int fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, int);
int wait(int *);
int main(int argc, char *argv[], char **env) {
  int pid;
  int toto;
  if ((pid = fork()) == 0) {
    printf("%d : %d \n", getpid(), getppid());
    exit(0x1);
  }
  if ((pid = fork()) == 0) {
    printf("%d : %d \n", getpid(), getppid());
    exit(0);
  }
  if ((pid = fork()) == 0) {
    printf("%d : %d \n", getpid(), getppid());
    exit(0x123);
  }
  pid = wait(&toto);
  printf("Mon fils %d vien de se termioner avec le status %x\n", pid, toto);
  pid = wait(&toto);
  printf("Mon fils %d vien de se termioner avec le status %x\n", pid, toto);
  pid = wait(&toto);
  printf("Mon fils %d vien de se termioner avec le status %x\n", pid, toto);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11b2 <main+0x52>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x24(%rbp),%esi
mov    %eax,%edx
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11ee <main+0x8e>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x28(%rbp),%esi
mov    %eax,%edx
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    122d <main+0xcd>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
lea    0xde2(%rip),%rdi
call   1040 <printf@plt>
mov    $0x123,%edi
call   1060 <exit@plt>
lea    -0x20(%rbp),%rdi
call   1070 <wait@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xdc4(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1070 <wait@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xda6(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
call   1070 <wait@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
lea    0xd88(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11e5 <main+0x85>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     120f <main+0xaf>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1236 <main+0xd6>
lea    0x4(%rsp),%r14
mov    %r14,%rdi
call   1070 <wait@plt>
mov    0x4(%rsp),%edx
lea    0xe65(%rip),%rbx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1070 <wait@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1070 <wait@plt>
mov    0x4(%rsp),%edx
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xe04(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xdda(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <exit@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <getppid@plt>
lea    0xdb3(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1040 <printf@plt>
mov    $0x123,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"%d : %d \0A\00"
@.str.1 = [52 x i8] c"Mon fils %d vien de se termioner avec le status %x\0A\00"
define i32 @main(i32 %0, i8** %1, i8** %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8** %2, i8*** %6
%9 = call i32 (...) @fork()
store i32 %9, i32* %7
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %3
%12 = call i32 (...) @getpid()
%13 = call i32 (...) @getppid()
%14 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %3
%17 = call i32 (...) @fork()
store i32 %17, i32* %7
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = call i32 (...) @getpid()
%21 = call i32 (...) @getppid()
%22 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %20, i32 %21)
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %16
%25 = call i32 (...) @fork()
store i32 %25, i32* %7
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %24
%28 = call i32 (...) @getpid()
%29 = call i32 (...) @getppid()
%30 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29)
%31 = call i32 @exit(i32 291)
unreachable
32: ; preds = %24
%33 = call i32 @wait(i32* %8)
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %34, i32 %35)
%37 = call i32 @wait(i32* %8)
store i32 %37, i32* %7
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %38, i32 %39)
%41 = call i32 @wait(i32* %8)
store i32 %41, i32* %7
%42 = load i32, i32* %7
%43 = load i32, i32* %8
%44 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %42, i32 %43)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"%d : %d \0A\00"
@.str.1 = [52 x i8] c"Mon fils %d vien de se termioner avec le status %x\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1, i8** nocapture readnone %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = tail call i32 (...) @fork()
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %3
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (...) @getppid()
%11 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9, i32 %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %3
%14 = tail call i32 (...) @fork()
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %13
%17 = tail call i32 (...) @getpid()
%18 = tail call i32 (...) @getppid()
%19 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18)
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %13
%22 = tail call i32 (...) @fork()
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = tail call i32 (...) @getpid()
%26 = tail call i32 (...) @getppid()
%27 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %25, i32 %26)
%28 = tail call i32 @exit(i32 291)
unreachable
29: ; preds = %21
%30 = call i32 @wait(i32* %4)
%31 = load i32, i32* %4
%32 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %30, i32 %31)
%33 = call i32 @wait(i32* %4)
%34 = load i32, i32* %4
%35 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34)
%36 = call i32 @wait(i32* %4)
%37 = load i32, i32* %4
%38 = call i32 @printf(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0), i32 %36, i32 %37)
ret i32 0
}