#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*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
char *malloc(int);
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 myread(char *path) {
  struct dirent *structdir;
  DIR *pdir;
  struct stat buff;
  char *fullpath;
  fullpath = malloc(100 * sizeof(char));
  if ((pdir = opendir(path)) == NULL) {
    fprintf(stdout, "Errore\n");
    exit(2);
  }
  while ((structdir = readdir(pdir)) != NULL) {
    if (stat(path, &buff) < 0) {
      fprintf(stdout, "Errore\n");
      exit(3);
    }
    if (S_ISDIR(buff.st_mode)) {
      sprintf(fullpath, "%s/%s", path, structdir->d_name);
      stat(fullpath, &buff);
      if (S_ISDIR(buff.st_mode)) {
        fprintf(stdout, "DIR:  %s\n", fullpath);
        if (strcmp(".", structdir->d_name) && strcmp("..", structdir->d_name))
          myread(fullpath);
      } else if (S_ISREG(buff.st_mode))
        fprintf(stdout, "FILE: %s\n", fullpath);
    } else {
      fprintf(stdout, "FILE: %s/%s\n", path, structdir->d_name);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<myread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x64,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1202 <myread+0x52>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <exit@plt>
jmp    1207 <myread+0x57>
mov    -0x18(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1363 <myread+0x1b3>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
jge    1256 <myread+0xa6>
mov    0x2da4(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>
mov    -0x20(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     133c <myread+0x18c>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xd8a(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <stat@plt>
mov    -0x20(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1305 <myread+0x155>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd58(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd4e(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1300 <myread+0x150>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd30(%rip),%rdi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1300 <myread+0x150>
mov    -0x28(%rbp),%rdi
call   1030 <myread@plt>
jmp    1337 <myread+0x187>
mov    -0x20(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     1332 <myread+0x182>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xcf0(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1337 <myread+0x187>
jmp    135e <myread+0x1ae>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xcce(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    1207 <myread+0x57>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<myread>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x64,%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1326 <myread+0x176>
mov    %rax,%r15
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12fa <myread+0x14a>
mov    %rax,%r13
mov    %rsp,%r12
mov    0x2de3(%rip),%rbp
jmp    122c <myread+0x7c>
nop
mov    0x0(%rbp),%edi
mov    0x0(%r13),%rcx
lea    0xe17(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     12fa <myread+0x14a>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <stat@plt>
test   %rax,%rax
js     130b <myread+0x15b>
mov    (%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     1200 <myread+0x50>
mov    0x0(%r13),%rcx
mov    %r14,%rdi
lea    0xdad(%rip),%rsi
mov    %rbx,%rdx
call   10c0 <sprintf@plt>
mov    %r14,%rdi
mov    %r12,%rsi
call   1080 <stat@plt>
mov    (%rsp),%edi
call   1050 <S_ISDIR@plt>
test   %rax,%rax
je     12d0 <myread+0x120>
mov    0x0(%rbp),%edi
lea    0xd89(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x0(%r13),%rsi
lea    0xd7f(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1218 <myread+0x68>
mov    0x0(%r13),%rsi
lea    0xd65(%rip),%rdi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1218 <myread+0x68>
mov    %r14,%rdi
call   1030 <myread@plt>
jmp    1218 <myread+0x68>
xchg   %ax,%ax
mov    (%rsp),%edi
call   1090 <S_ISREG@plt>
test   %rax,%rax
je     1218 <myread+0x68>
mov    0x0(%rbp),%edi
lea    0xd30(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1218 <myread+0x68>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%rbp),%edi
lea    0xceb(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x3,%edi
call   10d0 <exit@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
lea    0xcca(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0x2,%edi
call   10d0 <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 = [10 x i8] c"DIR: %s\0A\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [3 x i8] c"..\00"
@.str.5 = [10 x i8] c"FILE: %s\0A\00"
@.str.6 = [13 x i8] c"FILE: %s/%s\0A\00"
define i32 @myread(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.dirent*
%4 = alloca i32*
%5 = alloca %struct.stat
%6 = alloca i8*
store i8* %0, i8** %2
%7 = call i8* @malloc(i32 100)
store i8* %7, i8** %6
%8 = load i8*, i8** %2
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @stdout
%13 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 2)
unreachable
15: ; preds = %1
br label %16
16: ; preds = %83, %15
%17 = load i32*, i32** %4
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %3
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %84
20: ; preds = %16
%21 = load i8*, i8** %2
%22 = call i64 @stat(i8* %21, %struct.stat* %5)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = load i32, i32* @stdout
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%27 = call i32 @exit(i32 3)
unreachable
28: ; preds = %20
%29 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i64 @S_ISDIR(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %76
33: ; preds = %28
%34 = load i8*, i8** %6
%35 = load i8*, i8** %2
%36 = load %struct.dirent*, %struct.dirent** %3
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i32 @sprintf(i8* %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %35, i8* %38)
%40 = load i8*, i8** %6
%41 = call i64 @stat(i8* %40, %struct.stat* %5)
%42 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i64 @S_ISDIR(i32 %43)
%45 = icmp ne i64 %44, 0
br i1 %45, label %46, label %65
46: ; preds = %33
%47 = load i32, i32* @stdout
%48 = load i8*, i8** %6
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %48)
%50 = load %struct.dirent*, %struct.dirent** %3
%51 = getelementptr inbounds %struct.dirent, %struct.dirent* %50, i32 0, i32 0
%52 = load i8*, i8** %51
%53 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %64
55: ; preds = %46
%56 = load %struct.dirent*, %struct.dirent** %3
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %56, i32 0, i32 0
%58 = load i8*, i8** %57
%59 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %58)
%60 = icmp ne i64 %59, 0
br i1 %60, label %61, label %64
61: ; preds = %55
%62 = load i8*, i8** %6
%63 = call i32 @myread(i8* %62)
br label %64
64: ; preds = %61, %55, %46
br label %75
65: ; preds = %33
%66 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i64 @S_ISREG(i32 %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %65
%71 = load i32, i32* @stdout
%72 = load i8*, i8** %6
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %72)
br label %74
74: ; preds = %70, %65
br label %75
75: ; preds = %74, %64
br label %83
76: ; preds = %28
%77 = load i32, i32* @stdout
%78 = load i8*, i8** %2
%79 = load %struct.dirent*, %struct.dirent** %3
%80 = getelementptr inbounds %struct.dirent, %struct.dirent* %79, i32 0, i32 0
%81 = load i8*, i8** %80
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %77, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %78, i8* %81)
br label %83
83: ; preds = %76, %75
br label %16
84: ; preds = %16
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 = [10 x i8] c"DIR: %s\0A\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [3 x i8] c"..\00"
@.str.5 = [10 x i8] c"FILE: %s\0A\00"
@.str.6 = [13 x i8] c"FILE: %s/%s\0A\00"
define i32 @myread(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%5 = tail call i32* @opendir(i8* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %12, label %7
7: ; preds = %1
%8 = call %struct.dirent* @readdir(i32* %5)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %63, label %10
10: ; preds = %7
%11 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %16
12: ; preds = %1
%13 = load i32, i32* @stdout
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 2)
unreachable
16: ; preds = %10, %60
%17 = phi %struct.dirent* [ %8, %10 ], [ %61, %60 ]
%18 = call i64 @stat(i8* %0, %struct.stat* %2)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = load i32, i32* @stdout
%22 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 3)
unreachable
24: ; preds = %16
%25 = load i32, i32* %11
%26 = call i64 @S_ISDIR(i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %55, label %28
28: ; preds = %24
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 0
%30 = load i8*, i8** %29
%31 = call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %30)
%32 = call i64 @stat(i8* %4, %struct.stat* %2)
%33 = load i32, i32* %11
%34 = call i64 @S_ISDIR(i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %48, label %36
36: ; preds = %28
%37 = load i32, i32* @stdout
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%39 = load i8*, i8** %29
%40 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = icmp eq i64 %40, 0
br i1 %41, label %60, label %42
42: ; preds = %36
%43 = load i8*, i8** %29
%44 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %43)
%45 = icmp eq i64 %44, 0
br i1 %45, label %60, label %46
46: ; preds = %42
%47 = call i32 @myread(i8* %4)
br label %60
48: ; preds = %28
%49 = load i32, i32* %11
%50 = call i64 @S_ISREG(i32 %49)
%51 = icmp eq i64 %50, 0
br i1 %51, label %60, label %52
52: ; preds = %48
%53 = load i32, i32* @stdout
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %4)
br label %60
55: ; preds = %24
%56 = load i32, i32* @stdout
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 0
%58 = load i8*, i8** %57
%59 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %0, i8* %58)
br label %60
60: ; preds = %46, %42, %36, %52, %48, %55
%61 = call %struct.dirent* @readdir(i32* %5)
%62 = icmp eq %struct.dirent* %61, null
br i1 %62, label %63, label %16
63: ; preds = %60, %7
ret i32 0
}