#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ execlp(char *, char *, char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  char nomFichier[255];
  while (1) {
    printf(">");
    scanf("%s", nomFichier);
    if (!strcmp(nomFichier, "\\fin"))
      exit(0);
    else if (!strcmp(nomFichier, "\\ls")) {
      if (!fork()) {
        execlp("ls", "ls", NULL);
        exit(EXIT_FAILURE);
      }
      wait(NULL);
    } else if (!strcmp(nomFichier, "\\pwd")) {
      if (!fork()) {
        execlp("pwd", "pwd", NULL);
        exit(EXIT_FAILURE);
      }
      wait(NULL);
    } else if (!strcmp(nomFichier, "**")) {
      chdir("..");
      if (!fork()) {
        execlp("pwd", "pwd", NULL);
        exit(EXIT_FAILURE);
      }
      wait(NULL);
    } else if (!strcmp(nomFichier, "*")) {
      scanf("%s", nomFichier);
      chdir(nomFichier);
    } else {
      if (!fork()) {
        execlp("cat", "cat", nomFichier, NULL);
        exit(EXIT_FAILURE);
      }
      wait(NULL);
    }
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe60(%rip),%rdi
call   1040 <printf@plt>
lea    -0x110(%rbp),%rsi
lea    0xe4f(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe3f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11db <main+0x5b>
xor    %edi,%edi
call   1070 <exit@plt>
lea    -0x110(%rbp),%rdi
lea    0xe21(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1238 <main+0xb8>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%eax
jne    122a <main+0xaa>
lea    0xdfd(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1080 <execlp@plt>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <wait@plt>
jmp    1390 <main+0x210>
lea    -0x110(%rbp),%rdi
lea    0xdc8(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    1295 <main+0x115>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%eax
jne    1287 <main+0x107>
lea    0xda4(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1080 <execlp@plt>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <wait@plt>
jmp    138b <main+0x20b>
lea    -0x110(%rbp),%rdi
lea    0xd70(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    12fe <main+0x17e>
lea    0xd5e(%rip),%rdi
call   1030 <chdir@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%eax
jne    12f0 <main+0x170>
lea    0xd3b(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1080 <execlp@plt>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <wait@plt>
jmp    1386 <main+0x206>
lea    -0x110(%rbp),%rdi
lea    0xd08(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    133e <main+0x1be>
lea    -0x110(%rbp),%rsi
lea    0xcda(%rip),%rdi
call   1060 <scanf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <chdir@plt>
jmp    1381 <main+0x201>
mov    $0x0,%al
call   10a0 <fork@plt>
cmp    $0x0,%eax
jne    1378 <main+0x1f8>
lea    -0x110(%rbp),%rdx
lea    0xcbd(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
mov    $0x0,%al
call   1080 <execlp@plt>
mov    0x2c6f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <wait@plt>
jmp    1386 <main+0x206>
jmp    138b <main+0x20b>
jmp    1390 <main+0x210>
jmp    1395 <main+0x215>
jmp    1199 <main+0x19>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    $0x3e,%edi
call   1030 <putchar@plt>
lea    0xe6e(%rip),%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    $0x6e69665c,%ebp
mov    (%rsp),%eax
xor    %ebp,%eax
movzbl 0x4(%rsp),%ecx
or     %eax,%ecx
jne    11b4 <main+0x44>
xor    %edi,%edi
call   1060 <exit@plt>
lea    0xe45(%rip),%r14
mov    %rsp,%rbx
mov    $0x6477705c,%r12d
mov    $0x2a2a,%r13d
lea    0xe42(%rip),%r15
jmp    1219 <main+0xa9>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
je     129d <main+0x12d>
xor    %edi,%edi
call   1080 <wait@plt>
mov    $0x3e,%edi
call   1030 <putchar@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%eax
xor    %ebp,%eax
movzbl 0x4(%rsp),%ecx
or     %eax,%ecx
je     11ad <main+0x3d>
mov    (%rsp),%eax
cmp    $0x736c5c,%eax
je     11e0 <main+0x70>
mov    (%rsp),%ecx
xor    %r12d,%ecx
movzbl 0x4(%rsp),%edx
or     %ecx,%edx
je     1265 <main+0xf5>
mov    (%rsp),%ecx
xor    %r13d,%ecx
movzbl 0x2(%rsp),%edx
or     %cx,%dx
je     125d <main+0xed>
cmp    $0x2a,%ax
jne    1276 <main+0x106>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    %rbx,%rdi
call   1040 <chdir@plt>
jmp    11f6 <main+0x86>
mov    %r15,%rdi
call   1040 <chdir@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
jne    11ef <main+0x7f>
jmp    12a6 <main+0x136>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
jne    11ef <main+0x7f>
lea    0xd8a(%rip),%rdi
mov    %rsp,%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1070 <execlp@plt>
jmp    12b9 <main+0x149>
lea    0xd64(%rip),%rdi
jmp    12ad <main+0x13d>
lea    0xd5f(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <execlp@plt>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c">\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"\\fin\00"
@.str.3 = [4 x i8] c"\\ls\00"
@.str.4 = [3 x i8] c"ls\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [5 x i8] c"\\pwd\00"
@.str.6 = [4 x i8] c"pwd\00"
@.str.7 = [3 x i8] c"**\00"
@.str.8 = [3 x i8] c"..\00"
@.str.9 = [2 x i8] c"*\00"
@.str.10 = [4 x i8] c"cat\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [255 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %7
7: ; preds = %2, %79
%8 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%10 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%12 = call i32 @strcmp(i8* %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%13 = icmp ne i32 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %7
%15 = call i32 @exit(i32 0)
unreachable
16: ; preds = %7
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %29, label %20
20: ; preds = %16
%21 = call i32 (...) @fork()
%22 = icmp ne i32 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %20
%24 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* null)
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %20
%28 = call i32 @wait(i32* null)
br label %78
29: ; preds = %16
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%31 = call i32 @strcmp(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%32 = icmp ne i32 %31, 0
br i1 %32, label %42, label %33
33: ; preds = %29
%34 = call i32 (...) @fork()
%35 = icmp ne i32 %34, 0
br i1 %35, label %40, label %36
36: ; preds = %33
%37 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* null)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %33
%41 = call i32 @wait(i32* null)
br label %77
42: ; preds = %29
%43 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%44 = call i32 @strcmp(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
br i1 %45, label %56, label %46
46: ; preds = %42
%47 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%48 = call i32 (...) @fork()
%49 = icmp ne i32 %48, 0
br i1 %49, label %54, label %50
50: ; preds = %46
%51 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* null)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %46
%55 = call i32 @wait(i32* null)
br label %76
56: ; preds = %42
%57 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%58 = call i32 @strcmp(i8* %57, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
%59 = icmp ne i32 %58, 0
br i1 %59, label %65, label %60
60: ; preds = %56
%61 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%62 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %61)
%63 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%64 = call i32 @chdir(i8* %63)
br label %75
65: ; preds = %56
%66 = call i32 (...) @fork()
%67 = icmp ne i32 %66, 0
br i1 %67, label %73, label %68
68: ; preds = %65
%69 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%70 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %69, i8* null)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %65
%74 = call i32 @wait(i32* null)
br label %75
75: ; preds = %73, %60
br label %76
76: ; preds = %75, %54
br label %77
77: ; preds = %76, %40
br label %78
78: ; preds = %77, %27
br label %79
79: ; preds = %78
br label %7
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [5 x i8] c"\\fin\00"
@.str.4 = [3 x i8] c"ls\00"
@EXIT_FAILURE = global i32 0
@.str.5 = [5 x i8] c"\\pwd\00"
@.str.6 = [4 x i8] c"pwd\00"
@.str.7 = [3 x i8] c"**\00"
@.str.8 = [3 x i8] c"..\00"
@.str.10 = [4 x i8] c"cat\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [255 x i8]
%4 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
%5 = call i32 @putchar(i32 62)
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%7 = call i32 @bcmp(i8* dereferenceable(5) %4, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 5)
%8 = icmp eq i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = bitcast [255 x i8]* %3 to i32*
br label %13
11: ; preds = %65, %2
%12 = call i32 @exit(i32 0)
unreachable
13: ; preds = %9, %65
%14 = load i32, i32* %10
%15 = icmp eq i32 %14, 7564380
%16 = trunc i32 %14 to i16
br i1 %15, label %17, label %26
17: ; preds = %13
%18 = call i32 (...) @fork()
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %17
%21 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* null)
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %17
%25 = call i32 @wait(i32* null)
br label %65
26: ; preds = %13
%27 = call i32 @bcmp(i8* dereferenceable(5) %4, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i64 5)
%28 = icmp eq i32 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = call i32 (...) @fork()
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* null)
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %29
%37 = call i32 @wait(i32* null)
br label %65
38: ; preds = %26
%39 = call i32 @bcmp(i8* dereferenceable(3) %4, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i64 3)
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %51
41: ; preds = %38
%42 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%43 = call i32 (...) @fork()
%44 = icmp eq i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %41
%46 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* null)
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %41
%50 = call i32 @wait(i32* null)
br label %65
51: ; preds = %38
%52 = icmp eq i16 %16, 42
br i1 %52, label %53, label %56
53: ; preds = %51
%54 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%55 = call i32 @chdir(i8* %4)
br label %65
56: ; preds = %51
%57 = call i32 (...) @fork()
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %56
%60 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0), i8* %4, i8* null)
%61 = load i32, i32* @EXIT_FAILURE
%62 = call i32 @exit(i32 %61)
unreachable
63: ; preds = %56
%64 = call i32 @wait(i32* null)
br label %65
65: ; preds = %24, %49, %63, %53, %36
%66 = call i32 @putchar(i32 62)
%67 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%68 = call i32 @bcmp(i8* dereferenceable(5) %4, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i64 5)
%69 = icmp eq i32 %68, 0
br i1 %69, label %11, label %13
}