#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
scalar_t__ lstat(char *, struct stat *);
scalar_t__ malloc(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(int /*<<< orphan*/, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int parcours(char *rep, int indent) {
  DIR *repCourant = opendir(rep);
  if (repCourant == NULL) {
    fprintf(stderr, "Impossible d'ouvrir le répertoire : %s\n", rep);
    return -1;
  }
  char *chemin = (char *)malloc(1024);
  struct dirent *entree;
  struct stat etat;
  while ((entree = readdir(repCourant)) != NULL) {
    strcat(strcat(strcpy(chemin, rep), "/"), entree->d_name);
    if (lstat(chemin, &etat) < 0) {
      fprintf(stderr, "Impossible d'ouvrir le fichier : %s\n", chemin);
    }
    if (S_ISDIR(etat.st_mode) && strcmp(entree->d_name, ".") &&
        strcmp(entree->d_name, "..")) {
      int i;
      for (i = 0; i < indent; i++)
        printf(" ");
      printf("%s\n", chemin);
      parcours(chemin, indent + 1);
    }
  }
  free(chemin);
  closedir(repCourant);
  return 0;
}


x86 assembly (clang, -O0):
<parcours>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    121c <parcours+0x4c>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf5(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1354 <parcours+0x184>
mov    $0x400,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   10d0 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     133b <parcours+0x16b>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %eax,%edi
lea    0xdd2(%rip),%rsi
call   10f0 <strcat@plt>
mov    %eax,%edi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
call   10f0 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10a0 <lstat@plt>
cmp    $0x0,%rax
jge    129a <parcours+0xca>
mov    0x2d58(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd96(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x38(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1336 <parcours+0x166>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
lea    0xd97(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
je     1336 <parcours+0x166>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
lea    0xd79(%rip),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
je     1336 <parcours+0x166>
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1315 <parcours+0x145>
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    12ed <parcours+0x11d>
mov    -0x28(%rbp),%rsi
lea    0xd05(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1090 <parcours@plt>
jmp    122a <parcours+0x5a>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parcours>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,%r14
call   1070 <opendir@plt>
test   %rax,%rax
je     1348 <parcours+0x168>
mov    %rax,%r12
mov    $0x400,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
call   10e0 <readdir@plt>
test   %rax,%rax
je     1334 <parcours+0x154>
mov    %rax,%r15
mov    0x8(%rsp),%rax
add    $0x1,%eax
mov    %eax,0x14(%rsp)
lea    0xdee(%rip),%rbp
lea    0x10(%rsp),%r13
jmp    127b <parcours+0x9b>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <puts@plt>
mov    %rbx,%rdi
mov    0x14(%rsp),%esi
call   10a0 <parcours@plt>
mov    %r15,%rbp
mov    %r12,%rdi
call   10e0 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
je     1334 <parcours+0x154>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1050 <strcpy@plt>
mov    %eax,%edi
mov    %rbp,%rsi
call   1100 <strcat@plt>
mov    (%r15),%rsi
mov    %eax,%edi
call   1100 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10b0 <lstat@plt>
test   %rax,%rax
jns    12c2 <parcours+0xe2>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd71(%rip),%rsi
mov    %rbx,%rdx
call   10d0 <fprintf@plt>
mov    0x10(%rsp),%edi
call   1080 <S_ISDIR@plt>
test   %rax,%rax
je     1267 <parcours+0x87>
mov    (%r15),%rdi
lea    0xd77(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1267 <parcours+0x87>
mov    (%r15),%rdi
lea    0xd62(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1267 <parcours+0x87>
mov    %rbp,%r15
cmpl   $0x0,0x8(%rsp)
jle    1250 <parcours+0x70>
mov    0x8(%rsp),%rax
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    $0x20,%edi
call   1040 <putchar@plt>
add    $0xffffffff,%ebp
jne    1320 <parcours+0x140>
jmp    1250 <parcours+0x70>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1090 <closedir@plt>
xor    %eax,%eax
jmp    1365 <parcours+0x185>
mov    0x2c91(%rip),%rax
mov    (%rax),%edi
lea    0xca8(%rip),%rsi
mov    %r14,%rdx
call   10d0 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [41 x i8] c"Impossible d'ouvrir le r\C3\A9pertoire : %s\0A\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [37 x i8] c"Impossible d'ouvrir le fichier : %s\0A\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [3 x i8] c"..\00"
@.str.5 = [2 x i8] c" \00"
@.str.6 = [4 x i8] c"%s\0A\00"
define i32 @parcours(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca %struct.dirent*
%9 = alloca %struct.stat
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = load i8*, i8** %4
%12 = call i32* @opendir(i8* %11)
store i32* %12, i32** %6
%13 = load i32*, i32** %6
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %4
%18 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %17)
store i32 -1, i32* %3
br label %82
19: ; preds = %2
%20 = call i64 @malloc(i32 1024)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %7
br label %22
22: ; preds = %76, %19
%23 = load i32*, i32** %6
%24 = call %struct.dirent* @readdir(i32* %23)
store %struct.dirent* %24, %struct.dirent** %8
%25 = icmp ne %struct.dirent* %24, null
br i1 %25, label %26, label %77
26: ; preds = %22
%27 = load i8*, i8** %7
%28 = load i8*, i8** %4
%29 = call i32 @strcpy(i8* %27, i8* %28)
%30 = call i32 @strcat(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = load %struct.dirent*, %struct.dirent** %8
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @strcat(i32 %30, i8* %33)
%35 = load i8*, i8** %7
%36 = call i64 @lstat(i8* %35, %struct.stat* %9)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %26
%39 = load i32, i32* @stderr
%40 = load i8*, i8** %7
%41 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %38, %26
%43 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i64 @S_ISDIR(i32 %44)
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %76
47: ; preds = %42
%48 = load %struct.dirent*, %struct.dirent** %8
%49 = getelementptr inbounds %struct.dirent, %struct.dirent* %48, i32 0, i32 0
%50 = load i8*, i8** %49
%51 = call i64 @strcmp(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %76
53: ; preds = %47
%54 = load %struct.dirent*, %struct.dirent** %8
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %54, i32 0, i32 0
%56 = load i8*, i8** %55
%57 = call i64 @strcmp(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %76
59: ; preds = %53
store i32 0, i32* %10
br label %60
60: ; preds = %66, %59
%61 = load i32, i32* %10
%62 = load i32, i32* %5
%63 = icmp slt i32 %61, %62
br i1 %63, label %64, label %69
64: ; preds = %60
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
br label %66
66: ; preds = %64
%67 = load i32, i32* %10
%68 = add nsw i32 %67, 1
store i32 %68, i32* %10
br label %60
69: ; preds = %60
%70 = load i8*, i8** %7
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %70)
%72 = load i8*, i8** %7
%73 = load i32, i32* %5
%74 = add nsw i32 %73, 1
%75 = call i32 @parcours(i8* %72, i32 %74)
br label %76
76: ; preds = %69, %53, %47, %42
br label %22
77: ; preds = %22
%78 = load i8*, i8** %7
%79 = call i32 @free(i8* %78)
%80 = load i32*, i32** %6
%81 = call i32 @closedir(i32* %80)
store i32 0, i32* %3
br label %82
82: ; preds = %77, %15
%83 = load i32, i32* %3
ret i32 %83
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [41 x i8] c"Impossible d'ouvrir le r\C3\A9pertoire : %s\0A\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [37 x i8] c"Impossible d'ouvrir le fichier : %s\0A\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [3 x i8] c"..\00"
define i32 @parcours(i8* %0, i32 %1) {
%3 = alloca %struct.stat
%4 = tail call i32* @opendir(i8* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %58
9: ; preds = %2
%10 = tail call i64 @malloc(i32 1024)
%11 = inttoptr i64 %10 to i8*
%12 = bitcast %struct.stat* %3 to i8*
%13 = tail call %struct.dirent* @readdir(i32* %4)
%14 = icmp eq %struct.dirent* %13, null
br i1 %14, label %55, label %15
15: ; preds = %9
%16 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%17 = icmp sgt i32 %1, 0
%18 = add nsw i32 %1, 1
br label %19
19: ; preds = %15, %52
%20 = phi %struct.dirent* [ %13, %15 ], [ %53, %52 ]
%21 = tail call i32 @strcpy(i8* %11, i8* %0)
%22 = tail call i32 @strcat(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = tail call i32 @strcat(i32 %22, i8* %24)
%26 = call i64 @lstat(i8* %11, %struct.stat* %3)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %19
%29 = load i32, i32* @stderr
%30 = tail call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %11)
br label %31
31: ; preds = %28, %19
%32 = load i32, i32* %16
%33 = tail call i64 @S_ISDIR(i32 %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %52, label %35
35: ; preds = %31
%36 = load i8*, i8** %23
%37 = tail call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %52, label %39
39: ; preds = %35
%40 = load i8*, i8** %23
%41 = tail call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %52, label %43
43: ; preds = %39
br i1 %17, label %44, label %49
44: ; preds = %43, %44
%45 = phi i32 [ %47, %44 ], [ 0, %43 ]
%46 = tail call i32 @putchar(i32 32)
%47 = add nuw nsw i32 %45, 1
%48 = icmp eq i32 %47, %1
br i1 %48, label %49, label %44
49: ; preds = %44, %43
%50 = tail call i32 @puts(i8* dereferenceable(1) %11)
%51 = tail call i32 @parcours(i8* %11, i32 %18)
br label %52
52: ; preds = %49, %39, %35, %31
%53 = tail call %struct.dirent* @readdir(i32* %4)
%54 = icmp eq %struct.dirent* %53, null
br i1 %54, label %55, label %19
55: ; preds = %52, %9
%56 = tail call i32 @free(i8* %11)
%57 = tail call i32 @closedir(i32* %4)
br label %58
58: ; preds = %55, %6
%59 = phi i32 [ -1, %6 ], [ 0, %55 ]
ret i32 %59
}