#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 */
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ copy(char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ lstat(char *, struct stat *);
char *malloc(int);
int /*<<< orphan*/ mkdir(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int stat(char *, struct stat *);
int strlen(char *);
void sauv_rec(char *src, char *dest) {
  struct stat srcStat;
  struct stat destStat;
  if (stat(src, &srcStat) == -1) {
    printf("%s n'est pas une source valide.\n", src);
    exit(0);
  } else if (!(S_ISDIR(srcStat.st_mode))) {
    if (stat(dest, &destStat) == -1) {
      printf("Creation du lien vers le fichier\n");
      copy(src, dest);
    } else {
      printf("Il exite déja un fichier/dossier de ce nom");
      exit(0);
    }
  } else {
    if (stat(dest, &destStat) == -1) {
      printf("Creation dossier dest\n");
      mkdir(dest, srcStat.st_mode);
    } else if (!(S_ISDIR(destStat.st_mode))) {
      printf("Dest est un fichier.\n");
      exit(0);
    }
    DIR *dirSrc = opendir(src);
    struct dirent *entry;
    while ((entry = readdir(dirSrc)) != NULL) {
      if (entry->d_name[0] == '.') {
        continue;
      }
      struct stat tmpSrc;
      char *cheminSrc =
          malloc(sizeof(char) * (strlen(src) + strlen(entry->d_name) + 2));
      sprintf(cheminSrc, "%s/%s", src, entry->d_name);
      lstat(cheminSrc, &tmpSrc);
      char *cheminDest =
          malloc(sizeof(char) * (strlen(dest) + strlen(entry->d_name) + 2));
      sprintf(cheminDest, "%s/%s", dest, entry->d_name);
      sauv_rec(cheminSrc, cheminDest);
    }
  }
}


x86 assembly (clang, -O0):
<sauv_rec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
jne    120f <sauv_rec+0x3f>
mov    -0x8(%rbp),%rsi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1270 <sauv_rec+0xa0>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
jne    1256 <sauv_rec+0x86>
lea    0xde4(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10a0 <copy@plt>
jmp    126b <sauv_rec+0x9b>
lea    0xde6(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    13cc <sauv_rec+0x1fc>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0xffffffff,%eax
jne    12a5 <sauv_rec+0xd5>
lea    0xde2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <mkdir@plt>
jmp    12d0 <sauv_rec+0x100>
mov    -0x20(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    12cb <sauv_rec+0xfb>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   10f0 <exit@plt>
jmp    12d0 <sauv_rec+0x100>
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     13c7 <sauv_rec+0x1f7>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    130c <sauv_rec+0x13c>
jmp    12dd <sauv_rec+0x10d>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x50(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    (%rax),%rcx
lea    0xd47(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x40(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1090 <lstat@plt>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    (%rax),%rcx
lea    0xcec(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1040 <sauv_rec@plt>
jmp    12dd <sauv_rec+0x10d>
jmp    13cc <sauv_rec+0x1fc>
jmp    13d1 <sauv_rec+0x201>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sauv_rec>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
lea    0x10(%rsp),%rsi
mov    %rdi,(%rsp)
call   10c0 <stat@plt>
cmp    $0xffffffff,%eax
je     137c <sauv_rec+0x19c>
mov    0x10(%rsp),%r14d
mov    %r14d,%edi
call   1090 <S_ISDIR@plt>
mov    %eax,%ebp
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   10c0 <stat@plt>
test   %ebp,%ebp
je     1252 <sauv_rec+0x72>
cmp    $0xffffffff,%eax
mov    %rbx,0x18(%rsp)
je     1281 <sauv_rec+0xa1>
mov    0x8(%rsp),%edi
call   1090 <S_ISDIR@plt>
test   %eax,%eax
jne    1298 <sauv_rec+0xb8>
lea    0xe2e(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   1100 <exit@plt>
cmp    $0xffffffff,%eax
jne    1395 <sauv_rec+0x1b5>
lea    0xdf1(%rip),%rdi
call   1040 <puts@plt>
mov    (%rsp),%rdi
mov    %rbx,%rsi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10b0 <copy@plt>
lea    0xe01(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   1030 <mkdir@plt>
mov    (%rsp),%rdi
call   1060 <opendir@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   10d0 <readdir@plt>
test   %rax,%rax
je     136d <sauv_rec+0x18d>
mov    %rax,%rbp
mov    0x18(%rsp),%r15
jmp    12d4 <sauv_rec+0xf4>
nop
mov    %r12,%rdi
call   10d0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     136d <sauv_rec+0x18d>
mov    0x0(%rbp),%rax
cmpb   $0x2e,(%rax)
je     12c0 <sauv_rec+0xe0>
mov    (%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %eax,%r14d
mov    0x0(%rbp),%rdi
call   1070 <strlen@plt>
lea    (%r14,%rax,1),%edi
add    $0x2,%edi
call   10e0 <malloc@plt>
mov    %rax,%r13
mov    0x0(%rbp),%rcx
mov    %rax,%rdi
lea    0xd3b(%rip),%r14
mov    %r14,%rsi
mov    %rbx,%rdx
call   10f0 <sprintf@plt>
mov    %r13,%rdi
lea    0x20(%rsp),%rsi
call   10a0 <lstat@plt>
mov    %r15,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%rdi
call   1070 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%rcx
mov    %rax,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   10f0 <sprintf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <sauv_rec@plt>
jmp    12c0 <sauv_rec+0xe0>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc7d(%rip),%rdi
mov    (%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>
lea    0xc85(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
xor    %edi,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [33 x i8] c"%s n'est pas une source valide.\0A\00"
@.str.1 = [34 x i8] c"Creation du lien vers le fichier\0A\00"
@.str.2 = [44 x i8] c"Il exite d\C3\A9ja un fichier/dossier de ce nom\00"
@.str.3 = [23 x i8] c"Creation dossier dest\0A\00"
@.str.4 = [22 x i8] c"Dest est un fichier.\0A\00"
@.str.5 = [6 x i8] c"%s/%s\00"
define void @sauv_rec(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca %struct.stat
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca %struct.stat
%10 = alloca i8*
%11 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%12 = load i8*, i8** %3
%13 = call i32 @stat(i8* %12, %struct.stat* %5)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i8*, i8** %3
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = call i32 @exit(i32 0)
unreachable
19: ; preds = %2
%20 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @S_ISDIR(i32 %21)
%23 = icmp ne i32 %22, 0
br i1 %23, label %37, label %24
24: ; preds = %19
%25 = load i8*, i8** %4
%26 = call i32 @stat(i8* %25, %struct.stat* %6)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
%30 = load i8*, i8** %3
%31 = load i8*, i8** %4
%32 = call i32 @copy(i8* %30, i8* %31)
br label %36
33: ; preds = %24
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 0)
unreachable
36: ; preds = %28
br label %114
37: ; preds = %19
%38 = load i8*, i8** %4
%39 = call i32 @stat(i8* %38, %struct.stat* %6)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %47
41: ; preds = %37
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%43 = load i8*, i8** %4
%44 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%45 = load i32, i32* %44
%46 = call i32 @mkdir(i8* %43, i32 %45)
br label %56
47: ; preds = %37
%48 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @S_ISDIR(i32 %49)
%51 = icmp ne i32 %50, 0
br i1 %51, label %55, label %52
52: ; preds = %47
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %47
br label %56
56: ; preds = %55, %41
%57 = load i8*, i8** %3
%58 = call i32* @opendir(i8* %57)
store i32* %58, i32** %7
br label %59
59: ; preds = %72, %71, %56
%60 = load i32*, i32** %7
%61 = call %struct.dirent* @readdir(i32* %60)
store %struct.dirent* %61, %struct.dirent** %8
%62 = icmp ne %struct.dirent* %61, null
br i1 %62, label %63, label %113
63: ; preds = %59
%64 = load %struct.dirent*, %struct.dirent** %8
%65 = getelementptr inbounds %struct.dirent, %struct.dirent* %64, i32 0, i32 0
%66 = load i8*, i8** %65
%67 = getelementptr inbounds i8, i8* %66, i64 0
%68 = load i8, i8* %67
%69 = sext i8 %68 to i32
%70 = icmp eq i32 %69, 46
br i1 %70, label %71, label %72
71: ; preds = %63
br label %59
72: ; preds = %63
%73 = load i8*, i8** %3
%74 = call i32 @strlen(i8* %73)
%75 = load %struct.dirent*, %struct.dirent** %8
%76 = getelementptr inbounds %struct.dirent, %struct.dirent* %75, i32 0, i32 0
%77 = load i8*, i8** %76
%78 = call i32 @strlen(i8* %77)
%79 = add nsw i32 %74, %78
%80 = add nsw i32 %79, 2
%81 = sext i32 %80 to i64
%82 = mul i64 1, %81
%83 = trunc i64 %82 to i32
%84 = call i8* @malloc(i32 %83)
store i8* %84, i8** %10
%85 = load i8*, i8** %10
%86 = load i8*, i8** %3
%87 = load %struct.dirent*, %struct.dirent** %8
%88 = getelementptr inbounds %struct.dirent, %struct.dirent* %87, i32 0, i32 0
%89 = load i8*, i8** %88
%90 = call i32 @sprintf(i8* %85, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %86, i8* %89)
%91 = load i8*, i8** %10
%92 = call i32 @lstat(i8* %91, %struct.stat* %9)
%93 = load i8*, i8** %4
%94 = call i32 @strlen(i8* %93)
%95 = load %struct.dirent*, %struct.dirent** %8
%96 = getelementptr inbounds %struct.dirent, %struct.dirent* %95, i32 0, i32 0
%97 = load i8*, i8** %96
%98 = call i32 @strlen(i8* %97)
%99 = add nsw i32 %94, %98
%100 = add nsw i32 %99, 2
%101 = sext i32 %100 to i64
%102 = mul i64 1, %101
%103 = trunc i64 %102 to i32
%104 = call i8* @malloc(i32 %103)
store i8* %104, i8** %11
%105 = load i8*, i8** %11
%106 = load i8*, i8** %4
%107 = load %struct.dirent*, %struct.dirent** %8
%108 = getelementptr inbounds %struct.dirent, %struct.dirent* %107, i32 0, i32 0
%109 = load i8*, i8** %108
%110 = call i32 @sprintf(i8* %105, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %106, i8* %109)
%111 = load i8*, i8** %10
%112 = load i8*, i8** %11
br label %59
113: ; preds = %59
br label %114
114: ; preds = %113, %36
br label %115
115: ; preds = %114
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [33 x i8] c"%s n'est pas une source valide.\0A\00"
@.str.2 = [44 x i8] c"Il exite d\C3\A9ja un fichier/dossier de ce nom\00"
@.str.5 = [6 x i8] c"%s/%s\00"
@str = [33 x i8] c"Creation du lien vers le fichier\00"
@str.6 = [21 x i8] c"Dest est un fichier.\00"
@str.7 = [22 x i8] c"Creation dossier dest\00"
define void @sauv_rec(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = alloca %struct.stat
%5 = alloca %struct.stat
%6 = bitcast %struct.stat* %3 to i8*
%7 = bitcast %struct.stat* %4 to i8*
%8 = call i32 @stat(i8* %0, %struct.stat* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %0)
%12 = tail call i32 @exit(i32 0)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i32 @S_ISDIR(i32 %15)
%17 = icmp eq i32 %16, 0
%18 = call i32 @stat(i8* %1, %struct.stat* %4)
%19 = icmp eq i32 %18, -1
br i1 %17, label %20, label %27
20: ; preds = %13
br i1 %19, label %21, label %24
21: ; preds = %20
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
%23 = tail call i32 @copy(i8* %0, i8* %1)
br label %72
24: ; preds = %20
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 @exit(i32 0)
unreachable
27: ; preds = %13
br i1 %19, label %28, label %31
28: ; preds = %27
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0))
%30 = tail call i32 @mkdir(i8* %1, i32 %15)
br label %39
31: ; preds = %27
%32 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%33 = load i32, i32* %32
%34 = tail call i32 @S_ISDIR(i32 %33)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %31
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0))
%38 = tail call i32 @exit(i32 0)
unreachable
39: ; preds = %31, %28
%40 = tail call i32* @opendir(i8* %0)
%41 = tail call %struct.dirent* @readdir(i32* %40)
%42 = icmp eq %struct.dirent* %41, null
br i1 %42, label %72, label %43
43: ; preds = %39
%44 = bitcast %struct.stat* %5 to i8*
br label %45
45: ; preds = %43, %69
%46 = phi %struct.dirent* [ %41, %43 ], [ %70, %69 ]
%47 = getelementptr inbounds %struct.dirent, %struct.dirent* %46, i64 0, i32 0
%48 = load i8*, i8** %47
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 46
br i1 %50, label %69, label %51
51: ; preds = %45
%52 = tail call i32 @strlen(i8* %0)
%53 = load i8*, i8** %47
%54 = tail call i32 @strlen(i8* %53)
%55 = add i32 %52, 2
%56 = add i32 %55, %54
%57 = tail call i8* @malloc(i32 %56)
%58 = load i8*, i8** %47
%59 = tail call i32 @sprintf(i8* dereferenceable(1) %57, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %58)
%60 = call i32 @lstat(i8* %57, %struct.stat* %5)
%61 = tail call i32 @strlen(i8* %1)
%62 = load i8*, i8** %47
%63 = tail call i32 @strlen(i8* %62)
%64 = add i32 %61, 2
%65 = add i32 %64, %63
%66 = tail call i8* @malloc(i32 %65)
%67 = load i8*, i8** %47
%68 = tail call i32 @sprintf(i8* dereferenceable(1) %66, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %1, i8* %67)
tail call void @sauv_rec(i8* %57, i8* %66)
br label %69
69: ; preds = %51, %45
%70 = tail call %struct.dirent* @readdir(i32* %40)
%71 = icmp eq %struct.dirent* %70, null
br i1 %71, label %72, label %45
72: ; preds = %69, %39, %21
ret void
}