#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*/ execCommandeExterne(char **);
int /*<<< orphan*/ execCommandeInterne(char **, char **);
int /*<<< orphan*/ executeCommandeSequentielle(char **, char **);
int /*<<< orphan*/ executePipe(char **, char **);
char *getcwd(char *, int);
char *getlogin();
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ lireCommande(char *, char **);
int /*<<< orphan*/ modifEntreeSortie(char **, char **);
int /*<<< orphan*/ printf(char *, ...);
char *rechercheCaractereSpecial(char **);
scalar_t__ strcmp(char *, char *);
scalar_t__ testCommandeInterne(char *);
void monShell(char *arge[]) {
  char cmd[100] = "";
  char *com[10];
  char *caractereSpe;
  char prompt[100];
  printf("Voici mon shell, taper Q pour sortir\n");
  getcwd(prompt, 100);
  printf("%s@[%s]--> ", getlogin(), getcwd(NULL, 0));
  while (strcmp(cmd, "Q") != 0) {
    gets(cmd);
    lireCommande(cmd, com);
    caractereSpe = rechercheCaractereSpecial(com);
    if (caractereSpe != NULL && (strcmp(caractereSpe, "|") == 0))
      executePipe(com, arge);
    else if (caractereSpe != NULL && (strcmp(caractereSpe, ";") == 0))
      executeCommandeSequentielle(com, arge);
    else if (caractereSpe != NULL &&
             (strcmp(caractereSpe, "<") == 0 || strcmp(caractereSpe, ">") == 0))
      modifEntreeSortie(com, arge);
    else {
      if (testCommandeInterne(com[0])) {
        execCommandeInterne(com, arge);
      } else {
        execCommandeExterne(com);
      }
    }
    getcwd(prompt, 100);
    printf("%s@[%s]--> ", getlogin(), prompt);
  }
}


