#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 S_IRUSR;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int S_IWUSR;
int S_IXUSR;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *malloc(int);
scalar_t__ mkdir(char *, int);
int /*<<< orphan*/ mycopyf(char *, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int mycopy(char *spath, char *dpath) {
  DIR *pdirs;
  DIR *pdird;
  struct dirent *pstdir;
  struct stat pstat;
  char *rfilename, *wfilename;
  rfilename = malloc(4096 * sizeof(char));
  wfilename = malloc(4096 * sizeof(char));
  if ((pdirs = opendir(spath)) == NULL) {
    fprintf(stdout, "Errore\n");
    exit(2);
  }
  while ((pstdir = readdir(pdirs)) != NULL) {
    sprintf(rfilename, "%s/%s", spath, pstdir->d_name);
    sprintf(wfilename, "%s/%s", dpath, pstdir->d_name);
    if (stat(rfilename, &pstat) < 0) {
      fprintf(stdout, "Errore\n");
      exit(3);
    }
    if (S_ISDIR(pstat.st_mode) && strcmp(".", pstdir->d_name) &&
        strcmp("..", pstdir->d_name)) {
      if (mkdir(wfilename, S_IRUSR | S_IWUSR | S_IXUSR) < 0) {
        fprintf(stdout, "Errore %s\n", rfilename);
        exit(4);
      }
      fprintf(stdout, "%-30s %-30s\n", rfilename, wfilename);
      mycopy(rfilename, wfilename);
    } else if (S_ISREG(pstat.st_mode)) {
      fprintf(stdout, "%-30s %-30s\n", rfilename, wfilename);
      mycopyf(rfilename, wfilename);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<mycopy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1000,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    $0x1000,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1234 <mycopy+0x64>
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>
jmp    1239 <mycopy+0x69>
mov    -0x18(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     13d6 <mycopy+0x206>
mov    -0x38(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
lea    0xda2(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x40(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    (%rax),%rcx
lea    0xd87(%rip),%rsi
call   10e0 <sprintf@plt>
mov    -0x38(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
jge    12be <mycopy+0xee>
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x3,%edi
call   10f0 <exit@plt>
mov    -0x30(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     138e <mycopy+0x1be>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    0xd31(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     138e <mycopy+0x1be>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    0xd13(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     138e <mycopy+0x1be>
mov    -0x40(%rbp),%rdi
mov    0x2cbb(%rip),%rax
mov    (%rax),%esi
mov    0x2cc2(%rip),%rax
or     (%rax),%esi
mov    0x2cc1(%rip),%rax
or     (%rax),%esi
call   1030 <mkdir@plt>
cmp    $0x0,%rax
jge    135d <mycopy+0x18d>
mov    0x2c89(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xcc5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x4,%edi
call   10f0 <exit@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xca7(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   10a0 <mycopy@plt>
jmp    13d1 <mycopy+0x201>
mov    -0x30(%rbp),%edi
call   10b0 <S_ISREG@plt>
cmp    $0x0,%rax
je     13cc <mycopy+0x1fc>
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    0xc64(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%rsi
call   1040 <mycopyf@plt>
jmp    13d1 <mycopy+0x201>
jmp    1239 <mycopy+0x69>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mycopy>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,0x10(%rsp)
mov    %rdi,%r15
mov    $0x1000,%edi
call   10d0 <malloc@plt>
mov    %rax,%rbx
mov    $0x1000,%edi
call   10d0 <malloc@plt>
mov    %rax,%r12
mov    %r15,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     13ac <mycopy+0x1dc>
mov    %rax,%r13
mov    %rax,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
je     135f <mycopy+0x18f>
mov    %rax,%r14
lea    0xdd9(%rip),%rbp
jmp    12a8 <mycopy+0xd8>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2d99(%rip),%rax
mov    (%rax),%esi
mov    0x2d80(%rip),%rax
or     (%rax),%esi
mov    0x2d8f(%rip),%rax
or     (%rax),%esi
mov    %r12,%rdi
call   1030 <mkdir@plt>
mov    0x2d5e(%rip),%rcx
mov    (%rcx),%edi
test   %rax,%rax
js     1391 <mycopy+0x1c1>
lea    0xda0(%rip),%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10a0 <mycopy@plt>
mov    %r13,%rdi
call   10c0 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     135f <mycopy+0x18f>
mov    (%r14),%rcx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   10e0 <sprintf@plt>
mov    (%r14),%rcx
mov    %r12,%rdi
mov    %rbp,%rsi
mov    0x10(%rsp),%rdx
call   10e0 <sprintf@plt>
mov    %rbx,%rdi
lea    0x8(%rsp),%rsi
call   1090 <stat@plt>
test   %rax,%rax
js     1370 <mycopy+0x1a0>
mov    0x8(%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     1320 <mycopy+0x150>
mov    (%r14),%rsi
lea    0xd15(%rip),%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1320 <mycopy+0x150>
mov    (%r14),%rsi
lea    0xd00(%rip),%rdi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1240 <mycopy+0x70>
nopl   0x0(%rax)
mov    0x8(%rsp),%edi
call   10b0 <S_ISREG@plt>
test   %rax,%rax
je     1294 <mycopy+0xc4>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
lea    0xcda(%rip),%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <mycopyf@plt>
jmp    1294 <mycopy+0xc4>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c51(%rip),%rax
mov    (%rax),%edi
lea    0xc80(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x3,%edi
call   10f0 <exit@plt>
lea    0xc79(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x4,%edi
call   10f0 <exit@plt>
mov    0x2c15(%rip),%rax
mov    (%rax),%edi
lea    0xc44(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%edi
call   10f0 <exit@plt>

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

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