#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 O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_TRUNC;
int O_WRONLY;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ execCommandeExterne(char **);
int /*<<< orphan*/ execCommandeInterne(char **, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int nbElementsCommande(char **);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ rechercheCaractereEntreeSortie(char **, int *, int *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ testCommandeInterne(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
void modifEntreeSortie(char *commande[], char *arge[]) {
  int redirectEntree = 0;
  int redirectSortie = 0;
  int descripteurFicEntree, descripteurFicSortie;
  char *commandeAExecuter[10];
  rechercheCaractereEntreeSortie(commande, &redirectEntree, &redirectSortie);
  switch (fork()) {
  case -1:
    printf("Erreur fork\n");
    break;
  case 0:
    if (redirectEntree && redirectSortie) {
      if ((descripteurFicEntree =
               open(commande[redirectEntree + 1], O_RDONLY)) == -1) {
        printf("Le fichier %s n'existe pas\n", commande[redirectEntree + 1]);
        exit(0);
      }
      if ((descripteurFicSortie =
               open(commande[redirectSortie + 1], O_WRONLY | O_TRUNC)) == -1)
        descripteurFicSortie =
            open(commande[redirectSortie + 1], O_CREAT | O_WRONLY,
                 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
      close(0);
      dup(descripteurFicEntree);
      close(1);
      dup(descripteurFicSortie);
      int i;
      int positionFinalCar;
      if (redirectEntree < redirectSortie)
        positionFinalCar = redirectEntree;
      else
        positionFinalCar = redirectSortie;
      for (i = 0; i < positionFinalCar; i++)
        commandeAExecuter[i] = commande[i];
      commandeAExecuter[positionFinalCar] = (char *)NULL;
    } else if (redirectEntree && !redirectSortie) {
      if ((descripteurFicEntree =
               open(commande[redirectEntree + 1], O_RDONLY)) == -1)
        printf("Le fichier %s n'existe pas\n", commande[redirectEntree + 1]);
      else {
        close(0);
        dup(descripteurFicEntree);
        int i = 0;
        while (i < nbElementsCommande(commande) &&
               (strcmp(commande[i], "<") != 0)) {
          commandeAExecuter[i] = commande[i];
          i++;
        }
        commandeAExecuter[i] = (char *)NULL;
      }
    } else if (!redirectEntree && redirectSortie) {
      if ((descripteurFicSortie =
               open(commande[redirectSortie + 1], O_WRONLY | O_TRUNC)) == -1)
        descripteurFicSortie =
            open(commande[redirectSortie + 1], O_CREAT | O_WRONLY,
                 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
      close(1);
      dup(descripteurFicSortie);
      int i = 0;
      while (i < nbElementsCommande(commande) &&
             (strcmp(commande[i], ">") != 0)) {
        commandeAExecuter[i] = commande[i];
        i++;
      }
      commandeAExecuter[i] = (char *)NULL;
    }
    if (testCommandeInterne(commandeAExecuter[0]))
      execCommandeInterne(commandeAExecuter, arge);
    else
      execCommandeExterne(commandeAExecuter);
    exit(0);
    break;
  default:
    wait(NULL);
  }
}


x86 assembly (clang, -O0):
<modifEntreeSortie>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   10b0 <rechercheCaractereEntreeSortie@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x84(%rbp)
sub    $0xffffffff,%eax
je     1232 <modifEntreeSortie+0x62>
jmp    121f <modifEntreeSortie+0x4f>
mov    -0x84(%rbp),%eax
test   %eax,%eax
je     1245 <modifEntreeSortie+0x75>
jmp    164d <modifEntreeSortie+0x47d>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1656 <modifEntreeSortie+0x486>
cmpl   $0x0,-0x14(%rbp)
je     13b9 <modifEntreeSortie+0x1e9>
cmpl   $0x0,-0x18(%rbp)
je     13b9 <modifEntreeSortie+0x1e9>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    12ac <modifEntreeSortie+0xdc>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xd6f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2cdc(%rip),%rax
mov    (%rax),%esi
mov    0x2d23(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    1333 <modifEntreeSortie+0x163>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2cfe(%rip),%rax
mov    (%rax),%esi
mov    0x2c9d(%rip),%rax
or     (%rax),%esi
mov    0x2ca4(%rip),%rax
mov    (%rax),%edx
mov    0x2cbb(%rip),%rax
or     (%rax),%edx
mov    0x2ca2(%rip),%rax
or     (%rax),%edx
mov    0x2c91(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x20(%rbp)
xor    %edi,%edi
call   1090 <close@plt>
mov    -0x1c(%rbp),%edi
call   1080 <dup@plt>
mov    $0x1,%edi
call   1090 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <dup@plt>
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    136b <modifEntreeSortie+0x19b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x78(%rbp)
jmp    1371 <modifEntreeSortie+0x1a1>
mov    -0x18(%rbp),%eax
mov    %eax,-0x78(%rbp)
movl   $0x0,-0x74(%rbp)
mov    -0x74(%rbp),%eax
cmp    -0x78(%rbp),%eax
jge    13a7 <modifEntreeSortie+0x1d7>
mov    -0x8(%rbp),%rax
movslq -0x74(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
movslq -0x74(%rbp),%rax
mov    %rcx,-0x70(%rbp,%rax,8)
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    1378 <modifEntreeSortie+0x1a8>
movslq -0x78(%rbp),%rax
movq   $0x0,-0x70(%rbp,%rax,8)
jmp    1619 <modifEntreeSortie+0x449>
cmpl   $0x0,-0x14(%rbp)
je     14ca <modifEntreeSortie+0x2fa>
cmpl   $0x0,-0x18(%rbp)
jne    14ca <modifEntreeSortie+0x2fa>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2bf3(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    141e <modifEntreeSortie+0x24e>
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xbfb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    14c5 <modifEntreeSortie+0x2f5>
xor    %edi,%edi
call   1090 <close@plt>
mov    -0x1c(%rbp),%edi
call   1080 <dup@plt>
movl   $0x0,-0x7c(%rbp)
mov    -0x7c(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <nbElementsCommande@plt>
mov    -0x8c(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x85(%rbp)
jge    1482 <modifEntreeSortie+0x2b2>
mov    -0x8(%rbp),%rax
movslq -0x7c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xbb8(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
mov    %al,-0x85(%rbp)
mov    -0x85(%rbp),%al
test   $0x1,%al
jne    1495 <modifEntreeSortie+0x2c5>
jmp    14b8 <modifEntreeSortie+0x2e8>
mov    -0x8(%rbp),%rax
movslq -0x7c(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
movslq -0x7c(%rbp),%rax
mov    %rcx,-0x70(%rbp,%rax,8)
mov    -0x7c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x7c(%rbp)
jmp    1434 <modifEntreeSortie+0x264>
movslq -0x7c(%rbp),%rax
movq   $0x0,-0x70(%rbp,%rax,8)
jmp    1614 <modifEntreeSortie+0x444>
cmpl   $0x0,-0x14(%rbp)
jne    160f <modifEntreeSortie+0x43f>
cmpl   $0x0,-0x18(%rbp)
je     160f <modifEntreeSortie+0x43f>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2aaa(%rip),%rax
mov    (%rax),%esi
mov    0x2af1(%rip),%rax
or     (%rax),%esi
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    1565 <modifEntreeSortie+0x395>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2acc(%rip),%rax
mov    (%rax),%esi
mov    0x2a6b(%rip),%rax
or     (%rax),%esi
mov    0x2a72(%rip),%rax
mov    (%rax),%edx
mov    0x2a89(%rip),%rax
or     (%rax),%edx
mov    0x2a70(%rip),%rax
or     (%rax),%edx
mov    0x2a5f(%rip),%rax
or     (%rax),%edx
mov    $0x0,%al
call   10c0 <open@plt>
mov    %eax,-0x20(%rbp)
mov    $0x1,%edi
call   1090 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <dup@plt>
movl   $0x0,-0x80(%rbp)
mov    -0x80(%rbp),%eax
mov    %eax,-0x94(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <nbElementsCommande@plt>
mov    -0x94(%rbp),%ecx
mov    %eax,%edx
xor    %eax,%eax
cmp    %edx,%ecx
mov    %al,-0x8d(%rbp)
jge    15cc <modifEntreeSortie+0x3fc>
mov    -0x8(%rbp),%rax
movslq -0x80(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xa70(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
setne  %al
mov    %al,-0x8d(%rbp)
mov    -0x8d(%rbp),%al
test   $0x1,%al
jne    15df <modifEntreeSortie+0x40f>
jmp    1602 <modifEntreeSortie+0x432>
mov    -0x8(%rbp),%rax
movslq -0x80(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
movslq -0x80(%rbp),%rax
mov    %rcx,-0x70(%rbp,%rax,8)
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    157e <modifEntreeSortie+0x3ae>
movslq -0x80(%rbp),%rax
movq   $0x0,-0x70(%rbp,%rax,8)
jmp    1614 <modifEntreeSortie+0x444>
jmp    1619 <modifEntreeSortie+0x449>
mov    -0x70(%rbp),%rdi
call   1040 <testCommandeInterne@plt>
cmp    $0x0,%eax
je     163d <modifEntreeSortie+0x46d>
lea    -0x70(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <execCommandeInterne@plt>
jmp    1646 <modifEntreeSortie+0x476>
lea    -0x70(%rbp),%rdi
call   1060 <execCommandeExterne@plt>
xor    %edi,%edi
call   10d0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <wait@plt>
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<modifEntreeSortie>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0xc(%rsp),%rsi
lea    0x8(%rsp),%rdx
call   10d0 <rechercheCaractereEntreeSortie@plt>
xor    %eax,%eax
call   1110 <fork@plt>
cmp    $0xffffffff,%eax
je     123a <modifEntreeSortie+0x4a>
test   %eax,%eax
je     1253 <modifEntreeSortie+0x63>
xor    %edi,%edi
call   1100 <wait@plt>
jmp    1246 <modifEntreeSortie+0x56>
lea    0xddf(%rip),%rdi
call   1030 <puts@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
movslq 0xc(%rsp),%rcx
mov    0x8(%rsp),%eax
test   %rcx,%rcx
je     12a2 <modifEntreeSortie+0xb2>
test   %eax,%eax
je     12a2 <modifEntreeSortie+0xb2>
mov    0x8(%rbx,%rcx,8),%rdi
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
jne    13bf <modifEntreeSortie+0x1cf>
movslq 0xc(%rsp),%rax
mov    0x8(%rbx,%rax,8),%rsi
lea    0xd6c(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
test   %ecx,%ecx
je     12e5 <modifEntreeSortie+0xf5>
test   %eax,%eax
jne    12e5 <modifEntreeSortie+0xf5>
mov    0x8(%rbx,%rcx,8),%rdi
mov    0x2d22(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
jne    147b <modifEntreeSortie+0x28b>
movslq 0xc(%rsp),%rax
mov    0x8(%rbx,%rax,8),%rsi
lea    0xd27(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    14db <modifEntreeSortie+0x2eb>
test   %ecx,%ecx
jne    14db <modifEntreeSortie+0x2eb>
test   %eax,%eax
je     14db <modifEntreeSortie+0x2eb>
cltq
mov    0x8(%rbx,%rax,8),%rdi
mov    0x2c9d(%rip),%r15
mov    0x2ce6(%rip),%rax
mov    (%rax),%esi
or     (%r15),%esi
xor    %eax,%eax
call   10e0 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1360 <modifEntreeSortie+0x170>
mov    0x2cd4(%rip),%rax
mov    (%r15),%esi
or     (%rax),%esi
mov    0x2c80(%rip),%rax
mov    0x2c99(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
movslq 0x8(%rsp),%rax
mov    0x2c79(%rip),%rcx
or     (%rcx),%edx
mov    0x8(%rbx,%rax,8),%rdi
mov    0x2c63(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   10e0 <open@plt>
mov    %eax,%ebp
mov    $0x1,%edi
call   10a0 <close@plt>
mov    %ebp,%edi
call   1090 <dup@plt>
mov    %rbx,%rdi
call   1080 <nbElementsCommande@plt>
xor    %r12d,%r12d
test   %eax,%eax
jle    14cf <modifEntreeSortie+0x2df>
lea    0xc93(%rip),%r15
mov    (%rbx,%r12,8),%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     14cf <modifEntreeSortie+0x2df>
mov    %rbp,0x10(%rsp,%r12,8)
add    $0x1,%r12
mov    %rbx,%rdi
call   1080 <nbElementsCommande@plt>
cltq
cmp    %rax,%r12
jl     138b <modifEntreeSortie+0x19b>
jmp    14cf <modifEntreeSortie+0x2df>
mov    %eax,%r15d
movslq 0x8(%rsp),%rax
mov    0x8(%rbx,%rax,8),%rdi
mov    0x2bcd(%rip),%r12
mov    0x2c16(%rip),%rax
mov    (%rax),%esi
or     (%r12),%esi
xor    %eax,%eax
call   10e0 <open@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1432 <modifEntreeSortie+0x242>
mov    0x2c03(%rip),%rax
mov    (%r12),%esi
or     (%rax),%esi
mov    0x2bae(%rip),%rax
mov    0x2bc7(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
movslq 0x8(%rsp),%rax
mov    0x2ba7(%rip),%rcx
or     (%rcx),%edx
mov    0x8(%rbx,%rax,8),%rdi
mov    0x2b91(%rip),%rax
or     (%rax),%edx
xor    %eax,%eax
call   10e0 <open@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   10a0 <close@plt>
mov    %r15d,%edi
call   1090 <dup@plt>
mov    $0x1,%edi
call   10a0 <close@plt>
mov    %ebp,%edi
call   1090 <dup@plt>
mov    0xc(%rsp),%eax
mov    0x8(%rsp),%ebp
cmp    %ebp,%eax
cmovl  %eax,%ebp
test   %ebp,%ebp
jle    1476 <modifEntreeSortie+0x286>
mov    %ebp,%edx
shl    $0x3,%rdx
lea    0x10(%rsp),%rdi
mov    %rbx,%rsi
call   10c0 <memcpy@plt>
movslq %ebp,%rax
jmp    14d2 <modifEntreeSortie+0x2e2>
mov    %eax,%ebp
xor    %r12d,%r12d
xor    %edi,%edi
call   10a0 <close@plt>
mov    %ebp,%edi
call   1090 <dup@plt>
mov    %rbx,%rdi
call   1080 <nbElementsCommande@plt>
test   %eax,%eax
jle    14cf <modifEntreeSortie+0x2df>
xor    %r12d,%r12d
lea    0xb78(%rip),%r15
mov    (%rbx,%r12,8),%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
je     14cf <modifEntreeSortie+0x2df>
mov    %rbp,0x10(%rsp,%r12,8)
add    $0x1,%r12
mov    %rbx,%rdi
call   1080 <nbElementsCommande@plt>
cltq
cmp    %rax,%r12
jl     14a4 <modifEntreeSortie+0x2b4>
mov    %r12d,%eax
movq   $0x0,0x10(%rsp,%rax,8)
mov    0x10(%rsp),%rdi
call   1050 <testCommandeInterne@plt>
lea    0x10(%rsp),%rdi
test   %eax,%eax
jne    14fa <modifEntreeSortie+0x30a>
call   1070 <execCommandeExterne@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    %r14,%rsi
call   1040 <execCommandeInterne@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Erreur fork\0A\00"
@O_RDONLY = global i32 0
@.str.1 = [28 x i8] c"Le fichier %s n'existe pas\0A\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.2 = [2 x i8] c"<\00"
@.str.3 = [2 x i8] c">\00"
define void @modifEntreeSortie(i8** %0, i8** %1) {
%3 = alloca i8**
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [10 x i8*]
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8** %0, i8*** %3
store i8** %1, i8*** %4
store i32 0, i32* %5
store i32 0, i32* %6
%14 = load i8**, i8*** %3
%15 = call i32 @rechercheCaractereEntreeSortie(i8** %14, i32* %5, i32* %6)
%16 = call i32 (...) @fork()
switch i32 %16, label %254 [
i32 -1, label %17
i32 0, label %19
]
17: ; preds = %2
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %256
19: ; preds = %2
%20 = load i32, i32* %5
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %109
22: ; preds = %19
%23 = load i32, i32* %6
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %109
25: ; preds = %22
%26 = load i8**, i8*** %3
%27 = load i32, i32* %5
%28 = add nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %26, i64 %29
%31 = load i8*, i8** %30
%32 = load i32, i32* @O_RDONLY
%33 = call i32 (i8*, i32, ...) @open(i8* %31, i32 %32)
store i32 %33, i32* %7
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %44
35: ; preds = %25
%36 = load i8**, i8*** %3
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %36, i64 %39
%41 = load i8*, i8** %40
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %41)
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %25
%45 = load i8**, i8*** %3
%46 = load i32, i32* %6
%47 = add nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %45, i64 %48
%50 = load i8*, i8** %49
%51 = load i32, i32* @O_WRONLY
%52 = load i32, i32* @O_TRUNC
%53 = or i32 %51, %52
%54 = call i32 (i8*, i32, ...) @open(i8* %50, i32 %53)
store i32 %54, i32* %8
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %74
56: ; preds = %44
%57 = load i8**, i8*** %3
%58 = load i32, i32* %6
%59 = add nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i8*, i8** %57, i64 %60
%62 = load i8*, i8** %61
%63 = load i32, i32* @O_CREAT
%64 = load i32, i32* @O_WRONLY
%65 = or i32 %63, %64
%66 = load i32, i32* @S_IRUSR
%67 = load i32, i32* @S_IWUSR
%68 = or i32 %66, %67
%69 = load i32, i32* @S_IRGRP
%70 = or i32 %68, %69
%71 = load i32, i32* @S_IROTH
%72 = or i32 %70, %71
%73 = call i32 (i8*, i32, ...) @open(i8* %62, i32 %65, i32 %72)
store i32 %73, i32* %8
br label %74
74: ; preds = %56, %44
%75 = call i32 @close(i32 0)
%76 = load i32, i32* %7
%77 = call i32 @dup(i32 %76)
%78 = call i32 @close(i32 1)
%79 = load i32, i32* %8
%80 = call i32 @dup(i32 %79)
%81 = load i32, i32* %5
%82 = load i32, i32* %6
%83 = icmp slt i32 %81, %82
br i1 %83, label %84, label %86
84: ; preds = %74
%85 = load i32, i32* %5
store i32 %85, i32* %11
br label %88
86: ; preds = %74
%87 = load i32, i32* %6
store i32 %87, i32* %11
br label %88
88: ; preds = %86, %84
store i32 0, i32* %10
br label %89
89: ; preds = %102, %88
%90 = load i32, i32* %10
%91 = load i32, i32* %11
%92 = icmp slt i32 %90, %91
br i1 %92, label %93, label %105
93: ; preds = %89
%94 = load i8**, i8*** %3
%95 = load i32, i32* %10
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds i8*, i8** %94, i64 %96
%98 = load i8*, i8** %97
%99 = load i32, i32* %10
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 %100
store i8* %98, i8** %101
br label %102
102: ; preds = %93
%103 = load i32, i32* %10
%104 = add nsw i32 %103, 1
store i32 %104, i32* %10
br label %89
105: ; preds = %89
%106 = load i32, i32* %11
%107 = sext i32 %106 to i64
%108 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 %107
store i8* null, i8** %108
br label %240
109: ; preds = %22, %19
%110 = load i32, i32* %5
%111 = icmp ne i32 %110, 0
br i1 %111, label %112, label %168
112: ; preds = %109
%113 = load i32, i32* %6
%114 = icmp ne i32 %113, 0
br i1 %114, label %168, label %115
115: ; preds = %112
%116 = load i8**, i8*** %3
%117 = load i32, i32* %5
%118 = add nsw i32 %117, 1
%119 = sext i32 %118 to i64
%120 = getelementptr inbounds i8*, i8** %116, i64 %119
%121 = load i8*, i8** %120
%122 = load i32, i32* @O_RDONLY
%123 = call i32 (i8*, i32, ...) @open(i8* %121, i32 %122)
store i32 %123, i32* %7
%124 = icmp eq i32 %123, -1
br i1 %124, label %125, label %133
125: ; preds = %115
%126 = load i8**, i8*** %3
%127 = load i32, i32* %5
%128 = add nsw i32 %127, 1
%129 = sext i32 %128 to i64
%130 = getelementptr inbounds i8*, i8** %126, i64 %129
%131 = load i8*, i8** %130
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %131)
br label %167
133: ; preds = %115
%134 = call i32 @close(i32 0)
%135 = load i32, i32* %7
%136 = call i32 @dup(i32 %135)
store i32 0, i32* %12
br label %137
137: ; preds = %152, %133
%138 = load i32, i32* %12
%139 = load i8**, i8*** %3
%140 = call i32 @nbElementsCommande(i8** %139)
%141 = icmp slt i32 %138, %140
br i1 %141, label %142, label %150
142: ; preds = %137
%143 = load i8**, i8*** %3
%144 = load i32, i32* %12
%145 = sext i32 %144 to i64
%146 = getelementptr inbounds i8*, i8** %143, i64 %145
%147 = load i8*, i8** %146
%148 = call i32 @strcmp(i8* %147, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%149 = icmp ne i32 %148, 0
br label %150
150: ; preds = %142, %137
%151 = phi i1 [ false, %137 ], [ %149, %142 ]
br i1 %151, label %152, label %163
152: ; preds = %150
%153 = load i8**, i8*** %3
%154 = load i32, i32* %12
%155 = sext i32 %154 to i64
%156 = getelementptr inbounds i8*, i8** %153, i64 %155
%157 = load i8*, i8** %156
%158 = load i32, i32* %12
%159 = sext i32 %158 to i64
%160 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 %159
store i8* %157, i8** %160
%161 = load i32, i32* %12
%162 = add nsw i32 %161, 1
store i32 %162, i32* %12
br label %137
163: ; preds = %150
%164 = load i32, i32* %12
%165 = sext i32 %164 to i64
%166 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 %165
store i8* null, i8** %166
br label %167
167: ; preds = %163, %125
br label %239
168: ; preds = %112, %109
%169 = load i32, i32* %5
%170 = icmp ne i32 %169, 0
br i1 %170, label %238, label %171
171: ; preds = %168
%172 = load i32, i32* %6
%173 = icmp ne i32 %172, 0
br i1 %173, label %174, label %238
174: ; preds = %171
%175 = load i8**, i8*** %3
%176 = load i32, i32* %6
%177 = add nsw i32 %176, 1
%178 = sext i32 %177 to i64
%179 = getelementptr inbounds i8*, i8** %175, i64 %178
%180 = load i8*, i8** %179
%181 = load i32, i32* @O_WRONLY
%182 = load i32, i32* @O_TRUNC
%183 = or i32 %181, %182
%184 = call i32 (i8*, i32, ...) @open(i8* %180, i32 %183)
store i32 %184, i32* %8
%185 = icmp eq i32 %184, -1
br i1 %185, label %186, label %204
186: ; preds = %174
%187 = load i8**, i8*** %3
%188 = load i32, i32* %6
%189 = add nsw i32 %188, 1
%190 = sext i32 %189 to i64
%191 = getelementptr inbounds i8*, i8** %187, i64 %190
%192 = load i8*, i8** %191
%193 = load i32, i32* @O_CREAT
%194 = load i32, i32* @O_WRONLY
%195 = or i32 %193, %194
%196 = load i32, i32* @S_IRUSR
%197 = load i32, i32* @S_IWUSR
%198 = or i32 %196, %197
%199 = load i32, i32* @S_IRGRP
%200 = or i32 %198, %199
%201 = load i32, i32* @S_IROTH
%202 = or i32 %200, %201
%203 = call i32 (i8*, i32, ...) @open(i8* %192, i32 %195, i32 %202)
store i32 %203, i32* %8
br label %204
204: ; preds = %186, %174
%205 = call i32 @close(i32 1)
%206 = load i32, i32* %8
%207 = call i32 @dup(i32 %206)
store i32 0, i32* %13
br label %208
208: ; preds = %223, %204
%209 = load i32, i32* %13
%210 = load i8**, i8*** %3
%211 = call i32 @nbElementsCommande(i8** %210)
%212 = icmp slt i32 %209, %211
br i1 %212, label %213, label %221
213: ; preds = %208
%214 = load i8**, i8*** %3
%215 = load i32, i32* %13
%216 = sext i32 %215 to i64
%217 = getelementptr inbounds i8*, i8** %214, i64 %216
%218 = load i8*, i8** %217
%219 = call i32 @strcmp(i8* %218, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%220 = icmp ne i32 %219, 0
br label %221
221: ; preds = %213, %208
%222 = phi i1 [ false, %208 ], [ %220, %213 ]
br i1 %222, label %223, label %234
223: ; preds = %221
%224 = load i8**, i8*** %3
%225 = load i32, i32* %13
%226 = sext i32 %225 to i64
%227 = getelementptr inbounds i8*, i8** %224, i64 %226
%228 = load i8*, i8** %227
%229 = load i32, i32* %13
%230 = sext i32 %229 to i64
%231 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 %230
store i8* %228, i8** %231
%232 = load i32, i32* %13
%233 = add nsw i32 %232, 1
store i32 %233, i32* %13
br label %208
234: ; preds = %221
%235 = load i32, i32* %13
%236 = sext i32 %235 to i64
%237 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 %236
store i8* null, i8** %237
br label %238
238: ; preds = %234, %171, %168
br label %239
239: ; preds = %238, %167
br label %240
240: ; preds = %239, %105
%241 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 0
%242 = load i8*, i8** %241
%243 = call i32 @testCommandeInterne(i8* %242)
%244 = icmp ne i32 %243, 0
br i1 %244, label %245, label %249
245: ; preds = %240
%246 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 0
%247 = load i8**, i8*** %4
%248 = call i32 @execCommandeInterne(i8** %246, i8** %247)
br label %252
249: ; preds = %240
%250 = getelementptr inbounds [10 x i8*], [10 x i8*]* %9, i64 0, i64 0
%251 = call i32 @execCommandeExterne(i8** %250)
br label %252
252: ; preds = %249, %245
%253 = call i32 @exit(i32 0)
unreachable
254: ; preds = %2
%255 = call i32 @wait(i32* null)
br label %256
256: ; preds = %254, %17
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str.1 = [28 x i8] c"Le fichier %s n'existe pas\0A\00"
@O_WRONLY = global i32 0
@O_TRUNC = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.2 = [2 x i8] c"<\00"
@.str.3 = [2 x i8] c">\00"
@str = [12 x i8] c"Erreur fork\00"
define void @modifEntreeSortie(i8** %0, i8** %1) {
%3 = bitcast i8** %0 to i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x i8*]
%7 = bitcast [10 x i8*]* %6 to i8*
%8 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%9 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%10 = call i32 @rechercheCaractereEntreeSortie(i8** %0, i32* %4, i32* %5)
%11 = call i32 (...) @fork()
switch i32 %11, label %182 [
i32 -1, label %12
i32 0, label %14
]
12: ; preds = %2
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
br label %184
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 0
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %20, label %81
20: ; preds = %14
%21 = add nsw i32 %15, 1
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %0, i64 %22
%24 = load i8*, i8** %23
%25 = load i32, i32* @O_RDONLY
%26 = call i32 (i8*, i32, ...) @open(i8* %24, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %36
28: ; preds = %20
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8*, i8** %0, i64 %31
%33 = load i8*, i8** %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %20
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %0, i64 %39
%41 = load i8*, i8** %40
%42 = load i32, i32* @O_WRONLY
%43 = load i32, i32* @O_TRUNC
%44 = or i32 %43, %42
%45 = call i32 (i8*, i32, ...) @open(i8* %41, i32 %44)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %64
47: ; preds = %36
%48 = load i32, i32* %5
%49 = add nsw i32 %48, 1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds i8*, i8** %0, i64 %50
%52 = load i8*, i8** %51
%53 = load i32, i32* @O_CREAT
%54 = load i32, i32* @O_WRONLY
%55 = or i32 %54, %53
%56 = load i32, i32* @S_IRUSR
%57 = load i32, i32* @S_IWUSR
%58 = or i32 %57, %56
%59 = load i32, i32* @S_IRGRP
%60 = or i32 %58, %59
%61 = load i32, i32* @S_IROTH
%62 = or i32 %60, %61
%63 = call i32 (i8*, i32, ...) @open(i8* %52, i32 %55, i32 %62)
br label %64
64: ; preds = %47, %36
%65 = phi i32 [ %63, %47 ], [ %45, %36 ]
%66 = call i32 @close(i32 0)
%67 = call i32 @dup(i32 %26)
%68 = call i32 @close(i32 1)
%69 = call i32 @dup(i32 %65)
%70 = load i32, i32* %4
%71 = load i32, i32* %5
%72 = icmp slt i32 %70, %71
%73 = select i1 %72, i32 %70, i32 %71
%74 = icmp sgt i32 %73, 0
br i1 %74, label %75, label %78
75: ; preds = %64
%76 = zext i32 %73 to i64
%77 = shl nuw nsw i64 %76, 3
br label %78
78: ; preds = %75, %64
%79 = sext i32 %73 to i64
%80 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 %79
store i8* null, i8** %80
br label %171
81: ; preds = %14
%82 = icmp eq i32 %15, 0
%83 = select i1 %82, i1 true, i1 %18
br i1 %83, label %120, label %84
84: ; preds = %81
%85 = add nsw i32 %15, 1
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8*, i8** %0, i64 %86
%88 = load i8*, i8** %87
%89 = load i32, i32* @O_RDONLY
%90 = call i32 (i8*, i32, ...) @open(i8* %88, i32 %89)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %99
92: ; preds = %84
%93 = load i32, i32* %4
%94 = add nsw i32 %93, 1
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8*, i8** %0, i64 %95
%97 = load i8*, i8** %96
%98 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %97)
br label %171
99: ; preds = %84
%100 = call i32 @close(i32 0)
%101 = call i32 @dup(i32 %90)
%102 = call i32 @nbElementsCommande(i8** %0)
%103 = icmp sgt i32 %102, 0
br i1 %103, label %104, label %116
104: ; preds = %99, %110
%105 = phi i64 [ %112, %110 ], [ 0, %99 ]
%106 = getelementptr inbounds i8*, i8** %0, i64 %105
%107 = load i8*, i8** %106
%108 = call i32 @strcmp(i8* dereferenceable(1) %107, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%109 = icmp eq i32 %108, 0
br i1 %109, label %116, label %110
110: ; preds = %104
%111 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 %105
store i8* %107, i8** %111
%112 = add nuw nsw i64 %105, 1
%113 = call i32 @nbElementsCommande(i8** %0)
%114 = sext i32 %113 to i64
%115 = icmp slt i64 %112, %114
br i1 %115, label %104, label %116
116: ; preds = %104, %110, %99
%117 = phi i64 [ 0, %99 ], [ %112, %110 ], [ %105, %104 ]
%118 = and i64 %117, 4294967295
%119 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 %118
store i8* null, i8** %119
br label %171
120: ; preds = %81
%121 = select i1 %82, i1 %18, i1 false
br i1 %121, label %122, label %171
122: ; preds = %120
%123 = add nsw i32 %17, 1
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i8*, i8** %0, i64 %124
%126 = load i8*, i8** %125
%127 = load i32, i32* @O_WRONLY
%128 = load i32, i32* @O_TRUNC
%129 = or i32 %128, %127
%130 = call i32 (i8*, i32, ...) @open(i8* %126, i32 %129)
%131 = icmp eq i32 %130, -1
br i1 %131, label %132, label %149
132: ; preds = %122
%133 = load i32, i32* %5
%134 = add nsw i32 %133, 1
%135 = sext i32 %134 to i64
%136 = getelementptr inbounds i8*, i8** %0, i64 %135
%137 = load i8*, i8** %136
%138 = load i32, i32* @O_CREAT
%139 = load i32, i32* @O_WRONLY
%140 = or i32 %139, %138
%141 = load i32, i32* @S_IRUSR
%142 = load i32, i32* @S_IWUSR
%143 = or i32 %142, %141
%144 = load i32, i32* @S_IRGRP
%145 = or i32 %143, %144
%146 = load i32, i32* @S_IROTH
%147 = or i32 %145, %146
%148 = call i32 (i8*, i32, ...) @open(i8* %137, i32 %140, i32 %147)
br label %149
149: ; preds = %132, %122
%150 = phi i32 [ %148, %132 ], [ %130, %122 ]
%151 = call i32 @close(i32 1)
%152 = call i32 @dup(i32 %150)
%153 = call i32 @nbElementsCommande(i8** %0)
%154 = icmp sgt i32 %153, 0
br i1 %154, label %155, label %167
155: ; preds = %149, %161
%156 = phi i64 [ %163, %161 ], [ 0, %149 ]
%157 = getelementptr inbounds i8*, i8** %0, i64 %156
%158 = load i8*, i8** %157
%159 = call i32 @strcmp(i8* dereferenceable(1) %158, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%160 = icmp eq i32 %159, 0
br i1 %160, label %167, label %161
161: ; preds = %155
%162 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 %156
store i8* %158, i8** %162
%163 = add nuw nsw i64 %156, 1
%164 = call i32 @nbElementsCommande(i8** %0)
%165 = sext i32 %164 to i64
%166 = icmp slt i64 %163, %165
br i1 %166, label %155, label %167
167: ; preds = %155, %161, %149
%168 = phi i64 [ 0, %149 ], [ %163, %161 ], [ %156, %155 ]
%169 = and i64 %168, 4294967295
%170 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 %169
store i8* null, i8** %170
br label %171
171: ; preds = %116, %92, %167, %120, %78
%172 = getelementptr inbounds [10 x i8*], [10 x i8*]* %6, i64 0, i64 0
%173 = load i8*, i8** %172
%174 = call i32 @testCommandeInterne(i8* %173)
%175 = icmp eq i32 %174, 0
br i1 %175, label %178, label %176
176: ; preds = %171
%177 = call i32 @execCommandeInterne(i8** %172, i8** %1)
br label %180
178: ; preds = %171
%179 = call i32 @execCommandeExterne(i8** %172)
br label %180
180: ; preds = %178, %176
%181 = call i32 @exit(i32 0)
unreachable
182: ; preds = %2
%183 = call i32 @wait(i32* null)
br label %184
184: ; preds = %182, %12
ret void
}