#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 */
typedef int /*<<< orphan*/ uint32_t;
struct stat {
  int /*<<< orphan*/ st_mode;
};
struct notify_node {
  int dummy;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ S_ISLNK(int /*<<< orphan*/);
int /*<<< orphan*/ add_notify_list_node(struct notify_node **, int, char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ getcwd(char *, int);
int inotify_add_watch(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
int recursive_inotify(int fd, char *dir, uint32_t mask,
                      struct notify_node **list) {
  DIR *dp;
  int wd;
  struct dirent *ep;
  struct stat fstat;
  char directory[1024] = {
      0,
  };
  dp = opendir(dir);
  if (dp == NULL) {
    printf("Open Error: %s\n", dir);
    perror("opendir");
    exit(EXIT_FAILURE);
    return 2;
  }
  chdir(dir);
  while (ep = readdir(dp)) {
    if (strcmp(ep->d_name, ".") == 0 || strcmp(ep->d_name, "..") == 0)
      continue;
    lstat(ep->d_name, &fstat);
    if (S_ISDIR(fstat.st_mode) && !S_ISLNK(fstat.st_mode)) {
      bzero(directory, 1024);
      getcwd(directory, 1024);
      if (directory[strlen(directory) - 1] != '/')
        strcat(directory, "/");
      strcat(directory, ep->d_name);
      wd = inotify_add_watch(fd, directory, mask);
      if (wd < 0) {
        printf("ERROR:%s\n", directory);
        perror("inotify_add_watch");
        exit(EXIT_FAILURE);
      }
      add_notify_list_node(list, wd, directory);
      recursive_inotify(fd, directory, mask, list);
    }
  }
  chdir("..");
  closedir(dp);
}


x86 assembly (clang, -O0):
<recursive_inotify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x440(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10a0 <memset@plt>
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    129e <recursive_inotify+0x6e>
mov    -0x10(%rbp),%rsi
lea    0xd81(%rip),%rdi
call   1080 <printf@plt>
lea    0xd85(%rip),%rdi
call   1120 <perror@plt>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1070 <chdir@plt>
mov    -0x28(%rbp),%rdi
call   1100 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1414 <recursive_inotify+0x1e4>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xd4d(%rip),%rsi
call   10f0 <strcmp@plt>
cmp    $0x0,%rax
je     12f8 <recursive_inotify+0xc8>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xd2f(%rip),%rsi
call   10f0 <strcmp@plt>
cmp    $0x0,%rax
jne    12fd <recursive_inotify+0xcd>
jmp    12a7 <recursive_inotify+0x77>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    -0x40(%rbp),%rsi
call   10e0 <lstat@plt>
mov    -0x40(%rbp),%edi
call   1090 <S_ISDIR@plt>
cmp    $0x0,%rax
je     140f <recursive_inotify+0x1df>
mov    -0x40(%rbp),%edi
call   1030 <S_ISLNK@plt>
cmp    $0x0,%eax
jne    140f <recursive_inotify+0x1df>
lea    -0x440(%rbp),%rdi
mov    $0x400,%esi
call   1130 <bzero@plt>
lea    -0x440(%rbp),%rdi
mov    $0x400,%esi
call   10b0 <getcwd@plt>
lea    -0x440(%rbp),%rdi
call   1060 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x440(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
je     1387 <recursive_inotify+0x157>
lea    -0x440(%rbp),%rdi
lea    0xc99(%rip),%rsi
call   1140 <strcat@plt>
lea    -0x440(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
call   1140 <strcat@plt>
mov    -0x8(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1110 <inotify_add_watch@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    13e6 <recursive_inotify+0x1b6>
lea    -0x440(%rbp),%rsi
lea    0xc56(%rip),%rdi
call   1080 <printf@plt>
lea    0xc54(%rip),%rdi
call   1120 <perror@plt>
mov    0x2c01(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x440(%rbp),%rdx
call   1050 <add_notify_list_node@plt>
mov    -0x8(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
call   10c0 <recursive_inotify@plt>
jmp    12a7 <recursive_inotify+0x77>
lea    0xbfd(%rip),%rdi
call   1070 <chdir@plt>
mov    -0x28(%rbp),%rdi
call   10d0 <closedir@plt>
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursive_inotify>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
mov    %rcx,0x18(%rsp)
mov    %edx,0x14(%rsp)
mov    %rsi,%rbp
mov    %edi,0x10(%rsp)
lea    0x20(%rsp),%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <memset@plt>
mov    %rbp,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     13e5 <recursive_inotify+0x1b5>
mov    %rax,%r13
mov    %rbp,%rdi
call   1070 <chdir@plt>
mov    %r13,%rdi
call   1100 <readdir@plt>
test   %rax,%rax
je     13a5 <recursive_inotify+0x175>
mov    %rax,%r12
lea    0xd7d(%rip),%r14
lea    0xd75(%rip),%rbp
jmp    1314 <recursive_inotify+0xe4>
mov    (%r12),%rsi
mov    %rbx,%rdi
call   1140 <strcat@plt>
mov    0x10(%rsp),%ebp
mov    %ebp,%edi
mov    %rbx,%rsi
mov    0x14(%rsp),%r12d
mov    %r12d,%edx
call   1110 <inotify_add_watch@plt>
test   %eax,%eax
js     13cb <recursive_inotify+0x19b>
mov    0x18(%rsp),%r15
mov    %r15,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1050 <add_notify_list_node@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
mov    %r15,%rcx
call   10c0 <recursive_inotify@plt>
lea    0xd20(%rip),%rbp
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1100 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     13a5 <recursive_inotify+0x175>
mov    (%r12),%rdi
mov    %r14,%rsi
call   10f0 <strcmp@plt>
test   %rax,%rax
je     1300 <recursive_inotify+0xd0>
mov    (%r12),%rdi
mov    %rbp,%rsi
call   10f0 <strcmp@plt>
test   %rax,%rax
je     1300 <recursive_inotify+0xd0>
mov    (%r12),%rdi
lea    0x8(%rsp),%rsi
call   10e0 <lstat@plt>
mov    0x8(%rsp),%r15d
mov    %r15d,%edi
call   1090 <S_ISDIR@plt>
test   %rax,%rax
je     1300 <recursive_inotify+0xd0>
mov    %r15d,%edi
call   1030 <S_ISLNK@plt>
test   %eax,%eax
jne    1300 <recursive_inotify+0xd0>
mov    %rbx,%rdi
mov    $0x400,%esi
call   1130 <bzero@plt>
mov    %rbx,%rdi
mov    $0x400,%esi
call   10b0 <getcwd@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     12a5 <recursive_inotify+0x75>
mov    %rbx,%rdi
lea    0xc80(%rip),%rsi
call   1140 <strcat@plt>
jmp    12a5 <recursive_inotify+0x75>
lea    0xc6c(%rip),%rdi
call   1070 <chdir@plt>
mov    %r13,%rdi
call   10d0 <closedir@plt>
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc4b(%rip),%rdi
lea    0x20(%rsp),%rsi
call   1080 <printf@plt>
lea    0xc44(%rip),%rdi
jmp    13fb <recursive_inotify+0x1cb>
lea    0xc14(%rip),%rdi
mov    %rbp,%rsi
call   1080 <printf@plt>
lea    0xc15(%rip),%rdi
call   1120 <perror@plt>
mov    0x2bd9(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>

LLVM IR (-O0):
%struct.notify_node = type { i32 }
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@.str = [16 x i8] c"Open Error: %s\0A\00"
@.str.1 = [8 x i8] c"opendir\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [10 x i8] c"ERROR:%s\0A\00"
@.str.6 = [18 x i8] c"inotify_add_watch\00"
define i32 @recursive_inotify(i32 %0, i8* %1, i32 %2, %struct.notify_node** %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.notify_node**
%10 = alloca i32*
%11 = alloca i32
%12 = alloca %struct.dirent*
%13 = alloca %struct.stat
%14 = alloca [1024 x i8]
store i32 %0, i32* %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store %struct.notify_node** %3, %struct.notify_node*** %9
%15 = bitcast [1024 x i8]* %14 to i8*
%16 = load i8*, i8** %7
%17 = call i32* @opendir(i8* %16)
store i32* %17, i32** %10
%18 = load i32*, i32** %10
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %26
20: ; preds = %4
%21 = load i8*, i8** %7
%22 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %4
%27 = load i8*, i8** %7
%28 = call i32 @chdir(i8* %27)
br label %29
29: ; preds = %104, %45, %26
%30 = load i32*, i32** %10
%31 = call %struct.dirent* @readdir(i32* %30)
store %struct.dirent* %31, %struct.dirent** %12
%32 = icmp ne %struct.dirent* %31, null
br i1 %32, label %33, label %105
33: ; preds = %29
%34 = load %struct.dirent*, %struct.dirent** %12
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i64 @strcmp(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %45, label %39
39: ; preds = %33
%40 = load %struct.dirent*, %struct.dirent** %12
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %39, %33
br label %29
46: ; preds = %39
%47 = load %struct.dirent*, %struct.dirent** %12
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 0
%49 = load i8*, i8** %48
%50 = call i32 @lstat(i8* %49, %struct.stat* %13)
%51 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i64 @S_ISDIR(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %104
55: ; preds = %46
%56 = getelementptr inbounds %struct.stat, %struct.stat* %13, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @S_ISLNK(i32 %57)
%59 = icmp ne i32 %58, 0
br i1 %59, label %104, label %60
60: ; preds = %55
%61 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%62 = call i32 @bzero(i8* %61, i32 1024)
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%64 = call i32 @getcwd(i8* %63, i32 1024)
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%66 = call i32 @strlen(i8* %65)
%67 = sub nsw i32 %66, 1
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 %68
%70 = load i8, i8* %69
%71 = sext i8 %70 to i32
%72 = icmp ne i32 %71, 47
br i1 %72, label %73, label %76
73: ; preds = %60
%74 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%75 = call i32 @strcat(i8* %74, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %76
76: ; preds = %73, %60
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%78 = load %struct.dirent*, %struct.dirent** %12
%79 = getelementptr inbounds %struct.dirent, %struct.dirent* %78, i32 0, i32 0
%80 = load i8*, i8** %79
%81 = call i32 @strcat(i8* %77, i8* %80)
%82 = load i32, i32* %6
%83 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%84 = load i32, i32* %8
%85 = call i32 @inotify_add_watch(i32 %82, i8* %83, i32 %84)
store i32 %85, i32* %11
%86 = load i32, i32* %11
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %94
88: ; preds = %76
%89 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%90 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %89)
%91 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%92 = load i32, i32* @EXIT_FAILURE
%93 = call i32 @exit(i32 %92)
unreachable
94: ; preds = %76
%95 = load %struct.notify_node**, %struct.notify_node*** %9
%96 = load i32, i32* %11
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%98 = call i32 @add_notify_list_node(%struct.notify_node** %95, i32 %96, i8* %97)
%99 = load i32, i32* %6
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%101 = load i32, i32* %8
%102 = load %struct.notify_node**, %struct.notify_node*** %9
%103 = call i32 @recursive_inotify(i32 %99, i8* %100, i32 %101, %struct.notify_node** %102)
br label %104
104: ; preds = %94, %55, %46
br label %29
105: ; preds = %29
%106 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%107 = load i32*, i32** %10
%108 = call i32 @closedir(i32* %107)
%109 = load i32, i32* %5
ret i32 %109
}

LLVM IR (-O2):
%struct.notify_node = type { i32 }
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [16 x i8] c"Open Error: %s\0A\00"
@.str.1 = [8 x i8] c"opendir\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [10 x i8] c"ERROR:%s\0A\00"
@.str.6 = [18 x i8] c"inotify_add_watch\00"
define i32 @recursive_inotify(i32 %0, i8* %1, i32 %2, %struct.notify_node** %3) {
%5 = alloca %struct.stat
%6 = alloca [1024 x i8]
%7 = bitcast %struct.stat* %5 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = tail call i32* @opendir(i8* %1)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %4
%12 = tail call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %1)
%13 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %4
%17 = tail call i32 @chdir(i8* %1)
%18 = call %struct.dirent* @readdir(i32* %9)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %68, label %20
20: ; preds = %16
%21 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
br label %22
22: ; preds = %20, %32
%23 = phi %struct.dirent* [ %18, %20 ], [ %33, %32 ]
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i64 0, i32 0
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %22
%29 = load i8*, i8** %24
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %35, %41, %65, %22, %28
%33 = call %struct.dirent* @readdir(i32* %9)
%34 = icmp eq %struct.dirent* %33, null
br i1 %34, label %68, label %22
35: ; preds = %28
%36 = load i8*, i8** %24
%37 = call i32 @lstat(i8* %36, %struct.stat* %5)
%38 = load i32, i32* %21
%39 = call i64 @S_ISDIR(i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %32, label %41
41: ; preds = %35
%42 = call i32 @S_ISLNK(i32 %38)
%43 = icmp eq i32 %42, 0
br i1 %43, label %44, label %32
44: ; preds = %41
%45 = call i32 @bzero(i8* %8, i32 1024)
%46 = call i32 @getcwd(i8* %8, i32 1024)
%47 = call i32 @strlen(i8* %8)
%48 = add nsw i32 %47, -1
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %49
%51 = load i8, i8* %50
%52 = icmp eq i8 %51, 47
br i1 %52, label %55, label %53
53: ; preds = %44
%54 = call i32 @strcat(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %53, %44
%56 = load i8*, i8** %24
%57 = call i32 @strcat(i8* %8, i8* %56)
%58 = call i32 @inotify_add_watch(i32 %0, i8* %8, i32 %2)
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %65
60: ; preds = %55
%61 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%62 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %55
%66 = call i32 @add_notify_list_node(%struct.notify_node** %3, i32 %58, i8* %8)
%67 = call i32 @recursive_inotify(i32 %0, i8* %8, i32 %2, %struct.notify_node** %3)
br label %32
68: ; preds = %32, %16
%69 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%70 = call i32 @closedir(i32* %9)
ret i32 undef
}