#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 EXIT_SUCCESS;
int fprintf(int /*<<< orphan*/, char *, int);
int nfork(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdout;
int main(void) {
  int p;
  int i = 1;
  int N = 3;
  int fprintf_return = 0;
  int nb_processus = 1;
  do {
    p = nfork(i);
    nb_processus += p;
    if (p != 0)
      printf("%d \n", p);
  } while ((p == 0) && (++i <= N));
  fprintf_return = fprintf(stdout, "nb de processus: %d \n", nb_processus);
  if (fprintf_return < 0) {
    perror("Error fprintf");
    return fprintf_return;
  }
  printf("FIN\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
movl   $0x3,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x1,-0x18(%rbp)
mov    -0xc(%rbp),%edi
call   1030 <nfork@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     119a <main+0x5a>
mov    -0x8(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    119f <main+0x5f>
xor    %eax,%eax
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0x19(%rbp)
jne    11c0 <main+0x80>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
cmp    -0x10(%rbp),%eax
setle  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116b <main+0x2b>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%edx
lea    0xe22(%rip),%rsi
call   1050 <fprintf@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1207 <main+0xc7>
lea    0xe1f(%rip),%rdi
call   1060 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1221 <main+0xe1>
lea    0xe16(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x1,%edi
call   1040 <nfork@plt>
lea    0x1(%rax),%ebx
test   %eax,%eax
jne    1182 <main+0x32>
mov    $0x2,%edi
call   1040 <nfork@plt>
add    %eax,%ebx
test   %eax,%eax
jne    1182 <main+0x32>
mov    $0x3,%edi
call   1040 <nfork@plt>
add    %eax,%ebx
test   %eax,%eax
je     1192 <main+0x42>
lea    0xe88(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
lea    0xe5e(%rip),%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
test   %eax,%eax
js     11c6 <main+0x76>
lea    0xe70(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%ebx
mov    %ebx,%eax
pop    %rbx
ret
mov    %eax,%ebx
lea    0xe47(%rip),%rdi
call   1070 <perror@plt>
jmp    11c2 <main+0x72>

LLVM IR (-O0):
@.str = [5 x i8] c"%d \0A\00"
@stdout = global i32 0
@.str.1 = [22 x i8] c"nb de processus: %d \0A\00"
@.str.2 = [14 x i8] c"Error fprintf\00"
@.str.3 = [5 x i8] c"FIN\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
store i32 1, i32* %3
store i32 3, i32* %4
store i32 0, i32* %5
store i32 1, i32* %6
br label %7
7: ; preds = %27, %0
%8 = load i32, i32* %3
%9 = call i32 @nfork(i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = load i32, i32* %6
%12 = add nsw i32 %11, %10
store i32 %12, i32* %6
%13 = load i32, i32* %2
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %7
%16 = load i32, i32* %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %7
br label %19
19: ; preds = %18
%20 = load i32, i32* %2
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
%25 = load i32, i32* %4
%26 = icmp sle i32 %24, %25
br label %27
27: ; preds = %22, %19
%28 = phi i1 [ false, %19 ], [ %26, %22 ]
br i1 %28, label %7, label %29
29: ; preds = %27
%30 = load i32, i32* @stdout
%31 = load i32, i32* %6
%32 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %31)
store i32 %32, i32* %5
%33 = load i32, i32* %5
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %38
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32, i32* %5
store i32 %37, i32* %1
br label %41
38: ; preds = %29
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @EXIT_SUCCESS
store i32 %40, i32* %1
br label %41
41: ; preds = %38, %35
%42 = load i32, i32* %1
ret i32 %42
}

LLVM IR (-O2):
@.str = [5 x i8] c"%d \0A\00"
@stdout = global i32 0
@.str.1 = [22 x i8] c"nb de processus: %d \0A\00"
@.str.2 = [14 x i8] c"Error fprintf\00"
@EXIT_SUCCESS = global i32 0
@str = [4 x i8] c"FIN\00"
define i32 @main() {
%1 = tail call i32 @nfork(i32 1)
%2 = add nsw i32 %1, 1
%3 = icmp eq i32 %1, 0
br i1 %3, label %8, label %4
4: ; preds = %12, %8, %0
%5 = phi i32 [ %1, %0 ], [ %9, %8 ], [ %13, %12 ]
%6 = phi i32 [ %2, %0 ], [ %10, %8 ], [ %14, %12 ]
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %16
8: ; preds = %0
%9 = tail call i32 @nfork(i32 2)
%10 = add nsw i32 %9, %2
%11 = icmp eq i32 %9, 0
br i1 %11, label %12, label %4
12: ; preds = %8
%13 = tail call i32 @nfork(i32 3)
%14 = add nsw i32 %13, %10
%15 = icmp eq i32 %13, 0
br i1 %15, label %16, label %4
16: ; preds = %12, %4
%17 = phi i32 [ %6, %4 ], [ %14, %12 ]
%18 = load i32, i32* @stdout
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %26
23: ; preds = %16
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%25 = load i32, i32* @EXIT_SUCCESS
br label %26
26: ; preds = %23, %21
%27 = phi i32 [ %19, %21 ], [ %25, %23 ]
ret i32 %27
}