#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 int pid_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ read(int, int *, int);
int vie_des_fils(int /*<<< orphan*/ *, int *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int write(int, int *, int);
int main(int argc, char *arg[]) {
  int pipefd[2];
  pid_t p;
  FILE *fd;
  int nb;
  if ((pipe(pipefd)) == -1) {
    perror("pipe");
    return EXIT_FAILURE;
  }
  if ((fd = fopen("nombrePremier", "w")) == NULL) {
    perror("open");
    return EXIT_FAILURE;
  }
  switch (p = fork()) {
  case (pid_t)-1:
    perror("fork");
    return EXIT_FAILURE;
  case (pid_t)0:
    close(pipefd[1]);
    if ((read(pipefd[0], &nb, sizeof(int))) != 0) {
      if (vie_des_fils(fd, pipefd, nb) == -1) {
        perror("vie des fils");
        return EXIT_FAILURE;
      }
    }
    break;
  default:
    close(pipefd[0]);
    for (nb = 2; nb < 20; nb++) {
      if ((write(pipefd[1], &nb, sizeof(int))) == -1) {
        perror("write");
        return EXIT_FAILURE;
      }
    }
    close(pipefd[1]);
    wait(NULL);
    break;
  }
  fclose(fd);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11e5 <main+0x45>
lea    0xe31(%rip),%rdi
call   1090 <perror@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1358 <main+0x1b8>
lea    0xe19(%rip),%rdi
lea    0xe20(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1223 <main+0x83>
lea    0xe08(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1358 <main+0x1b8>
xor    %eax,%eax
call   10b0 <fork@plt>
mov    %eax,-0x1c(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x30(%rbp)
sub    $0xffffffff,%eax
je     1250 <main+0xb0>
jmp    1240 <main+0xa0>
mov    -0x30(%rbp),%eax
test   %eax,%eax
je     126d <main+0xcd>
jmp    12cf <main+0x12f>
lea    0xdc3(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1358 <main+0x1b8>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
cmp    $0x0,%eax
je     12ca <main+0x12a>
mov    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   10c0 <vie_des_fils@plt>
cmp    $0xffffffff,%eax
jne    12c5 <main+0x125>
lea    0xd70(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1358 <main+0x1b8>
jmp    12ca <main+0x12a>
jmp    1343 <main+0x1a3>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
movl   $0x2,-0x2c(%rbp)
cmpl   $0x14,-0x2c(%rbp)
jge    1332 <main+0x192>
mov    -0x14(%rbp),%edi
lea    -0x2c(%rbp),%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    131f <main+0x17f>
lea    0xd23(%rip),%rdi
call   1090 <perror@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1358 <main+0x1b8>
jmp    1324 <main+0x184>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12de <main+0x13e>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    0x2c85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     1298 <main+0xf8>
lea    0xe43(%rip),%rdi
lea    0xe4a(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12a1 <main+0x101>
mov    %rax,%r14
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     1248 <main+0xa8>
cmp    $0xffffffff,%eax
je     12aa <main+0x10a>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
movl   $0x2,0x4(%rsp)
mov    $0x3,%ebp
lea    0x4(%rsp),%rbx
nopl   0x0(%rax)
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
je     12b3 <main+0x113>
mov    %ebp,0x4(%rsp)
add    $0x1,%ebp
cmp    $0x15,%ebp
jne    1210 <main+0x70>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10a0 <wait@plt>
jmp    127e <main+0xde>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1070 <read@plt>
test   %eax,%eax
je     127e <main+0xde>
mov    0x4(%rsp),%edx
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   10c0 <vie_des_fils@plt>
cmp    $0xffffffff,%eax
je     12bc <main+0x11c>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    0x2d4b(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd61(%rip),%rdi
jmp    12c3 <main+0x123>
lea    0xd6d(%rip),%rdi
jmp    12c3 <main+0x123>
lea    0xd69(%rip),%rdi
jmp    12c3 <main+0x123>
lea    0xd72(%rip),%rdi
jmp    12c3 <main+0x123>
lea    0xd5c(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d11(%rip),%rax
jmp    128d <main+0xed>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"nombrePremier\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [5 x i8] c"open\00"
@.str.4 = [5 x i8] c"fork\00"
@.str.5 = [13 x i8] c"vie des fils\00"
@.str.6 = [6 x i8] c"write\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
store i32 %15, i32* %3
br label %74
16: ; preds = %2
%17 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %17, i32** %8
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
store i32 %21, i32* %3
br label %74
22: ; preds = %16
%23 = call i32 (...) @fork()
store i32 %23, i32* %7
switch i32 %23, label %46 [
i32 -1, label %24
i32 0, label %27
]
24: ; preds = %22
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %3
br label %74
27: ; preds = %22
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%32 = load i32, i32* %31
%33 = call i32 @read(i32 %32, i32* %9, i32 4)
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %45
35: ; preds = %27
%36 = load i32*, i32** %8
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%38 = load i32, i32* %9
%39 = call i32 @vie_des_fils(i32* %36, i32* %37, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%43 = load i32, i32* @EXIT_FAILURE
store i32 %43, i32* %3
br label %74
44: ; preds = %35
br label %45
45: ; preds = %44, %27
br label %70
46: ; preds = %22
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%48 = load i32, i32* %47
%49 = call i32 @close(i32 %48)
store i32 2, i32* %9
br label %50
50: ; preds = %62, %46
%51 = load i32, i32* %9
%52 = icmp slt i32 %51, 20
br i1 %52, label %53, label %65
53: ; preds = %50
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%55 = load i32, i32* %54
%56 = call i32 @write(i32 %55, i32* %9, i32 4)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%60 = load i32, i32* @EXIT_FAILURE
store i32 %60, i32* %3
br label %74
61: ; preds = %53
br label %62
62: ; preds = %61
%63 = load i32, i32* %9
%64 = add nsw i32 %63, 1
store i32 %64, i32* %9
br label %50
65: ; preds = %50
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%67 = load i32, i32* %66
%68 = call i32 @close(i32 %67)
%69 = call i32 @wait(i32* null)
br label %70
70: ; preds = %65, %45
%71 = load i32*, i32** %8
%72 = call i32 @fclose(i32* %71)
%73 = load i32, i32* @EXIT_SUCCESS
store i32 %73, i32* %3
br label %74
74: ; preds = %70, %58, %41, %24, %19, %13
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [14 x i8] c"nombrePremier\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [5 x i8] c"open\00"
@.str.4 = [5 x i8] c"fork\00"
@.str.5 = [13 x i8] c"vie des fils\00"
@.str.6 = [6 x i8] c"write\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = bitcast [2 x i32]* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %54
12: ; preds = %2
%13 = call i32* @fopen(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %12
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %54
17: ; preds = %12
%18 = call i32 (...) @fork()
switch i32 %18, label %34 [
i32 -1, label %19
i32 0, label %21
]
19: ; preds = %17
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %54
21: ; preds = %17
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
%25 = load i32, i32* %7
%26 = call i32 @read(i32 %25, i32* %4, i32 4)
%27 = icmp eq i32 %26, 0
br i1 %27, label %52, label %28
28: ; preds = %21
%29 = load i32, i32* %4
%30 = call i32 @vie_des_fils(i32* %13, i32* %7, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %52
32: ; preds = %28
%33 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
br label %54
34: ; preds = %17
%35 = load i32, i32* %7
%36 = call i32 @close(i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
store i32 2, i32* %4
br label %40
38: ; preds = %40
store i32 %45, i32* %4
%39 = icmp eq i32 %45, 20
br i1 %39, label %48, label %40
40: ; preds = %34, %38
%41 = phi i32 [ 2, %34 ], [ %45, %38 ]
%42 = load i32, i32* %37
%43 = call i32 @write(i32 %42, i32* %4, i32 4)
%44 = icmp eq i32 %43, -1
%45 = add nuw nsw i32 %41, 1
br i1 %44, label %46, label %38
46: ; preds = %40
%47 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %54
48: ; preds = %38
%49 = load i32, i32* %37
%50 = call i32 @close(i32 %49)
%51 = call i32 @wait(i32* null)
br label %52
52: ; preds = %21, %28, %48
%53 = call i32 @fclose(i32* %13)
br label %54
54: ; preds = %52, %46, %32, %19, %15, %10
%55 = phi i32* [ @EXIT_FAILURE, %10 ], [ @EXIT_FAILURE, %15 ], [ @EXIT_FAILURE, %46 ], [ @EXIT_SUCCESS, %52 ], [ @EXIT_FAILURE, %32 ], [ @EXIT_FAILURE, %19 ]
%56 = load i32, i32* %55
ret i32 %56
}