#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*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int nbElementsCommande(char **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
void execCommandeExterne(char *commande[]) {
  char *commande_new[10];
  int i;
  for (i = 0; i <= nbElementsCommande(commande) - 2; i++)
    commande_new[i] = commande[i];
  int pid = fork();
  switch (pid) {
  case -1:
    perror("Erreur fork");
    exit(-1);
    break;
  case 0:
    if (commande[nbElementsCommande(commande) - 1] != NULL &&
        commande[nbElementsCommande(commande) - 1][0] == '&')
      execvp(commande_new[0], commande_new);
    else
      execvp(commande[0], commande);
    exit(-1);
    break;
  default:
    if (commande[nbElementsCommande(commande) - 1] != NULL &&
        commande[nbElementsCommande(commande) - 1][0] != '&')
      waitpid(pid, NULL, 0);
  }
}


x86 assembly (clang, -O0):
<execCommandeExterne>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <nbElementsCommande@plt>
mov    %eax,%ecx
mov    -0x6c(%rbp),%eax
sub    $0x2,%ecx
cmp    %ecx,%eax
jg     11b8 <execCommandeExterne+0x58>
mov    -0x8(%rbp),%rax
movslq -0x64(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
movslq -0x64(%rbp),%rax
mov    %rcx,-0x60(%rbp,%rax,8)
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1176 <execCommandeExterne+0x16>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
mov    %eax,-0x70(%rbp)
sub    $0xffffffff,%eax
je     11e6 <execCommandeExterne+0x86>
jmp    11d6 <execCommandeExterne+0x76>
mov    -0x70(%rbp),%eax
test   %eax,%eax
je     11fc <execCommandeExterne+0x9c>
jmp    127d <execCommandeExterne+0x11d>
lea    0xe13(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <nbElementsCommande@plt>
mov    %eax,%ecx
mov    -0x78(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     1263 <execCommandeExterne+0x103>
mov    -0x8(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <nbElementsCommande@plt>
mov    %eax,%ecx
mov    -0x80(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
jne    1263 <execCommandeExterne+0x103>
mov    -0x60(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1060 <execvp@plt>
jmp    1273 <execCommandeExterne+0x113>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1060 <execvp@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <nbElementsCommande@plt>
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     12ec <execCommandeExterne+0x18c>
mov    -0x8(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <nbElementsCommande@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x26,%eax
je     12ec <execCommandeExterne+0x18c>
mov    -0x68(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <waitpid@plt>
jmp    12f1 <execCommandeExterne+0x191>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execCommandeExterne>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
mov    %rdi,%rbx
call   1030 <nbElementsCommande@plt>
cmp    $0x2,%eax
jl     11a0 <execCommandeExterne+0x40>
mov    $0xffffffffffffffff,%rbp
nopw   0x0(%rax,%rax,1)
mov    0x8(%rbx,%rbp,8),%rax
mov    %rax,0x8(%rsp,%rbp,8)
mov    %rbx,%rdi
call   1030 <nbElementsCommande@plt>
add    $0xfffffffe,%eax
cltq
add    $0x1,%rbp
cmp    %rax,%rbp
jl     1180 <execCommandeExterne+0x20>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11f0 <execCommandeExterne+0x90>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     121f <execCommandeExterne+0xbf>
mov    %rbx,%rdi
call   1030 <nbElementsCommande@plt>
cltq
cmpq   $0x0,-0x8(%rbx,%rax,8)
je     11d8 <execCommandeExterne+0x78>
mov    %rbx,%rdi
call   1030 <nbElementsCommande@plt>
cltq
mov    -0x8(%rbx,%rax,8),%rax
cmpb   $0x26,(%rax)
jne    11df <execCommandeExterne+0x7f>
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
add    $0x58,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <waitpid@plt>
mov    %rbx,%rdi
call   1030 <nbElementsCommande@plt>
cltq
cmpq   $0x0,-0x8(%rbx,%rax,8)
je     1235 <execCommandeExterne+0xd5>
mov    %rbx,%rdi
call   1030 <nbElementsCommande@plt>
cltq
mov    -0x8(%rbx,%rax,8),%rax
cmpb   $0x26,(%rax)
jne    1235 <execCommandeExterne+0xd5>
mov    (%rsp),%rdi
mov    %rsp,%rsi
jmp    123b <execCommandeExterne+0xdb>
lea    0xdda(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1060 <execvp@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"Erreur fork\00"
define void @execCommandeExterne(i8** %0) {
%2 = alloca i8**
%3 = alloca [10 x i8*]
%4 = alloca i32
%5 = alloca i32
store i8** %0, i8*** %2
store i32 0, i32* %4
br label %6
6: ; preds = %21, %1
%7 = load i32, i32* %4
%8 = load i8**, i8*** %2
%9 = call i32 @nbElementsCommande(i8** %8)
%10 = sub nsw i32 %9, 2
%11 = icmp sle i32 %7, %10
br i1 %11, label %12, label %24
12: ; preds = %6
%13 = load i8**, i8*** %2
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = load i32, i32* %4
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 %19
store i8* %17, i8** %20
br label %21
21: ; preds = %12
%22 = load i32, i32* %4
%23 = add nsw i32 %22, 1
store i32 %23, i32* %4
br label %6
24: ; preds = %6
%25 = call i32 (...) @fork()
store i32 %25, i32* %5
%26 = load i32, i32* %5
switch i32 %26, label %64 [
i32 -1, label %27
i32 0, label %30
]
27: ; preds = %24
%28 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 -1)
unreachable
30: ; preds = %24
%31 = load i8**, i8*** %2
%32 = load i8**, i8*** %2
%33 = call i32 @nbElementsCommande(i8** %32)
%34 = sub nsw i32 %33, 1
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %31, i64 %35
%37 = load i8*, i8** %36
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %56
39: ; preds = %30
%40 = load i8**, i8*** %2
%41 = load i8**, i8*** %2
%42 = call i32 @nbElementsCommande(i8** %41)
%43 = sub nsw i32 %42, 1
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i8*, i8** %40, i64 %44
%46 = load i8*, i8** %45
%47 = getelementptr inbounds i8, i8* %46, i64 0
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 38
br i1 %50, label %51, label %56
51: ; preds = %39
%52 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 0
%53 = load i8*, i8** %52
%54 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 0
%55 = call i32 @execvp(i8* %53, i8** %54)
br label %62
56: ; preds = %39, %30
%57 = load i8**, i8*** %2
%58 = getelementptr inbounds i8*, i8** %57, i64 0
%59 = load i8*, i8** %58
%60 = load i8**, i8*** %2
%61 = call i32 @execvp(i8* %59, i8** %60)
br label %62
62: ; preds = %56, %51
%63 = call i32 @exit(i32 -1)
unreachable
64: ; preds = %24
%65 = load i8**, i8*** %2
%66 = load i8**, i8*** %2
%67 = call i32 @nbElementsCommande(i8** %66)
%68 = sub nsw i32 %67, 1
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %65, i64 %69
%71 = load i8*, i8** %70
%72 = icmp ne i8* %71, null
br i1 %72, label %73, label %88
73: ; preds = %64
%74 = load i8**, i8*** %2
%75 = load i8**, i8*** %2
%76 = call i32 @nbElementsCommande(i8** %75)
%77 = sub nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds i8*, i8** %74, i64 %78
%80 = load i8*, i8** %79
%81 = getelementptr inbounds i8, i8* %80, i64 0
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = icmp ne i32 %83, 38
br i1 %84, label %85, label %88
85: ; preds = %73
%86 = load i32, i32* %5
%87 = call i32 @waitpid(i32 %86, i32* null, i32 0)
br label %88
88: ; preds = %85, %73, %64
br label %89
89: ; preds = %88
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"Erreur fork\00"
define void @execCommandeExterne(i8** %0) {
%2 = alloca [10 x i8*]
%3 = bitcast [10 x i8*]* %2 to i8*
%4 = tail call i32 @nbElementsCommande(i8** %0)
%5 = icmp slt i32 %4, 2
br i1 %5, label %16, label %6
6: ; preds = %1, %6
%7 = phi i64 [ %11, %6 ], [ 0, %1 ]
%8 = getelementptr inbounds i8*, i8** %0, i64 %7
%9 = load i8*, i8** %8
%10 = getelementptr inbounds [10 x i8*], [10 x i8*]* %2, i64 0, i64 %7
store i8* %9, i8** %10
%11 = add nuw nsw i64 %7, 1
%12 = tail call i32 @nbElementsCommande(i8** %0)
%13 = add nsw i32 %12, -2
%14 = sext i32 %13 to i64
%15 = icmp slt i64 %7, %14
br i1 %15, label %6, label %16
16: ; preds = %6, %1
%17 = tail call i32 (...) @fork()
switch i32 %17, label %45 [
i32 -1, label %18
i32 0, label %21
]
18: ; preds = %16
%19 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %16
%22 = tail call i32 @nbElementsCommande(i8** %0)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %0, i64 %24
%26 = load i8*, i8** %25
%27 = icmp eq i8* %26, null
br i1 %27, label %40, label %28
28: ; preds = %21
%29 = tail call i32 @nbElementsCommande(i8** %0)
%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 = load i8, i8* %33
%35 = icmp eq i8 %34, 38
br i1 %35, label %36, label %40
36: ; preds = %28
%37 = getelementptr inbounds [10 x i8*], [10 x i8*]* %2, i64 0, i64 0
%38 = load i8*, i8** %37
%39 = call i32 @execvp(i8* %38, i8** %37)
br label %43
40: ; preds = %28, %21
%41 = load i8*, i8** %0
%42 = tail call i32 @execvp(i8* %41, i8** %0)
br label %43
43: ; preds = %40, %36
%44 = call i32 @exit(i32 -1)
unreachable
45: ; preds = %16
%46 = tail call i32 @nbElementsCommande(i8** %0)
%47 = add nsw i32 %46, -1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %0, i64 %48
%50 = load i8*, i8** %49
%51 = icmp eq i8* %50, null
br i1 %51, label %62, label %52
52: ; preds = %45
%53 = tail call i32 @nbElementsCommande(i8** %0)
%54 = add nsw i32 %53, -1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %0, i64 %55
%57 = load i8*, i8** %56
%58 = load i8, i8* %57
%59 = icmp eq i8 %58, 38
br i1 %59, label %62, label %60
60: ; preds = %52
%61 = tail call i32 @waitpid(i32 %17, i32* null, i32 0)
br label %62
62: ; preds = %45, %52, %60
ret void
}