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

/* Variables and functions */
int DT_DIR;
int /*<<< orphan*/ EXIT_FAILURE;
int PATH_MAX;
int /*<<< orphan*/ addWatch(char const *, int const, int const);
scalar_t__ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
char *strerror(int /*<<< orphan*/);
void mapDirectory(const char *directoryName, const int targetIndex,
                  const int iNotifyInstance) {
  addWatch(directoryName, targetIndex, iNotifyInstance);
  DIR *directory;
  directory = opendir(directoryName);
  if (!directory) {
    fprintf(stderr, "Cannot open directory '%s': %s\n", directoryName,
            strerror(errno));
  } else {
    while (1) {
      struct dirent *entry;
      const char *dName;
      entry = readdir(directory);
      if (!entry) {
        break;
      }
      dName = entry->d_name;
      if (entry->d_type & DT_DIR) {
        if (strcmp(dName, "..") != 0 && strcmp(dName, ".") != 0 &&
            strcmp(dName, ".svn") != 0 && strcmp(dName, "DEBIAN") != 0) {
          int pathLength;
          char path[PATH_MAX];
          pathLength = snprintf(path, PATH_MAX, "%s/%s", directoryName, dName);
          if (pathLength >= PATH_MAX) {
            fprintf(stderr, "Path length has got too long.\n");
            exit(EXIT_FAILURE);
          }
          mapDirectory(path, targetIndex, iNotifyInstance);
        }
      }
    }
    if (closedir(directory)) {
      fprintf(stderr, "Could not close '%s': %s\n", directoryName,
              strerror(errno));
    }
  }
}


