#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 const *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ lstat(char const *, struct stat *);
char *malloc(int);
int /*<<< orphan*/ mkdir(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const *);
scalar_t__ strcmp(char const *, char *);
int strlen(char const *);
void sauv_rec(const char *src, const char *dest) {
  struct stat source;
  lstat(src, &source);
  struct stat destination;
  lstat(dest, &destination);
  if (!S_ISDIR(source.st_mode)) {
    exit(-1);
  }
  if (!S_ISDIR(destination.st_mode)) {
    mkdir(dest, source.st_mode);
  }
  DIR *dir;
  dir = opendir(src);
  struct dirent *entry;
  while ((entry = readdir(dir)) != NULL) {
    printf("%s", src);
    if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
      continue;
    }
    char *chSrc =
        malloc(sizeof(char) * (strlen(src) + strlen(entry->d_name) + 2));
    sprintf(chSrc, "%s/%s", src, entry->d_name);
    struct stat tmp;
    lstat(chSrc, &tmp);
    if (S_ISDIR(tmp.st_mode)) {
      printf("%s\n", src);
      char *chDest =
          malloc(sizeof(char) * (strlen(dest) + strlen(entry->d_name) + 2));
      sprintf(chDest, "%s/%s", dest, entry->d_name);
      sauv_rec(chSrc, chDest);
    }
  }
}


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   1090 <lstat@plt>
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <lstat@plt>
mov    -0x18(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%rax
jne    1206 <sauv_rec+0x46>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x20(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%rax
jne    1224 <sauv_rec+0x64>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1030 <mkdir@plt>
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     1374 <sauv_rec+0x1b4>
mov    -0x8(%rbp),%rsi
lea    0xdb3(%rip),%rdi
call   1070 <printf@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
lea    0xd9b(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1292 <sauv_rec+0xd2>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
lea    0xd7d(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1297 <sauv_rec+0xd7>
jmp    1231 <sauv_rec+0x71>
mov    -0x8(%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   10c0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    (%rax),%rcx
lea    0xd23(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x40(%rbp),%rsi
call   1090 <lstat@plt>
mov    -0x40(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%rax
je     136f <sauv_rec+0x1af>
mov    -0x8(%rbp),%rsi
lea    0xcfa(%rip),%rdi
call   1070 <printf@plt>
mov    -0x10(%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   10c0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x30(%rbp),%rax
mov    (%rax),%rcx
lea    0xca6(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1040 <sauv_rec@plt>
jmp    1231 <sauv_rec+0x71>
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
mov    %rdi,%r15
lea    0x10(%rsp),%rsi
call   1090 <lstat@plt>
lea    0x8(%rsp),%rsi
mov    %rbx,0x18(%rsp)
mov    %rbx,%rdi
call   1090 <lstat@plt>
mov    0x10(%rsp),%ebp
mov    %ebp,%edi
call   1080 <S_ISDIR@plt>
test   %rax,%rax
je     136a <sauv_rec+0x1aa>
mov    0x8(%rsp),%edi
call   1080 <S_ISDIR@plt>
test   %rax,%rax
jne    121e <sauv_rec+0x5e>
mov    0x18(%rsp),%rdi
mov    %ebp,%esi
call   1030 <mkdir@plt>
mov    %r15,%rdi
call   1050 <opendir@plt>
mov    %rax,0x20(%rsp)
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     135b <sauv_rec+0x19b>
mov    %rax,%rbp
lea    0xdc0(%rip),%r13
lea    0xdb4(%rip),%rbx
lea    0xdaf(%rip),%r12
jmp    127d <sauv_rec+0xbd>
cs nopw 0x0(%rax,%rax,1)
lea    0xd9a(%rip),%rbx
mov    0x20(%rsp),%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     135b <sauv_rec+0x19b>
mov    %r13,%rdi
mov    %r15,%rsi
call   1070 <printf@plt>
mov    0x0(%rbp),%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1267 <sauv_rec+0xa7>
mov    0x0(%rbp),%rdi
lea    0xd5c(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1267 <sauv_rec+0xa7>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%rdi
call   1060 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   10c0 <malloc@plt>
mov    %rax,%r14
mov    0x0(%rbp),%rcx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   10d0 <sprintf@plt>
mov    %r14,%rdi
mov    %rsp,%rsi
call   1090 <lstat@plt>
mov    (%rsp),%edi
call   1080 <S_ISDIR@plt>
test   %rax,%rax
je     1260 <sauv_rec+0xa0>
lea    0xd05(%rip),%rdi
mov    %r15,%rsi
call   1070 <printf@plt>
mov    0x18(%rsp),%r13
mov    %r13,%rdi
call   1060 <strlen@plt>
mov    %eax,%ebx
mov    0x0(%rbp),%rdi
call   1060 <strlen@plt>
lea    (%rbx,%rax,1),%edi
add    $0x2,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%rcx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
lea    0xcc0(%rip),%r13
call   10d0 <sprintf@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <sauv_rec@plt>
jmp    1260 <sauv_rec+0xa0>
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0xffffffff,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [4 x i8] c"%s\0A\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 i8*
%10 = alloca %struct.stat
%11 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%12 = load i8*, i8** %3
%13 = call i32 @lstat(i8* %12, %struct.stat* %5)
%14 = load i8*, i8** %4
%15 = call i32 @lstat(i8* %14, %struct.stat* %6)
%16 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i64 @S_ISDIR(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %22, label %20
20: ; preds = %2
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %2
%23 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i64 @S_ISDIR(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %22
%28 = load i8*, i8** %4
%29 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @mkdir(i8* %28, i32 %30)
br label %32
32: ; preds = %27, %22
%33 = load i8*, i8** %3
%34 = call i32* @opendir(i8* %33)
store i32* %34, i32** %7
br label %35
35: ; preds = %102, %53, %32
%36 = load i32*, i32** %7
%37 = call %struct.dirent* @readdir(i32* %36)
store %struct.dirent* %37, %struct.dirent** %8
%38 = icmp ne %struct.dirent* %37, null
br i1 %38, label %39, label %103
39: ; preds = %35
%40 = load i8*, i8** %3
%41 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %40)
%42 = load %struct.dirent*, %struct.dirent** %8
%43 = getelementptr inbounds %struct.dirent, %struct.dirent* %42, i32 0, i32 0
%44 = load i8*, i8** %43
%45 = call i64 @strcmp(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%46 = icmp eq i64 %45, 0
br i1 %46, label %53, label %47
47: ; preds = %39
%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 ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %54
53: ; preds = %47, %39
br label %35
54: ; preds = %47
%55 = load i8*, i8** %3
%56 = call i32 @strlen(i8* %55)
%57 = load %struct.dirent*, %struct.dirent** %8
%58 = getelementptr inbounds %struct.dirent, %struct.dirent* %57, i32 0, i32 0
%59 = load i8*, i8** %58
%60 = call i32 @strlen(i8* %59)
%61 = add nsw i32 %56, %60
%62 = add nsw i32 %61, 2
%63 = sext i32 %62 to i64
%64 = mul i64 1, %63
%65 = trunc i64 %64 to i32
%66 = call i8* @malloc(i32 %65)
store i8* %66, i8** %9
%67 = load i8*, i8** %9
%68 = load i8*, i8** %3
%69 = load %struct.dirent*, %struct.dirent** %8
%70 = getelementptr inbounds %struct.dirent, %struct.dirent* %69, i32 0, i32 0
%71 = load i8*, i8** %70
%72 = call i32 @sprintf(i8* %67, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %68, i8* %71)
%73 = load i8*, i8** %9
%74 = call i32 @lstat(i8* %73, %struct.stat* %10)
%75 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%76 = load i32, i32* %75
%77 = call i64 @S_ISDIR(i32 %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %102
79: ; preds = %54
%80 = load i8*, i8** %3
%81 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %80)
%82 = load i8*, i8** %4
%83 = call i32 @strlen(i8* %82)
%84 = load %struct.dirent*, %struct.dirent** %8
%85 = getelementptr inbounds %struct.dirent, %struct.dirent* %84, i32 0, i32 0
%86 = load i8*, i8** %85
%87 = call i32 @strlen(i8* %86)
%88 = add nsw i32 %83, %87
%89 = add nsw i32 %88, 2
%90 = sext i32 %89 to i64
%91 = mul i64 1, %90
%92 = trunc i64 %91 to i32
%93 = call i8* @malloc(i32 %92)
store i8* %93, i8** %11
%94 = load i8*, i8** %11
%95 = load i8*, i8** %4
%96 = load %struct.dirent*, %struct.dirent** %8
%97 = getelementptr inbounds %struct.dirent, %struct.dirent* %96, i32 0, i32 0
%98 = load i8*, i8** %97
%99 = call i32 @sprintf(i8* %94, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %95, i8* %98)
%100 = load i8*, i8** %9
%101 = load i8*, i8** %11
br label %102
102: ; preds = %79, %54
br label %35
103: ; preds = %35
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [4 x i8] c"%s\0A\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 = call i32 @lstat(i8* %0, %struct.stat* %3)
%8 = bitcast %struct.stat* %4 to i8*
%9 = call i32 @lstat(i8* %1, %struct.stat* %4)
%10 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%11 = load i32, i32* %10
%12 = tail call i64 @S_ISDIR(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%18 = load i32, i32* %17
%19 = tail call i64 @S_ISDIR(i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %16
%22 = tail call i32 @mkdir(i8* %1, i32 %11)
br label %23
23: ; preds = %21, %16
%24 = tail call i32* @opendir(i8* %0)
%25 = tail call %struct.dirent* @readdir(i32* %24)
%26 = icmp eq %struct.dirent* %25, null
br i1 %26, label %68, label %27
27: ; preds = %23
%28 = bitcast %struct.stat* %5 to i8*
%29 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
br label %30
30: ; preds = %27, %41
%31 = phi %struct.dirent* [ %25, %27 ], [ %42, %41 ]
%32 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i64 0, i32 0
%34 = load i8*, i8** %33
%35 = tail call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %41, label %37
37: ; preds = %30
%38 = load i8*, i8** %33
%39 = tail call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %30, %37, %67
%42 = tail call %struct.dirent* @readdir(i32* %24)
%43 = icmp eq %struct.dirent* %42, null
br i1 %43, label %68, label %30
44: ; preds = %37
%45 = tail call i32 @strlen(i8* %0)
%46 = load i8*, i8** %33
%47 = tail call i32 @strlen(i8* %46)
%48 = add i32 %45, 2
%49 = add i32 %48, %47
%50 = tail call i8* @malloc(i32 %49)
%51 = load i8*, i8** %33
%52 = tail call i32 @sprintf(i8* dereferenceable(1) %50, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %51)
%53 = call i32 @lstat(i8* %50, %struct.stat* %5)
%54 = load i32, i32* %29
%55 = tail call i64 @S_ISDIR(i32 %54)
%56 = icmp eq i64 %55, 0
br i1 %56, label %67, label %57
57: ; preds = %44
%58 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %0)
%59 = tail call i32 @strlen(i8* %1)
%60 = load i8*, i8** %33
%61 = tail call i32 @strlen(i8* %60)
%62 = add i32 %59, 2
%63 = add i32 %62, %61
%64 = tail call i8* @malloc(i32 %63)
%65 = load i8*, i8** %33
%66 = tail call i32 @sprintf(i8* dereferenceable(1) %64, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %65)
tail call void @sauv_rec(i8* %50, i8* %64)
br label %67
67: ; preds = %57, %44
br label %41
68: ; preds = %41, %23
ret void
}