#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 ssize_t;
typedef int pid_t;
typedef int off_t;

/* Variables and functions */
int EXIT_SUCCESS;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int RAND_MAX;
int /*<<< orphan*/ SEEK_SET;
int atoi(char const *);
int close(int);
int dup(int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int fprintf(int /*<<< orphan*/, char *, ...);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ memset(void *, int /*<<< orphan*/, size_t);
int open(char *, int, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ rand();
int read(int, void *, size_t);
int sprintf(char *, char *, int);
int /*<<< orphan*/ stdout;
int waitpid(int, int *, int /*<<< orphan*/);
int write(int, void const *, size_t);
int main(int argc, char **argv) {
  pid_t fork_return = NULL;
  pid_t waitpid_return = NULL;
  int error = 0;
  int waitpid_status = 0;
  int fprintf_return = 0;
  int sprintf_return = 0;
  int nb_fork = 0;
  int close_return = 0;
  int file_to_read = 0;
  int file_to_write = 0;
  int user_nb_fork = 0;
  int valeur_aleatoire = 0;
  int somme = 0;
  ssize_t read_return = 0;
  ssize_t write_return = 0;
  char read_buffer[1 + 1] = "";
  char write_buffer[1] = "";
  off_t lseek_return = 0;
  if (argc != 3) {
    fprintf_return = fprintf(
        stdout,
        "Usage: %s <nb de processus fils> <fichier de communication> \n",
        argv[0]);
    if (fprintf_return < 0) {
      perror("Error fprintf");
      return fprintf_return;
    }
    return -1;
  }
  user_nb_fork = atoi(argv[1]);
  if (user_nb_fork == 0) {
    return -1;
  }
  file_to_write = open(argv[2], O_CREAT | O_RDWR | O_TRUNC, 00600);
  if (file_to_write == -1) {
    error = errno;
    perror("Error open");
    return error;
  }
  for (nb_fork = 0; nb_fork < user_nb_fork; nb_fork++) {
    fork_return = fork();
    if (fork_return == -1) {
      error = errno;
      perror("Error fork");
      if (nb_fork == 0)
        return -1;
      return error;
    } else if (fork_return == 0) {
      valeur_aleatoire = (int)(10 * (float)rand() / RAND_MAX);
      sprintf_return = sprintf(write_buffer, "%d", valeur_aleatoire);
      write_return = write(file_to_write, (const void *)write_buffer,
                           (size_t)sprintf_return);
      if (write_return == -1) {
        error = errno;
        perror("Error write");
        return error;
      }
      close_return = close(file_to_write);
      if (close_return == -1) {
        error = errno;
        perror("Error close");
        return error;
      }
      exit(0);
    }
  }
  for (nb_fork = 0; nb_fork < user_nb_fork; nb_fork++) {
    waitpid_return = waitpid(-1, &waitpid_status, 0);
    if (waitpid_return == -1) {
      error = errno;
      perror("Error wait");
      return error;
    }
  }
  file_to_read = dup(file_to_write);
  if (file_to_read == -1) {
    error = errno;
    perror("Error dup");
    return error;
  }
  close_return = close(file_to_write);
  if (close_return == -1) {
    error = errno;
    perror("Error close");
    return error;
  }
  lseek_return = lseek(file_to_read, 0, SEEK_SET);
  if (lseek_return == -1) {
    error = errno;
    perror("Error lseek");
    return error;
  }
  read_buffer[1 + 1] = '\0';
  while ((read_return = read(file_to_read,
                             (void *)memset((void *)read_buffer, 0, (size_t)1),
                             (size_t)1)) != 0) {
    if (read_return == -1) {
      error = errno;
      perror("Error read");
      return error;
    }
    valeur_aleatoire = atoi((const char *)read_buffer);
    somme += valeur_aleatoire;
  }
  close_return = close(file_to_read);
  if (close_return == -1) {
    error = errno;
    perror("Error close");
    return error;
  }
  fprintf_return = fprintf(stdout, "Somme: %d \n", somme);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x0,-0x48(%rbp)
movl   $0x0,-0x4c(%rbp)
lea    -0x4e(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1060 <memset@plt>
lea    -0x4f(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1060 <memset@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     12ee <main+0xfe>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd4d(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12e2 <main+0xf2>
lea    0xd70(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
movl   $0xffffffff,-0x4(%rbp)
jmp    16ad <main+0x4bd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0x0,-0x3c(%rbp)
jne    1314 <main+0x124>
movl   $0xffffffff,-0x4(%rbp)
jmp    16ad <main+0x4bd>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    0x2cd5(%rip),%rax
mov    (%rax),%esi
mov    0x2cac(%rip),%rax
or     (%rax),%esi
mov    0x2cbb(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   10b0 <open@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0xffffffff,-0x38(%rbp)
jne    1371 <main+0x181>
mov    0x2c6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xcef(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    14b6 <main+0x2c6>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    13d1 <main+0x1e1>
mov    0x2c21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xcb0(%rip),%rdi
call   10c0 <perror@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    13c6 <main+0x1d6>
movl   $0xffffffff,-0x4(%rbp)
jmp    16ad <main+0x4bd>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
cmpl   $0x0,-0x14(%rbp)
jne    149e <main+0x2ae>
mov    $0x0,%al
call   1110 <rand@plt>
cvtsi2ss %rax,%xmm1
movss  0xc11(%rip),%xmm0
mulss  %xmm1,%xmm0
mov    0x2bd6(%rip),%rax
cvtsi2ssl (%rax),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%eax
mov    %eax,-0x40(%rbp)
lea    -0x4f(%rbp),%rdi
mov    -0x40(%rbp),%edx
lea    0xc4f(%rip),%rsi
call   10e0 <sprintf@plt>
mov    %eax,-0x28(%rbp)
mov    -0x38(%rbp),%edi
lea    -0x4f(%rbp),%rsi
movslq -0x28(%rbp),%rdx
call   1030 <write@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0xffffffff,-0x4c(%rbp)
jne    145f <main+0x26f>
mov    0x2b7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xc1a(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
mov    -0x38(%rbp),%edi
call   1070 <close@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    1497 <main+0x2a7>
mov    0x2b45(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xbee(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    14a3 <main+0x2b3>
jmp    14a8 <main+0x2b8>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1378 <main+0x188>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x3c(%rbp),%eax
jge    151c <main+0x32c>
mov    $0xffffffff,%edi
lea    -0x20(%rbp),%rsi
xor    %edx,%edx
call   10a0 <waitpid@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1509 <main+0x319>
mov    0x2ad3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xb88(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
jmp    150e <main+0x31e>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    14bd <main+0x2cd>
mov    -0x38(%rbp),%edi
call   1040 <dup@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1554 <main+0x364>
mov    0x2a88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xb48(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
mov    -0x38(%rbp),%edi
call   1070 <close@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    158c <main+0x39c>
mov    0x2a50(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xaf9(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
mov    -0x34(%rbp),%edi
mov    0x2a22(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    15cf <main+0x3df>
mov    0x2a0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xad7(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
movb   $0x0,-0x4c(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x58(%rbp)
lea    -0x4e(%rbp),%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1060 <memset@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rsi
mov    $0x1,%edx
call   1080 <read@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
je     164c <main+0x45c>
cmpl   $0xffffffff,-0x48(%rbp)
jne    1632 <main+0x442>
mov    0x29aa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xa80(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
lea    -0x4e(%rbp),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
jmp    15d3 <main+0x3e3>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
mov    %eax,-0x30(%rbp)
cmpl   $0xffffffff,-0x30(%rbp)
jne    1684 <main+0x494>
mov    0x2958(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
lea    0xa01(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    16ad <main+0x4bd>
mov    0x2925(%rip),%rax
mov    (%rax),%edi
mov    -0x44(%rbp),%edx
lea    0xa16(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    %eax,-0x24(%rbp)
mov    0x2900(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
movl   $0x0,0x4(%rsp)
movw   $0x0,0x2(%rsp)
movb   $0x0,0x1(%rsp)
cmp    $0x3,%edi
jne    1348 <main+0x158>
mov    0x8(%rbx),%rdi
call   10d0 <atoi@plt>
test   %eax,%eax
je     13b2 <main+0x1c2>
mov    %eax,%ebp
mov    0x2dc7(%rip),%rax
mov    0x2da0(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x10(%rbx),%rdi
mov    0x2da9(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   10b0 <open@plt>
cmp    $0xffffffff,%eax
je     13c4 <main+0x1d4>
mov    %eax,%r15d
test   %ebp,%ebp
jle    12bd <main+0xcd>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1100 <fork@plt>
test   %eax,%eax
je     1420 <main+0x230>
cmp    $0xffffffff,%eax
je     1488 <main+0x298>
add    $0x1,%ebx
cmp    %ebx,%ebp
jne    1270 <main+0x80>
test   %ebp,%ebp
jle    12bd <main+0xcd>
lea    0x4(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    $0xffffffff,%edi
mov    %rbx,%rsi
xor    %edx,%edx
call   10a0 <waitpid@plt>
cmp    $0xffffffff,%eax
je     14a7 <main+0x2b7>
add    $0xffffffff,%ebp
jne    12a0 <main+0xb0>
mov    %r15d,%edi
call   1040 <dup@plt>
cmp    $0xffffffff,%eax
je     13db <main+0x1eb>
mov    %eax,%r14d
mov    %r15d,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
je     14ce <main+0x2de>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %r14d,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     13f2 <main+0x202>
movb   $0x0,0x4(%rsp)
lea    0x2(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1060 <memset@plt>
mov    $0x1,%edx
mov    %r14d,%edi
mov    %rax,%rsi
call   1080 <read@plt>
test   %eax,%eax
je     137d <main+0x18d>
cmp    $0xffffffff,%eax
je     1409 <main+0x219>
mov    %rbp,%rdi
call   10d0 <atoi@plt>
add    %eax,%ebx
jmp    1310 <main+0x120>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xca9(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%ebx
test   %eax,%eax
jns    13b7 <main+0x1c7>
mov    %eax,%ebp
lea    0xcce(%rip),%rdi
call   10c0 <perror@plt>
mov    %ebp,%ebx
jmp    13b7 <main+0x1c7>
mov    %r14d,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
je     14ce <main+0x2de>
mov    0x2c1b(%rip),%rax
mov    (%rax),%edi
lea    0xd0f(%rip),%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    0x2bfa(%rip),%rax
mov    (%rax),%ebx
jmp    13b7 <main+0x1c7>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bf5(%rip),%rax
mov    (%rax),%ebx
lea    0xc7c(%rip),%rdi
call   10c0 <perror@plt>
jmp    13b7 <main+0x1c7>
mov    0x2bde(%rip),%rax
mov    (%rax),%ebx
lea    0xca1(%rip),%rdi
call   10c0 <perror@plt>
jmp    13b7 <main+0x1c7>
mov    0x2bc7(%rip),%rax
mov    (%rax),%ebx
lea    0xc94(%rip),%rdi
call   10c0 <perror@plt>
jmp    13b7 <main+0x1c7>
mov    0x2bb0(%rip),%rax
mov    (%rax),%ebx
lea    0xc89(%rip),%rdi
call   10c0 <perror@plt>
jmp    13b7 <main+0x1c7>
xor    %eax,%eax
call   1110 <rand@plt>
cvtsi2ss %rax,%xmm0
mulss  0xbcc(%rip),%xmm0
mov    0x2b95(%rip),%rax
cvtsi2ssl (%rax),%xmm1
divss  %xmm1,%xmm0
cvttss2si %xmm0,%edx
lea    0xc18(%rip),%rsi
lea    0x1(%rsp),%rbx
mov    %rbx,%rdi
call   10e0 <sprintf@plt>
movslq %eax,%rdx
mov    %r15d,%edi
mov    %rbx,%rsi
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    14c1 <main+0x2d1>
mov    0x2b4b(%rip),%rax
mov    (%rax),%ebx
lea    0xbeb(%rip),%rdi
call   10c0 <perror@plt>
jmp    13b7 <main+0x1c7>
mov    0x2b31(%rip),%rax
cmp    $0x1,%ebx
sbb    %ebx,%ebx
or     (%rax),%ebx
lea    0xbbe(%rip),%rdi
call   10c0 <perror@plt>
jmp    13b7 <main+0x1c7>
mov    0x2b12(%rip),%rax
mov    (%rax),%ebx
lea    0xbca(%rip),%rdi
call   10c0 <perror@plt>
jmp    13b7 <main+0x1c7>
mov    %r15d,%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    14e8 <main+0x2f8>
mov    0x2aeb(%rip),%rax
mov    (%rax),%ebx
lea    0xb97(%rip),%rdi
call   10c0 <perror@plt>
jmp    13b7 <main+0x1c7>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [62 x i8] c"Usage: %s <nb de processus fils> <fichier de communication> \0A\00"
@.str.1 = [14 x i8] c"Error fprintf\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@errno = global i32 0
@.str.2 = [11 x i8] c"Error open\00"
@.str.3 = [11 x i8] c"Error fork\00"
@RAND_MAX = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [12 x i8] c"Error write\00"
@.str.6 = [12 x i8] c"Error close\00"
@.str.7 = [11 x i8] c"Error wait\00"
@.str.8 = [10 x i8] c"Error dup\00"
@SEEK_SET = global i32 0
@.str.9 = [12 x i8] c"Error lseek\00"
@.str.10 = [11 x i8] c"Error read\00"
@.str.11 = [12 x i8] c"Somme: %d \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca [2 x i8]
%22 = alloca [1 x i8]
%23 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
store i32 0, i32* %15
store i32 0, i32* %16
store i32 0, i32* %17
store i32 0, i32* %18
store i32 0, i32* %19
store i32 0, i32* %20
%24 = bitcast [2 x i8]* %21 to i8*
%25 = bitcast [1 x i8]* %22 to i8*
store i32 0, i32* %23
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 3
br i1 %27, label %28, label %40
28: ; preds = %2
%29 = load i32, i32* @stdout
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 0
%32 = load i8*, i8** %31
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* %32)
store i32 %33, i32* %10
%34 = load i32, i32* %10
%35 = icmp slt i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %28
%37 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* %10
store i32 %38, i32* %3
br label %203
39: ; preds = %28
store i32 -1, i32* %3
br label %203
40: ; preds = %2
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %16
%45 = load i32, i32* %16
%46 = icmp eq i32 %45, 0
br i1 %46, label %47, label %48
47: ; preds = %40
store i32 -1, i32* %3
br label %203
48: ; preds = %40
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 2
%51 = load i8*, i8** %50
%52 = load i32, i32* @O_CREAT
%53 = load i32, i32* @O_RDWR
%54 = or i32 %52, %53
%55 = load i32, i32* @O_TRUNC
%56 = or i32 %54, %55
%57 = call i32 @open(i8* %51, i32 %56, i32 384)
store i32 %57, i32* %15
%58 = load i32, i32* %15
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %48
%61 = load i32, i32* @errno
store i32 %61, i32* %8
%62 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%63 = load i32, i32* %8
store i32 %63, i32* %3
br label %203
64: ; preds = %48
store i32 0, i32* %12
br label %65
65: ; preds = %119, %64
%66 = load i32, i32* %12
%67 = load i32, i32* %16
%68 = icmp slt i32 %66, %67
br i1 %68, label %69, label %122
69: ; preds = %65
%70 = call i32 (...) @fork()
store i32 %70, i32* %6
%71 = load i32, i32* %6
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %81
73: ; preds = %69
%74 = load i32, i32* @errno
store i32 %74, i32* %8
%75 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%76 = load i32, i32* %12
%77 = icmp eq i32 %76, 0
br i1 %77, label %78, label %79
78: ; preds = %73
store i32 -1, i32* %3
br label %203
79: ; preds = %73
%80 = load i32, i32* %8
store i32 %80, i32* %3
br label %203
81: ; preds = %69
%82 = load i32, i32* %6
%83 = icmp eq i32 %82, 0
br i1 %83, label %84, label %117
84: ; preds = %81
%85 = call i64 (...) @rand()
%86 = sitofp i64 %85 to float
%87 = fmul float 1.000000e+01, %86
%88 = load i32, i32* @RAND_MAX
%89 = sitofp i32 %88 to float
%90 = fdiv float %87, %89
%91 = fptosi float %90 to i32
store i32 %91, i32* %17
%92 = getelementptr inbounds [1 x i8], [1 x i8]* %22, i64 0, i64 0
%93 = load i32, i32* %17
%94 = call i32 @sprintf(i8* %92, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %93)
store i32 %94, i32* %11
%95 = load i32, i32* %15
%96 = getelementptr inbounds [1 x i8], [1 x i8]* %22, i64 0, i64 0
%97 = load i32, i32* %11
%98 = sext i32 %97 to i64
%99 = call i32 @write(i32 %95, i8* %96, i64 %98)
store i32 %99, i32* %20
%100 = load i32, i32* %20
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %106
102: ; preds = %84
%103 = load i32, i32* @errno
store i32 %103, i32* %8
%104 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%105 = load i32, i32* %8
store i32 %105, i32* %3
br label %203
106: ; preds = %84
%107 = load i32, i32* %15
%108 = call i32 @close(i32 %107)
store i32 %108, i32* %13
%109 = load i32, i32* %13
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %115
111: ; preds = %106
%112 = load i32, i32* @errno
store i32 %112, i32* %8
%113 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%114 = load i32, i32* %8
store i32 %114, i32* %3
br label %203
115: ; preds = %106
%116 = call i32 @exit(i32 0)
unreachable
117: ; preds = %81
br label %118
118: ; preds = %117
br label %119
119: ; preds = %118
%120 = load i32, i32* %12
%121 = add nsw i32 %120, 1
store i32 %121, i32* %12
br label %65
122: ; preds = %65
store i32 0, i32* %12
br label %123
123: ; preds = %136, %122
%124 = load i32, i32* %12
%125 = load i32, i32* %16
%126 = icmp slt i32 %124, %125
br i1 %126, label %127, label %139
127: ; preds = %123
%128 = call i32 @waitpid(i32 -1, i32* %9, i32 0)
store i32 %128, i32* %7
%129 = load i32, i32* %7
%130 = icmp eq i32 %129, -1
br i1 %130, label %131, label %135
131: ; preds = %127
%132 = load i32, i32* @errno
store i32 %132, i32* %8
%133 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%134 = load i32, i32* %8
store i32 %134, i32* %3
br label %203
135: ; preds = %127
br label %136
136: ; preds = %135
%137 = load i32, i32* %12
%138 = add nsw i32 %137, 1
store i32 %138, i32* %12
br label %123
139: ; preds = %123
%140 = load i32, i32* %15
%141 = call i32 @dup(i32 %140)
store i32 %141, i32* %14
%142 = load i32, i32* %14
%143 = icmp eq i32 %142, -1
br i1 %143, label %144, label %148
144: ; preds = %139
%145 = load i32, i32* @errno
store i32 %145, i32* %8
%146 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
%147 = load i32, i32* %8
store i32 %147, i32* %3
br label %203
148: ; preds = %139
%149 = load i32, i32* %15
%150 = call i32 @close(i32 %149)
store i32 %150, i32* %13
%151 = load i32, i32* %13
%152 = icmp eq i32 %151, -1
br i1 %152, label %153, label %157
153: ; preds = %148
%154 = load i32, i32* @errno
store i32 %154, i32* %8
%155 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%156 = load i32, i32* %8
store i32 %156, i32* %3
br label %203
157: ; preds = %148
%158 = load i32, i32* %14
%159 = load i32, i32* @SEEK_SET
%160 = call i32 @lseek(i32 %158, i32 0, i32 %159)
store i32 %160, i32* %23
%161 = load i32, i32* %23
%162 = icmp eq i32 %161, -1
br i1 %162, label %163, label %167
163: ; preds = %157
%164 = load i32, i32* @errno
store i32 %164, i32* %8
%165 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
%166 = load i32, i32* %8
store i32 %166, i32* %3
br label %203
167: ; preds = %157
%168 = getelementptr inbounds [2 x i8], [2 x i8]* %21, i64 0, i64 2
store i8 0, i8* %168
br label %169
169: ; preds = %183, %167
%170 = load i32, i32* %14
%171 = getelementptr inbounds [2 x i8], [2 x i8]* %21, i64 0, i64 0
%172 = call i64 @memset(i8* %171, i32 0, i64 1)
%173 = inttoptr i64 %172 to i8*
%174 = call i32 @read(i32 %170, i8* %173, i64 1)
store i32 %174, i32* %19
%175 = icmp ne i32 %174, 0
br i1 %175, label %176, label %189
176: ; preds = %169
%177 = load i32, i32* %19
%178 = icmp eq i32 %177, -1
br i1 %178, label %179, label %183
179: ; preds = %176
%180 = load i32, i32* @errno
store i32 %180, i32* %8
%181 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
%182 = load i32, i32* %8
store i32 %182, i32* %3
br label %203
183: ; preds = %176
%184 = getelementptr inbounds [2 x i8], [2 x i8]* %21, i64 0, i64 0
%185 = call i32 @atoi(i8* %184)
store i32 %185, i32* %17
%186 = load i32, i32* %17
%187 = load i32, i32* %18
%188 = add nsw i32 %187, %186
store i32 %188, i32* %18
br label %169
189: ; preds = %169
%190 = load i32, i32* %14
%191 = call i32 @close(i32 %190)
store i32 %191, i32* %13
%192 = load i32, i32* %13
%193 = icmp eq i32 %192, -1
br i1 %193, label %194, label %198
194: ; preds = %189
%195 = load i32, i32* @errno
store i32 %195, i32* %8
%196 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
%197 = load i32, i32* %8
store i32 %197, i32* %3
br label %203
198: ; preds = %189
%199 = load i32, i32* @stdout
%200 = load i32, i32* %18
%201 = call i32 (i32, i8*, ...) @fprintf(i32 %199, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i32 %200)
store i32 %201, i32* %10
%202 = load i32, i32* @EXIT_SUCCESS
store i32 %202, i32* %3
br label %203
203: ; preds = %198, %194, %179, %163, %153, %144, %131, %111, %102, %79, %78, %60, %47, %39, %36
%204 = load i32, i32* %3
ret i32 %204
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [62 x i8] c"Usage: %s <nb de processus fils> <fichier de communication> \0A\00"
@.str.1 = [14 x i8] c"Error fprintf\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@O_TRUNC = global i32 0
@errno = global i32 0
@.str.2 = [11 x i8] c"Error open\00"
@.str.3 = [11 x i8] c"Error fork\00"
@RAND_MAX = global i32 0
@.str.4 = [3 x i8] c"%d\00"
@.str.5 = [12 x i8] c"Error write\00"
@.str.6 = [12 x i8] c"Error close\00"
@.str.7 = [11 x i8] c"Error wait\00"
@.str.8 = [10 x i8] c"Error dup\00"
@SEEK_SET = global i32 0
@.str.9 = [12 x i8] c"Error lseek\00"
@.str.10 = [11 x i8] c"Error read\00"
@.str.11 = [12 x i8] c"Somme: %d \0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca i16
%5 = alloca [1 x i8]
%6 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%7 = bitcast i16* %4 to i8*
store i16 0, i16* %4
%8 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
store i8 0, i8* %8
%9 = icmp eq i32 %0, 3
br i1 %9, label %17, label %10
10: ; preds = %2
%11 = load i32, i32* @stdout
%12 = load i8*, i8** %1
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %125
15: ; preds = %10
%16 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %125
17: ; preds = %2
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = icmp eq i32 %20, 0
br i1 %21, label %125, label %22
22: ; preds = %17
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_CREAT
%26 = load i32, i32* @O_RDWR
%27 = or i32 %26, %25
%28 = load i32, i32* @O_TRUNC
%29 = or i32 %27, %28
%30 = tail call i32 @open(i8* %24, i32 %29, i32 384)
%31 = icmp eq i32 %30, -1
br i1 %31, label %34, label %32
32: ; preds = %22
%33 = icmp sgt i32 %20, 0
br i1 %33, label %38, label %82
34: ; preds = %22
%35 = load i32, i32* @errno
%36 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
br label %125
37: ; preds = %69
br i1 %33, label %74, label %82
38: ; preds = %32, %69
%39 = phi i32 [ %70, %69 ], [ 0, %32 ]
%40 = tail call i32 (...) @fork()
switch i32 %40, label %69 [
i32 -1, label %41
i32 0, label %46
]
41: ; preds = %38
%42 = load i32, i32* @errno
%43 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i32 %39, 0
%45 = select i1 %44, i32 -1, i32 %42
br label %125
46: ; preds = %38
%47 = tail call i64 (...) @rand()
%48 = sitofp i64 %47 to float
%49 = fmul float %48, 1.000000e+01
%50 = load i32, i32* @RAND_MAX
%51 = sitofp i32 %50 to float
%52 = fdiv float %49, %51
%53 = fptosi float %52 to i32
%54 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 %53)
%55 = sext i32 %54 to i64
%56 = call i32 @write(i32 %30, i8* %8, i64 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %46
%59 = load i32, i32* @errno
%60 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %125
61: ; preds = %46
%62 = tail call i32 @close(i32 %30)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = load i32, i32* @errno
%66 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %125
67: ; preds = %61
%68 = tail call i32 @exit(i32 0)
unreachable
69: ; preds = %38
%70 = add nuw nsw i32 %39, 1
%71 = icmp eq i32 %70, %20
br i1 %71, label %37, label %38
72: ; preds = %74
%73 = icmp eq i32 %78, %20
br i1 %73, label %82, label %74
74: ; preds = %37, %72
%75 = phi i32 [ %78, %72 ], [ 0, %37 ]
%76 = call i32 @waitpid(i32 -1, i32* %3, i32 0)
%77 = icmp eq i32 %76, -1
%78 = add nuw nsw i32 %75, 1
br i1 %77, label %79, label %72
79: ; preds = %74
%80 = load i32, i32* @errno
%81 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %125
82: ; preds = %72, %32, %37
%83 = call i32 @dup(i32 %30)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %88
85: ; preds = %82
%86 = load i32, i32* @errno
%87 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0))
br label %125
88: ; preds = %82
%89 = call i32 @close(i32 %30)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %94
91: ; preds = %88
%92 = load i32, i32* @errno
%93 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %125
94: ; preds = %88
%95 = load i32, i32* @SEEK_SET
%96 = call i32 @lseek(i32 %83, i32 0, i32 %95)
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %101
98: ; preds = %94
%99 = load i32, i32* @errno
%100 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
br label %125
101: ; preds = %94
%102 = getelementptr inbounds i16, i16* %4, i64 1
%103 = bitcast i16* %102 to i8*
store i8 0, i8* %103
br label %104
104: ; preds = %112, %101
%105 = phi i32 [ 0, %101 ], [ %114, %112 ]
%106 = call i64 @memset(i8* %7, i32 0, i64 1)
%107 = inttoptr i64 %106 to i8*
%108 = call i32 @read(i32 %83, i8* %107, i64 1)
switch i32 %108, label %112 [
i32 0, label %115
i32 -1, label %109
]
109: ; preds = %104
%110 = load i32, i32* @errno
%111 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0))
br label %125
112: ; preds = %104
%113 = call i32 @atoi(i8* %7)
%114 = add nsw i32 %113, %105
br label %104
115: ; preds = %104
%116 = call i32 @close(i32 %83)
%117 = icmp eq i32 %116, -1
br i1 %117, label %118, label %121
118: ; preds = %115
%119 = load i32, i32* @errno
%120 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0))
br label %125
121: ; preds = %115
%122 = load i32, i32* @stdout
%123 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0), i32 %105)
%124 = load i32, i32* @EXIT_SUCCESS
br label %125
125: ; preds = %41, %17, %10, %121, %118, %109, %98, %91, %85, %79, %64, %58, %34, %15
%126 = phi i32 [ %13, %15 ], [ %35, %34 ], [ %59, %58 ], [ %65, %64 ], [ %80, %79 ], [ %86, %85 ], [ %92, %91 ], [ %99, %98 ], [ %110, %109 ], [ %119, %118 ], [ %124, %121 ], [ -1, %10 ], [ -1, %17 ], [ %45, %41 ]
ret i32 %126
}