x86 assembly (clang, -O0):
<mapDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   10a0 <addWatch@plt>
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1218 <mapDirectory+0x78>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xdf4(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    13bb <mapDirectory+0x21b>
jmp    121d <mapDirectory+0x7d>
mov    -0x18(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    123a <mapDirectory+0x9a>
jmp    1369 <mapDirectory+0x1c9>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%eax
mov    0x2d7d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1364 <mapDirectory+0x1c4>
mov    -0x28(%rbp),%rdi
lea    0xdb7(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     135f <mapDirectory+0x1bf>
mov    -0x28(%rbp),%rdi
lea    0xd9e(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     135f <mapDirectory+0x1bf>
mov    -0x28(%rbp),%rdi
lea    0xd86(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     135f <mapDirectory+0x1bf>
mov    -0x28(%rbp),%rdi
lea    0xd71(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     135f <mapDirectory+0x1bf>
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x58(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x40(%rbp)
mov    0x2cf7(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xd25(%rip),%rdx
call   1050 <snprintf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2cd4(%rip),%rcx
cmp    (%rcx),%eax
jl     1349 <mapDirectory+0x1a9>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
lea    0xd01(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x58(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1040 <mapDirectory@plt>
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
jmp    1364 <mapDirectory+0x1c4>
jmp    121d <mapDirectory+0x7d>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
cmp    $0x0,%rax
je     13b6 <mapDirectory+0x216>
mov    0x2c55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2c31(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xca5(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    13bb <mapDirectory+0x21b>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mapDirectory>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r14
mov    %esi,-0x2c(%rbp)
mov    %edx,-0x30(%rbp)
call   10a0 <addWatch@plt>
mov    %r14,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     131b <mapDirectory+0x17b>
mov    %rax,%r12
mov    %r14,-0x38(%rbp)
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     12d1 <mapDirectory+0x131>
mov    0x2de1(%rip),%rbx
lea    0xe2a(%rip),%r14
lea    0xe24(%rip),%r13
jmp    1211 <mapDirectory+0x71>
nop
mov    %r12,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     12d1 <mapDirectory+0x131>
mov    (%rbx),%ecx
test   %ecx,0x8(%rax)
je     1200 <mapDirectory+0x60>
mov    (%rax),%r15
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1200 <mapDirectory+0x60>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1200 <mapDirectory+0x60>
mov    %r15,%rdi
lea    0xdde(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1200 <mapDirectory+0x60>
mov    %r15,%rdi
lea    0xdcf(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1200 <mapDirectory+0x60>
mov    %r14,%rbx
mov    %rsp,%r13
mov    0x2d80(%rip),%rcx
mov    (%rcx),%eax
mov    %rsp,%r14
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    (%rcx),%esi
mov    %r14,%rdi
lea    0xda0(%rip),%rdx
mov    -0x38(%rbp),%rcx
mov    %r15,%r8
call   1050 <snprintf@plt>
mov    0x2d4e(%rip),%rcx
cmp    (%rcx),%eax
jge    1356 <mapDirectory+0x1b6>
mov    %r14,%rdi
mov    -0x2c(%rbp),%esi
mov    -0x30(%rbp),%edx
call   1040 <mapDirectory@plt>
mov    %r13,%rsp
mov    %rbx,%r14
mov    0x2d0b(%rip),%rbx
lea    0xd55(%rip),%r13
jmp    1200 <mapDirectory+0x60>
mov    %r12,%rdi
call   1060 <closedir@plt>
test   %rax,%rax
je     130c <mapDirectory+0x16c>
mov    0x2cf3(%rip),%rax
mov    (%rax),%ebx
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd58(%rip),%rsi
mov    %ebx,%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cb6(%rip),%rax
mov    (%rax),%ebx
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xcc7(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <fprintf@plt>
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
lea    0xccf(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2c4c(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8*, i32 }
@stderr = global i32 0
@.str = [32 x i8] c"Cannot open directory '%s': %s\0A\00"
@errno = global i32 0
@DT_DIR = global i32 0
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [5 x i8] c".svn\00"
@.str.4 = [7 x i8] c"DEBIAN\00"
@PATH_MAX = global i32 0
@.str.5 = [6 x i8] c"%s/%s\00"
@.str.6 = [31 x i8] c"Path length has got too long.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [26 x i8] c"Could not close '%s': %s\0A\00"
define void @mapDirectory(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%13 = load i8*, i8** %4
%14 = load i32, i32* %5
%15 = load i32, i32* %6
%16 = call i32 @addWatch(i8* %13, i32 %14, i32 %15)
%17 = load i8*, i8** %4
%18 = call i32* @opendir(i8* %17)
store i32* %18, i32** %7
%19 = load i32*, i32** %7
%20 = icmp ne i32* %19, null
br i1 %20, label %27, label %21
21: ; preds = %3
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %4
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %25)
br label %94
27: ; preds = %3
br label %28
28: ; preds = %27, %82
%29 = load i32*, i32** %7
%30 = call %struct.dirent* @readdir(i32* %29)
store %struct.dirent* %30, %struct.dirent** %8
%31 = load %struct.dirent*, %struct.dirent** %8
%32 = icmp ne %struct.dirent* %31, null
br i1 %32, label %34, label %33
33: ; preds = %28
br label %83
34: ; preds = %28
%35 = load %struct.dirent*, %struct.dirent** %8
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
store i8* %37, i8** %9
%38 = load %struct.dirent*, %struct.dirent** %8
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 1
%40 = load i32, i32* %39
%41 = load i32, i32* @DT_DIR
%42 = and i32 %40, %41
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %82
44: ; preds = %34
%45 = load i8*, i8** %9
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %81
48: ; preds = %44
%49 = load i8*, i8** %9
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %81
52: ; preds = %48
%53 = load i8*, i8** %9
%54 = call i64 @strcmp(i8* %53, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %81
56: ; preds = %52
%57 = load i8*, i8** %9
%58 = call i64 @strcmp(i8* %57, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %81
60: ; preds = %56
%61 = load i32, i32* @PATH_MAX
%62 = zext i32 %61 to i64
%63 = call i8* @llvm.stacksave()
store i8* %63, i8** %11
%64 = alloca i8, i64 %62
store i64 %62, i64* %12
%65 = load i32, i32* @PATH_MAX
%66 = load i8*, i8** %4
%67 = load i8*, i8** %9
%68 = call i32 @snprintf(i8* %64, i32 %65, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %66, i8* %67)
store i32 %68, i32* %10
%69 = load i32, i32* %10
%70 = load i32, i32* @PATH_MAX
%71 = icmp sge i32 %69, %70
br i1 %71, label %72, label %77
72: ; preds = %60
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %60
%78 = load i32, i32* %5
%79 = load i32, i32* %6
%80 = load i8*, i8** %11
br label %81
81: ; preds = %77, %56, %52, %48, %44
br label %82
82: ; preds = %81, %34
br label %28
83: ; preds = %33
%84 = load i32*, i32** %7
%85 = call i64 @closedir(i32* %84)
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %93
87: ; preds = %83
%88 = load i32, i32* @stderr
%89 = load i8*, i8** %4
%90 = load i32, i32* @errno
%91 = call i8* @strerror(i32 %90)
%92 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %89, i8* %91)
br label %93
93: ; preds = %87, %83
br label %94
94: ; preds = %93, %21
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i32 }
@stderr = global i32 0
@.str = [32 x i8] c"Cannot open directory '%s': %s\0A\00"
@errno = global i32 0
@DT_DIR = global i32 0
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [5 x i8] c".svn\00"
@.str.4 = [7 x i8] c"DEBIAN\00"
@PATH_MAX = global i32 0
@.str.5 = [6 x i8] c"%s/%s\00"
@.str.6 = [31 x i8] c"Path length has got too long.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.7 = [26 x i8] c"Could not close '%s': %s\0A\00"
define void @mapDirectory(i8* %0, i32 %1, i32 %2) {
%4 = tail call i32 @addWatch(i8* %0, i32 %1, i32 %2)
%5 = tail call i32* @opendir(i8* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = call %struct.dirent* @readdir(i32* %5)
%9 = icmp eq %struct.dirent* %8, null
br i1 %9, label %54, label %15
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = tail call i8* @strerror(i32 %12)
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %13)
br label %62
15: ; preds = %7, %51
%16 = phi %struct.dirent* [ %52, %51 ], [ %8, %7 ]
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 0
%18 = load i8*, i8** %17
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 1
%20 = load i32, i32* %19
%21 = load i32, i32* @DT_DIR
%22 = and i32 %21, %20
%23 = icmp eq i32 %22, 0
br i1 %23, label %51, label %24
24: ; preds = %15
%25 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %51, label %27
27: ; preds = %24
%28 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %51, label %30
30: ; preds = %27
%31 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %51, label %33
33: ; preds = %30
%34 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %51, label %36
36: ; preds = %33
%37 = load i32, i32* @PATH_MAX
%38 = zext i32 %37 to i64
%39 = call i8* @llvm.stacksave()
%40 = alloca i8, i64 %38
%41 = load i32, i32* @PATH_MAX
%42 = call i32 @snprintf(i8* %40, i32 %41, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %18)
%43 = load i32, i32* @PATH_MAX
%44 = icmp slt i32 %42, %43
br i1 %44, label %50, label %45
45: ; preds = %36
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %36
br label %51
51: ; preds = %15, %50, %33, %30, %27, %24
%52 = call %struct.dirent* @readdir(i32* %5)
%53 = icmp eq %struct.dirent* %52, null
br i1 %53, label %54, label %15
54: ; preds = %51, %7
%55 = call i64 @closedir(i32* %5)
%56 = icmp eq i64 %55, 0
br i1 %56, label %62, label %57
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.7, i64 0, i64 0), i8* %0, i8* %60)
br label %62
62: ; preds = %54, %57, %10
ret void
}