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

/* Variables and functions */
unsigned char DT_BLK;
unsigned char DT_CHR;
unsigned char DT_DIR;
unsigned char DT_FIFO;
unsigned char DT_REG;
unsigned char DT_SOCK;
scalar_t__ EACCES;
int /*<<< orphan*/ checkfile(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewinddir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void checkDirectory(DIR *dir, char *name) {
  struct dirent *dp;
  rewinddir(dir);
  while ((dp = readdir(dir)) != NULL) {
    char *aname = dp->d_name;
    if (0 == strcmp("..", aname)) {
      continue;
    }
    if (0 == strcmp(".", aname)) {
      continue;
    }
    unsigned char entrytype = dp->d_type;
    if ((entrytype == DT_BLK) || (entrytype == DT_CHR) ||
        (entrytype == DT_FIFO) || (entrytype == DT_SOCK)) {
      continue;
    }
    char path[1025];
    strcpy(path, name);
    strcat(path, "/");
    strcat(path, aname);
    struct stat finfo;
    int statresult;
    statresult = lstat(path, &finfo);
    if (statresult != 0) {
      perror("Stat failed for the file: ");
      exit(1);
    }
    if (entrytype == DT_DIR) {
      DIR *subdir;
      subdir = opendir(path);
      if (subdir == NULL) {
        if (errno == EACCES) {
          fprintf(stdout, "Cannot access %s\n", path);
          continue;
        } else {
          perror("Opendir failed");
          exit(1);
        }
      }
      checkDirectory(subdir, path);
      closedir(subdir);
    } else {
      if (entrytype == DT_REG) {
        checkfile(path);
      }
    }
  }
}


x86 assembly (clang, -O0):
<checkDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <rewinddir@plt>
mov    -0x8(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1402 <checkDirectory+0x232>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xde7(%rip),%rdi
call   1090 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1231 <checkDirectory+0x61>
jmp    11ec <checkDirectory+0x1c>
mov    -0x20(%rbp),%rsi
lea    0xdc5(%rip),%rdi
call   1090 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    1254 <checkDirectory+0x84>
jmp    11ec <checkDirectory+0x1c>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%al
mov    %al,-0x21(%rbp)
movzbl -0x21(%rbp),%eax
mov    0x2d57(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
je     12b6 <checkDirectory+0xe6>
movzbl -0x21(%rbp),%eax
mov    0x2d39(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
je     12b6 <checkDirectory+0xe6>
movzbl -0x21(%rbp),%eax
mov    0x2d0b(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
je     12b6 <checkDirectory+0xe6>
movzbl -0x21(%rbp),%eax
mov    0x2ced(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jne    12bb <checkDirectory+0xeb>
jmp    11ec <checkDirectory+0x1c>
lea    -0x430(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x430(%rbp),%rdi
lea    0xd2a(%rip),%rsi
call   10e0 <strcat@plt>
lea    -0x430(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   10e0 <strcat@plt>
lea    -0x430(%rbp),%rdi
lea    -0x438(%rbp),%rsi
call   1080 <lstat@plt>
mov    %eax,-0x43c(%rbp)
cmpl   $0x0,-0x43c(%rbp)
je     132a <checkDirectory+0x15a>
lea    0xcea(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
movzbl -0x21(%rbp),%eax
mov    0x2c9b(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jne    13d6 <checkDirectory+0x206>
lea    -0x430(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x448(%rbp)
cmpq   $0x0,-0x448(%rbp)
jne    13b2 <checkDirectory+0x1e2>
mov    0x2c60(%rip),%rax
mov    (%rax),%rax
mov    0x2c76(%rip),%rcx
cmp    (%rcx),%rax
jne    139c <checkDirectory+0x1cc>
mov    0x2c2e(%rip),%rax
mov    (%rax),%edi
lea    -0x430(%rbp),%rdx
lea    0xc8e(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    11ec <checkDirectory+0x1c>
lea    0xc8f(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x448(%rbp),%rdi
lea    -0x430(%rbp),%rsi
call   10c0 <checkDirectory@plt>
mov    -0x448(%rbp),%rdi
call   1060 <closedir@plt>
jmp    13fd <checkDirectory+0x22d>
movzbl -0x21(%rbp),%eax
mov    0x2bf7(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
jne    13f8 <checkDirectory+0x228>
lea    -0x430(%rbp),%rdi
call   1070 <checkfile@plt>
jmp    13fd <checkDirectory+0x22d>
jmp    11ec <checkDirectory+0x1c>
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkDirectory>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,(%rsp)
mov    %rdi,%r12
call   1050 <rewinddir@plt>
mov    %r12,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     1341 <checkDirectory+0x171>
mov    %rax,%rbp
lea    0xdf8(%rip),%r15
lea    0x10(%rsp),%r13
jmp    1254 <checkDirectory+0x84>
mov    %r13,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     130e <checkDirectory+0x13e>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r13,%rsi
call   10c0 <checkDirectory@plt>
mov    %rbp,%rdi
call   1060 <closedir@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1341 <checkDirectory+0x171>
mov    0x0(%rbp),%r14
mov    %r15,%rdi
mov    %r14,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1240 <checkDirectory+0x70>
lea    0xd92(%rip),%rdi
mov    %r14,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1240 <checkDirectory+0x70>
movzbl 0x8(%rbp),%ebx
mov    0x2d39(%rip),%rax
cmp    (%rax),%bl
je     1240 <checkDirectory+0x70>
mov    0x2d26(%rip),%rax
cmp    (%rax),%bl
je     1240 <checkDirectory+0x70>
mov    0x2d03(%rip),%rax
cmp    (%rax),%bl
je     1240 <checkDirectory+0x70>
mov    0x2cf0(%rip),%rax
cmp    (%rax),%bl
je     1240 <checkDirectory+0x70>
mov    %r13,%rdi
mov    (%rsp),%rsi
call   1030 <strcpy@plt>
mov    %r13,%rdi
lea    0xd41(%rip),%rsi
call   10e0 <strcat@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   10e0 <strcat@plt>
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
call   1080 <lstat@plt>
test   %eax,%eax
jne    1353 <checkDirectory+0x183>
mov    0x2ce6(%rip),%rax
cmp    (%rax),%bl
je     120f <checkDirectory+0x3f>
mov    0x2cdf(%rip),%rax
cmp    (%rax),%bl
jne    1240 <checkDirectory+0x70>
mov    %r13,%rdi
call   1070 <checkfile@plt>
jmp    1240 <checkDirectory+0x70>
mov    0x2cb3(%rip),%rax
mov    (%rax),%rax
mov    0x2cc9(%rip),%rcx
cmp    (%rcx),%rax
jne    1369 <checkDirectory+0x199>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
lea    0xcec(%rip),%rsi
mov    %r13,%rdx
call   10a0 <fprintf@plt>
jmp    1240 <checkDirectory+0x70>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xcab(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xcc2(%rip),%rdi
jmp    135a <checkDirectory+0x18a>

LLVM IR (-O0):
%struct.dirent = type { i8*, i8 }
%struct.stat = type { i32 }
@.str = [3 x i8] c"..\00"
@.str.1 = [2 x i8] c".\00"
@DT_BLK = global i8 0
@DT_CHR = global i8 0
@DT_FIFO = global i8 0
@DT_SOCK = global i8 0
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [27 x i8] c"Stat failed for the file: \00"
@DT_DIR = global i8 0
@errno = global i64 0
@EACCES = global i64 0
@stdout = global i32 0
@.str.4 = [18 x i8] c"Cannot access %s\0A\00"
@.str.5 = [15 x i8] c"Opendir failed\00"
@DT_REG = global i8 0
define void @checkDirectory(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca %struct.dirent*
%6 = alloca i8*
%7 = alloca i8
%8 = alloca [1025 x i8]
%9 = alloca %struct.stat
%10 = alloca i32
%11 = alloca i32*
store i32* %0, i32** %3
store i8* %1, i8** %4
%12 = load i32*, i32** %3
%13 = call i32 @rewinddir(i32* %12)
br label %14
14: ; preds = %112, %90, %58, %30, %25, %2
%15 = load i32*, i32** %3
%16 = call %struct.dirent* @readdir(i32* %15)
store %struct.dirent* %16, %struct.dirent** %5
%17 = icmp ne %struct.dirent* %16, null
br i1 %17, label %18, label %113
18: ; preds = %14
%19 = load %struct.dirent*, %struct.dirent** %5
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i32 0, i32 0
%21 = load i8*, i8** %20
store i8* %21, i8** %6
%22 = load i8*, i8** %6
%23 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = icmp eq i64 0, %23
br i1 %24, label %25, label %26
25: ; preds = %18
br label %14
26: ; preds = %18
%27 = load i8*, i8** %6
%28 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = icmp eq i64 0, %28
br i1 %29, label %30, label %31
30: ; preds = %26
br label %14
31: ; preds = %26
%32 = load %struct.dirent*, %struct.dirent** %5
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 1
%34 = load i8, i8* %33
store i8 %34, i8* %7
%35 = load i8, i8* %7
%36 = zext i8 %35 to i32
%37 = load i8, i8* @DT_BLK
%38 = zext i8 %37 to i32
%39 = icmp eq i32 %36, %38
br i1 %39, label %58, label %40
40: ; preds = %31
%41 = load i8, i8* %7
%42 = zext i8 %41 to i32
%43 = load i8, i8* @DT_CHR
%44 = zext i8 %43 to i32
%45 = icmp eq i32 %42, %44
br i1 %45, label %58, label %46
46: ; preds = %40
%47 = load i8, i8* %7
%48 = zext i8 %47 to i32
%49 = load i8, i8* @DT_FIFO
%50 = zext i8 %49 to i32
%51 = icmp eq i32 %48, %50
br i1 %51, label %58, label %52
52: ; preds = %46
%53 = load i8, i8* %7
%54 = zext i8 %53 to i32
%55 = load i8, i8* @DT_SOCK
%56 = zext i8 %55 to i32
%57 = icmp eq i32 %54, %56
br i1 %57, label %58, label %59
58: ; preds = %52, %46, %40, %31
br label %14
59: ; preds = %52
%60 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%61 = load i8*, i8** %4
%62 = call i32 @strcpy(i8* %60, i8* %61)
%63 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%64 = call i32 @strcat(i8* %63, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%65 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%66 = load i8*, i8** %6
%67 = call i32 @strcat(i8* %65, i8* %66)
%68 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%69 = call i32 @lstat(i8* %68, %struct.stat* %9)
store i32 %69, i32* %10
%70 = load i32, i32* %10
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %59
%73 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %59
%76 = load i8, i8* %7
%77 = zext i8 %76 to i32
%78 = load i8, i8* @DT_DIR
%79 = zext i8 %78 to i32
%80 = icmp eq i32 %77, %79
br i1 %80, label %81, label %102
81: ; preds = %75
%82 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%83 = call i32* @opendir(i8* %82)
store i32* %83, i32** %11
%84 = load i32*, i32** %11
%85 = icmp eq i32* %84, null
br i1 %85, label %86, label %97
86: ; preds = %81
%87 = load i64, i64* @errno
%88 = load i64, i64* @EACCES
%89 = icmp eq i64 %87, %88
br i1 %89, label %90, label %94
90: ; preds = %86
%91 = load i32, i32* @stdout
%92 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%93 = call i32 @fprintf(i32 %91, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %92)
br label %14
94: ; preds = %86
%95 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%96 = call i32 @exit(i32 1)
unreachable
97: ; preds = %81
%98 = load i32*, i32** %11
%99 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%100 = load i32*, i32** %11
%101 = call i32 @closedir(i32* %100)
br label %112
102: ; preds = %75
%103 = load i8, i8* %7
%104 = zext i8 %103 to i32
%105 = load i8, i8* @DT_REG
%106 = zext i8 %105 to i32
%107 = icmp eq i32 %104, %106
br i1 %107, label %108, label %111
108: ; preds = %102
%109 = getelementptr inbounds [1025 x i8], [1025 x i8]* %8, i64 0, i64 0
%110 = call i32 @checkfile(i8* %109)
br label %111
111: ; preds = %108, %102
br label %112
112: ; preds = %111, %97
br label %14
113: ; preds = %14
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8*, i8 }
@.str = [3 x i8] c"..\00"
@.str.1 = [2 x i8] c".\00"
@DT_BLK = global i8 0
@DT_CHR = global i8 0
@DT_FIFO = global i8 0
@DT_SOCK = global i8 0
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [27 x i8] c"Stat failed for the file: \00"
@DT_DIR = global i8 0
@errno = global i64 0
@EACCES = global i64 0
@stdout = global i32 0
@.str.4 = [18 x i8] c"Cannot access %s\0A\00"
@.str.5 = [15 x i8] c"Opendir failed\00"
@DT_REG = global i8 0
define void @checkDirectory(i32* %0, i8* %1) {
%3 = alloca [1025 x i8]
%4 = alloca %struct.stat
%5 = tail call i32 @rewinddir(i32* %0)
%6 = call %struct.dirent* @readdir(i32* %0)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %70, label %8
8: ; preds = %2
%9 = getelementptr inbounds [1025 x i8], [1025 x i8]* %3, i64 0, i64 0
%10 = bitcast %struct.stat* %4 to i8*
br label %11
11: ; preds = %8, %67
%12 = phi %struct.dirent* [ %6, %8 ], [ %68, %67 ]
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %67, label %17
17: ; preds = %11
%18 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%19 = icmp eq i64 %18, 0
br i1 %19, label %67, label %20
20: ; preds = %17
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 1
%22 = load i8, i8* %21
%23 = load i8, i8* @DT_BLK
%24 = icmp eq i8 %22, %23
%25 = load i8, i8* @DT_CHR
%26 = icmp eq i8 %22, %25
%27 = select i1 %24, i1 true, i1 %26
%28 = load i8, i8* @DT_FIFO
%29 = icmp eq i8 %22, %28
%30 = select i1 %27, i1 true, i1 %29
%31 = load i8, i8* @DT_SOCK
%32 = icmp eq i8 %22, %31
%33 = select i1 %30, i1 true, i1 %32
br i1 %33, label %67, label %34
34: ; preds = %20
%35 = call i32 @strcpy(i8* %9, i8* %1)
%36 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%37 = call i32 @strcat(i8* %9, i8* %14)
%38 = call i32 @lstat(i8* %9, %struct.stat* %4)
%39 = icmp eq i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %34
%41 = call i32 @perror(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %34
%44 = load i8, i8* @DT_DIR
%45 = icmp eq i8 %22, %44
br i1 %45, label %46, label %61
46: ; preds = %43
%47 = call i32* @opendir(i8* %9)
%48 = icmp eq i32* %47, null
br i1 %48, label %49, label %59
49: ; preds = %46
%50 = load i64, i64* @errno
%51 = load i64, i64* @EACCES
%52 = icmp eq i64 %50, %51
br i1 %52, label %53, label %56
53: ; preds = %49
%54 = load i32, i32* @stdout
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i8* %9)
br label %66
56: ; preds = %49
%57 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %46
%60 = call i32 @closedir(i32* %47)
br label %66
61: ; preds = %43
%62 = load i8, i8* @DT_REG
%63 = icmp eq i8 %22, %62
br i1 %63, label %64, label %66
64: ; preds = %61
%65 = call i32 @checkfile(i8* %9)
br label %66
66: ; preds = %53, %59, %64, %61
br label %67
67: ; preds = %66, %20, %17, %11
%68 = call %struct.dirent* @readdir(i32* %0)
%69 = icmp eq %struct.dirent* %68, null
br i1 %69, label %70, label %11
70: ; preds = %67, %2
ret void
}