x86 assembly (clang, -O0):
<monShell>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   10a0 <memset@plt>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x130(%rbp),%rdi
mov    $0x64,%esi
call   10b0 <getcwd@plt>
mov    $0x0,%al
call   10e0 <getlogin@plt>
mov    %rax,-0x138(%rbp)
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   10b0 <getcwd@plt>
mov    -0x138(%rbp),%rsi
mov    %rax,%rdx
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x70(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
je     13ed <monShell+0x20d>
lea    -0x70(%rbp),%rdi
call   10d0 <gets@plt>
lea    -0x70(%rbp),%rdi
lea    -0xc0(%rbp),%rsi
call   1100 <lireCommande@plt>
lea    -0xc0(%rbp),%rdi
call   1040 <rechercheCaractereSpecial@plt>
mov    %rax,-0xc8(%rbp)
cmpq   $0x0,-0xc8(%rbp)
je     12d5 <monShell+0xf5>
mov    -0xc8(%rbp),%rdi
lea    0xd83(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    12d5 <monShell+0xf5>
lea    -0xc0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10f0 <executePipe@plt>
jmp    13b8 <monShell+0x1d8>
cmpq   $0x0,-0xc8(%rbp)
je     1315 <monShell+0x135>
mov    -0xc8(%rbp),%rdi
lea    0xd45(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1315 <monShell+0x135>
lea    -0xc0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <executeCommandeSequentielle@plt>
jmp    13b3 <monShell+0x1d3>
cmpq   $0x0,-0xc8(%rbp)
je     1372 <monShell+0x192>
mov    -0xc8(%rbp),%rdi
lea    0xd07(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
je     135d <monShell+0x17d>
mov    -0xc8(%rbp),%rdi
lea    0xcec(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1372 <monShell+0x192>
lea    -0xc0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <modifEntreeSortie@plt>
jmp    13ae <monShell+0x1ce>
mov    -0xc0(%rbp),%rdi
call   1060 <testCommandeInterne@plt>
cmp    $0x0,%rax
je     139d <monShell+0x1bd>
lea    -0xc0(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <execCommandeInterne@plt>
jmp    13a9 <monShell+0x1c9>
lea    -0xc0(%rbp),%rdi
call   1080 <execCommandeExterne@plt>
jmp    13ae <monShell+0x1ce>
jmp    13b3 <monShell+0x1d3>
jmp    13b8 <monShell+0x1d8>
lea    -0x130(%rbp),%rdi
mov    $0x64,%esi
call   10b0 <getcwd@plt>
mov    $0x0,%al
call   10e0 <getlogin@plt>
mov    %rax,%rsi
lea    -0x130(%rbp),%rdx
lea    0xc45(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    124f <monShell+0x6f>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monShell>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rdi,%r14
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
movl   $0x0,0x60(%rsp)
lea    0xdf3(%rip),%rdi
call   1040 <puts@plt>
lea    0xc0(%rsp),%rdi
mov    $0x64,%esi
call   10b0 <getcwd@plt>
xor    %eax,%eax
call   10e0 <getlogin@plt>
mov    %rax,%rbx
xor    %edi,%edi
xor    %esi,%esi
call   10b0 <getcwd@plt>
lea    0xdac(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xda4(%rip),%rsi
mov    %rsp,%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     13a9 <monShell+0x1c9>
mov    %rsp,%r15
lea    0x70(%rsp),%rbx
lea    0xc0(%rsp),%r12
lea    0xd7c(%rip),%rbp
jmp    12e7 <monShell+0x107>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r14,%rsi
call   10f0 <executePipe@plt>
mov    %r12,%rdi
mov    $0x64,%esi
call   10b0 <getcwd@plt>
xor    %eax,%eax
call   10e0 <getlogin@plt>
lea    0xd3a(%rip),%rdi
mov    %rax,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     13a9 <monShell+0x1c9>
mov    %r15,%rdi
call   10d0 <gets@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1100 <lireCommande@plt>
mov    %rbx,%rdi
call   1050 <rechercheCaractereSpecial@plt>
test   %rax,%rax
je     1360 <monShell+0x180>
mov    %rax,%r13
mov    %rax,%rdi
lea    0xcfa(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     12a0 <monShell+0xc0>
mov    %r13,%rdi
lea    0xce8(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1399 <monShell+0x1b9>
mov    %r13,%rdi
lea    0xcd6(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1389 <monShell+0x1a9>
mov    %r13,%rdi
lea    0xcc4(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1389 <monShell+0x1a9>
nopw   0x0(%rax,%rax,1)
mov    0x70(%rsp),%rdi
call   1070 <testCommandeInterne@plt>
mov    %rbx,%rdi
test   %rax,%rax
je     137f <monShell+0x19f>
mov    %r14,%rsi
call   1060 <execCommandeInterne@plt>
jmp    12ab <monShell+0xcb>
call   1090 <execCommandeExterne@plt>
jmp    12ab <monShell+0xcb>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <modifEntreeSortie@plt>
jmp    12ab <monShell+0xcb>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10a0 <executeCommandeSequentielle@plt>
jmp    12ab <monShell+0xcb>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"Voici mon shell, taper Q pour sortir\0A\00"
@.str.1 = [12 x i8] c"%s@[%s]--> \00"
@.str.2 = [2 x i8] c"Q\00"
@.str.3 = [2 x i8] c"|\00"
@.str.4 = [2 x i8] c";\00"
@.str.5 = [2 x i8] c"<\00"
@.str.6 = [2 x i8] c">\00"
define void @monShell(i8** %0) {
%2 = alloca i8**
%3 = alloca [100 x i8]
%4 = alloca [10 x i8*]
%5 = alloca i8*
%6 = alloca [100 x i8]
store i8** %0, i8*** %2
%7 = bitcast [100 x i8]* %3 to i8*
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%10 = call i8* @getcwd(i8* %9, i32 100)
%11 = call i8* (...) @getlogin()
%12 = call i8* @getcwd(i8* null, i32 0)
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %12)
br label %14
14: ; preds = %77, %1
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %83
18: ; preds = %14
%19 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%20 = call i32 @gets(i8* %19)
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%22 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%23 = call i32 @lireCommande(i8* %21, i8** %22)
%24 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%25 = call i8* @rechercheCaractereSpecial(i8** %24)
store i8* %25, i8** %5
%26 = load i8*, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %36
28: ; preds = %18
%29 = load i8*, i8** %5
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%34 = load i8**, i8*** %2
%35 = call i32 @executePipe(i8** %33, i8** %34)
br label %77
36: ; preds = %28, %18
%37 = load i8*, i8** %5
%38 = icmp ne i8* %37, null
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = load i8*, i8** %5
%41 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%45 = load i8**, i8*** %2
%46 = call i32 @executeCommandeSequentielle(i8** %44, i8** %45)
br label %76
47: ; preds = %39, %36
%48 = load i8*, i8** %5
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %62
50: ; preds = %47
%51 = load i8*, i8** %5
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %50
%55 = load i8*, i8** %5
%56 = call i64 @strcmp(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %62
58: ; preds = %54, %50
%59 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%60 = load i8**, i8*** %2
%61 = call i32 @modifEntreeSortie(i8** %59, i8** %60)
br label %75
62: ; preds = %54, %47
%63 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%64 = load i8*, i8** %63
%65 = call i64 @testCommandeInterne(i8* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %71
67: ; preds = %62
%68 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%69 = load i8**, i8*** %2
%70 = call i32 @execCommandeInterne(i8** %68, i8** %69)
br label %74
71: ; preds = %62
%72 = getelementptr inbounds [10 x i8*], [10 x i8*]* %4, i64 0, i64 0
%73 = call i32 @execCommandeExterne(i8** %72)
br label %74
74: ; preds = %71, %67
br label %75
75: ; preds = %74, %58
br label %76
76: ; preds = %75, %43
br label %77
77: ; preds = %76, %32
%78 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%79 = call i8* @getcwd(i8* %78, i32 100)
%80 = call i8* (...) @getlogin()
%81 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %80, i8* %81)
br label %14
83: ; preds = %14
ret void
}

LLVM IR (-O2):
@.str.1 = [12 x i8] c"%s@[%s]--> \00"
@.str.2 = [2 x i8] c"Q\00"
@.str.3 = [2 x i8] c"|\00"
@.str.4 = [2 x i8] c";\00"
@.str.5 = [2 x i8] c"<\00"
@.str.6 = [2 x i8] c">\00"
@str = [37 x i8] c"Voici mon shell, taper Q pour sortir\00"
define void @monShell(i8** %0) {
%2 = alloca [100 x i8]
%3 = alloca [10 x i8*]
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%6 = bitcast [10 x i8*]* %3 to i8*
%7 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%9 = call i8* @getcwd(i8* %7, i32 100)
%10 = call i8* (...) @getlogin()
%11 = call i8* @getcwd(i8* null, i32 0)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %10, i8* %11)
%13 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %54, label %15
15: ; preds = %1
%16 = getelementptr inbounds [10 x i8*], [10 x i8*]* %3, i64 0, i64 0
br label %17
17: ; preds = %15, %48
%18 = call i32 @gets(i8* %5)
%19 = call i32 @lireCommande(i8* %5, i8** %16)
%20 = call i8* @rechercheCaractereSpecial(i8** %16)
%21 = icmp eq i8* %20, null
br i1 %21, label %40, label %22
22: ; preds = %17
%23 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %22
%26 = call i32 @executePipe(i8** %16, i8** %0)
br label %48
27: ; preds = %22
%28 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @executeCommandeSequentielle(i8** %16, i8** %0)
br label %48
32: ; preds = %27
%33 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %38, label %35
35: ; preds = %32
%36 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %35, %32
%39 = call i32 @modifEntreeSortie(i8** %16, i8** %0)
br label %48
40: ; preds = %17, %35
%41 = load i8*, i8** %16
%42 = call i64 @testCommandeInterne(i8* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %46, label %44
44: ; preds = %40
%45 = call i32 @execCommandeInterne(i8** %16, i8** %0)
br label %48
46: ; preds = %40
%47 = call i32 @execCommandeExterne(i8** %16)
br label %48
48: ; preds = %30, %44, %46, %38, %25
%49 = call i8* @getcwd(i8* %7, i32 100)
%50 = call i8* (...) @getlogin()
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %50, i8* %7)
%52 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %17
54: ; preds = %48, %1
ret void
}