#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 inotify_event {
  int /*<<< orphan*/ name;
};

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ ENOENT;
int /*<<< orphan*/ EXIT_FAILURE;
int IN_CREATE;
int IN_MOVED_TO;
scalar_t__ PATH_MAX;
scalar_t__ chdir(char const *);
int /*<<< orphan*/ err(int /*<<< orphan*/, char *, ...);
scalar_t__ errno;
int inotify_add_watch(int, char *, int);
int /*<<< orphan*/ inotify_rm_watch(int, int);
struct inotify_event *malloc(scalar_t__);
scalar_t__ read(int, struct inotify_event *, scalar_t__);
int /*<<< orphan*/ stat(char const *, struct stat *);
int /*<<< orphan*/ strcmp(char const *, int /*<<< orphan*/);
char *strrchr(char const *, char);
void await(const char *path, int inotify, int parent) {
  char *slash;
  int watch;
  struct inotify_event *event;
  struct stat test;
  if (parent && !chdir(path))
    return;
  if (*path == '/') {
    if (chdir("/"))
      err(EXIT_FAILURE, "chdir /");
    while (*path == '/')
      path++;
  }
  slash = strrchr(path, '/');
  if (slash && slash[1] == 0) {
    while (*slash == '/')
      *slash-- = 0;
    slash = strrchr(path, '/');
  }
  if (slash) {
    *slash = 0;
    await(path, inotify, 1);
    path = slash + 1;
  }
  if (*path == 0)
    return;
  if ((watch = inotify_add_watch(inotify, ".", IN_CREATE | IN_MOVED_TO)) < 0)
    err(EXIT_FAILURE, "inotify_add_watch");
  if (parent) {
    if (!chdir(path))
      goto out;
    if (errno != ENOENT)
      err(EXIT_FAILURE, "chdir %s", path);
  } else {
    if (!stat(path, &test))
      goto out;
    if (errno != ENOENT)
      err(EXIT_FAILURE, "stat %s", path);
  }
  if (!(event = malloc(sizeof(*event) + PATH_MAX + 1)))
    err(EXIT_FAILURE, "malloc");
  while (1) {
    if (read(inotify, event, sizeof(*event) + PATH_MAX + 1) < 0) {
      if (errno != EAGAIN && errno != EINTR)
        err(EXIT_FAILURE, "read");
    } else if (!strcmp(path, event->name)) {
      if (!parent || !chdir(path))
        goto out;
      if (errno != ENOENT)
        err(EXIT_FAILURE, "chdir %s", path);
    }
  }
out:
  inotify_rm_watch(inotify, watch);
}


x86 assembly (clang, -O0):
<await>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11d4 <await+0x34>
mov    -0x8(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
jne    11d4 <await+0x34>
jmp    1523 <await+0x383>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    123c <await+0x9c>
lea    0xe1b(%rip),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
je     1211 <await+0x71>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
jmp    1216 <await+0x76>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1237 <await+0x97>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1216 <await+0x76>
jmp    123c <await+0x9c>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12a8 <await+0x108>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
jne    12a8 <await+0x108>
jmp    126f <await+0xcf>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1296 <await+0xf6>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x18(%rbp)
movb   $0x0,(%rax)
jmp    126f <await+0xcf>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12d7 <await+0x137>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    $0x1,%edx
call   1030 <await@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    12ec <await+0x14c>
jmp    1523 <await+0x383>
mov    -0xc(%rbp),%edi
mov    0x2cd2(%rip),%rax
mov    (%rax),%edx
mov    0x2cd9(%rip),%rax
or     (%rax),%edx
lea    0xd00(%rip),%rsi
call   10b0 <inotify_add_watch@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1330 <await+0x190>
mov    0x2ca0(%rip),%rax
mov    (%rax),%edi
lea    0xce1(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
cmpl   $0x0,-0x10(%rbp)
je     138c <await+0x1ec>
mov    -0x8(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
jne    1352 <await+0x1b2>
jmp    1518 <await+0x378>
mov    0x2c77(%rip),%rax
mov    (%rax),%rax
mov    0x2c45(%rip),%rcx
cmp    (%rcx),%rax
je     1387 <await+0x1e7>
mov    0x2c4d(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xc9c(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
jmp    13e1 <await+0x241>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%eax
jne    13a7 <await+0x207>
jmp    1518 <await+0x378>
mov    0x2c22(%rip),%rax
mov    (%rax),%rax
mov    0x2bf0(%rip),%rcx
cmp    (%rcx),%rax
je     13dc <await+0x23c>
mov    0x2bf8(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xc50(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
jmp    13e1 <await+0x241>
mov    0x2c08(%rip),%rax
mov    (%rax),%rdi
add    $0x4,%rdi
add    $0x1,%rdi
call   10a0 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    141d <await+0x27d>
mov    0x2bb3(%rip),%rax
mov    (%rax),%edi
lea    0xc17(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
jmp    1422 <await+0x282>
mov    -0xc(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    0x2bc0(%rip),%rax
mov    (%rax),%rdx
add    $0x4,%rdx
add    $0x1,%rdx
call   1060 <read@plt>
cmp    $0x0,%rax
jge    149a <await+0x2fa>
mov    0x2b7f(%rip),%rax
mov    (%rax),%rax
mov    0x2b45(%rip),%rcx
cmp    (%rcx),%rax
je     1495 <await+0x2f5>
mov    0x2b65(%rip),%rax
mov    (%rax),%rax
mov    0x2b43(%rip),%rcx
cmp    (%rcx),%rax
je     1495 <await+0x2f5>
mov    0x2b3b(%rip),%rax
mov    (%rax),%edi
lea    0xba6(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
jmp    1513 <await+0x373>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    150e <await+0x36e>
cmpl   $0x0,-0x10(%rbp)
je     14cf <await+0x32f>
mov    -0x8(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0x0,%rax
jne    14d4 <await+0x334>
jmp    1518 <await+0x378>
mov    0x2af5(%rip),%rax
mov    (%rax),%rax
mov    0x2ac3(%rip),%rcx
cmp    (%rcx),%rax
je     1509 <await+0x369>
mov    0x2acb(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xb1a(%rip),%rsi
mov    $0x0,%al
call   1090 <err@plt>
jmp    150e <await+0x36e>
jmp    1513 <await+0x373>
jmp    1422 <await+0x282>
mov    -0xc(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10c0 <inotify_rm_watch@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<await>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r12d
mov    %rdi,%rbp
mov    %edx,0x8(%rsp)
test   %edx,%edx
je     11cd <await+0x2d>
mov    %rbp,%rdi
call   1040 <chdir@plt>
test   %rax,%rax
je     12fb <await+0x15b>
cmpb   $0x2f,0x0(%rbp)
jne    121d <await+0x7d>
lea    0xe2c(%rip),%rdi
call   1040 <chdir@plt>
test   %rax,%rax
je     11fb <await+0x5b>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
xor    %eax,%eax
call   1090 <err@plt>
add    $0xffffffffffffffff,%rbp
mov    %rbp,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0x1(%rax),%rbp
cmpb   $0x2f,0x1(%rax)
mov    %rbp,%rax
je     1210 <await+0x70>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     127c <await+0xdc>
mov    %rax,%rbx
cmpb   $0x0,0x1(%rax)
jne    1262 <await+0xc2>
cmpb   $0x2f,(%rbx)
jne    124d <await+0xad>
nopl   (%rax)
movb   $0x0,(%rbx)
cmpb   $0x2f,-0x1(%rbx)
lea    -0x1(%rbx),%rbx
je     1240 <await+0xa0>
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,%rbx
test   %rax,%rax
je     127c <await+0xdc>
movb   $0x0,(%rbx)
mov    %rbp,%rdi
mov    %r12d,%esi
mov    $0x1,%edx
call   1030 <await@plt>
add    $0x1,%rbx
mov    %rbx,%rbp
cmpb   $0x0,0x0(%rbp)
je     12fb <await+0x15b>
mov    0x2d3f(%rip),%rax
mov    0x2d48(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xd6d(%rip),%rsi
mov    %r12d,%edi
call   10b0 <inotify_add_watch@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    12c0 <await+0x120>
mov    0x2d10(%rip),%rax
mov    (%rax),%edi
lea    0xd51(%rip),%rsi
xor    %eax,%eax
call   1090 <err@plt>
cmpl   $0x0,0x8(%rsp)
mov    %ebx,0xc(%rsp)
je     130a <await+0x16a>
mov    %rbp,%rdi
call   1040 <chdir@plt>
test   %rax,%rax
je     1435 <await+0x295>
mov    0x2ced(%rip),%rax
mov    (%rax),%rax
mov    0x2cbb(%rip),%rcx
cmp    (%rcx),%rax
je     134f <await+0x1af>
lea    0xd23(%rip),%rsi
jmp    133c <await+0x19c>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rsi
mov    %rbp,%rdi
call   1080 <stat@plt>
test   %eax,%eax
je     1435 <await+0x295>
mov    0x2caa(%rip),%rax
mov    (%rax),%rax
mov    0x2c78(%rip),%rcx
cmp    (%rcx),%rax
je     134f <await+0x1af>
lea    0xce9(%rip),%rsi
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <err@plt>
mov    0x2c9a(%rip),%r15
mov    (%r15),%rdi
add    $0x5,%rdi
call   10a0 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1381 <await+0x1e1>
mov    0x2c4f(%rip),%rax
mov    (%rax),%edi
lea    0xcb3(%rip),%rsi
xor    %eax,%eax
call   1090 <err@plt>
mov    0x2c48(%rip),%r13
mov    0x2c11(%rip),%r14
nop
mov    (%r15),%rdx
add    $0x5,%rdx
mov    %r12d,%edi
mov    %rbx,%rsi
call   1060 <read@plt>
test   %rax,%rax
js     1400 <await+0x260>
mov    (%rbx),%esi
mov    %rbp,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
jne    1390 <await+0x1f0>
cmpl   $0x0,0x8(%rsp)
je     1435 <await+0x295>
mov    %rbp,%rdi
call   1040 <chdir@plt>
test   %rax,%rax
je     1435 <await+0x295>
mov    0x0(%r13),%rax
mov    0x2bd4(%rip),%rcx
cmp    (%rcx),%rax
je     1390 <await+0x1f0>
mov    0x2be0(%rip),%rax
mov    (%rax),%edi
lea    0xc33(%rip),%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1090 <err@plt>
jmp    1390 <await+0x1f0>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13),%rax
cmp    (%r14),%rax
je     1390 <await+0x1f0>
mov    0x2ba8(%rip),%rcx
cmp    (%rcx),%rax
je     1390 <await+0x1f0>
mov    0x2ba0(%rip),%rax
mov    (%rax),%edi
lea    0xc0b(%rip),%rsi
xor    %eax,%eax
call   1090 <err@plt>
jmp    1390 <await+0x1f0>
mov    %r12d,%edi
mov    0xc(%rsp),%esi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    10c0 <inotify_rm_watch@plt>

LLVM IR (-O0):
%struct.inotify_event = type { i32 }
%struct.stat = type { i32 }
@.str = [2 x i8] c"/\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"chdir /\00"
@.str.2 = [2 x i8] c".\00"
@IN_CREATE = global i32 0
@IN_MOVED_TO = global i32 0
@.str.3 = [18 x i8] c"inotify_add_watch\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.4 = [9 x i8] c"chdir %s\00"
@.str.5 = [8 x i8] c"stat %s\00"
@PATH_MAX = global i64 0
@.str.6 = [7 x i8] c"malloc\00"
@EAGAIN = global i64 0
@EINTR = global i64 0
@.str.7 = [5 x i8] c"read\00"
define void @await(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.inotify_event*
%10 = alloca %struct.stat
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %3
%14 = load i8*, i8** %4
%15 = call i64 @chdir(i8* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %13
br label %178
18: ; preds = %13, %3
%19 = load i8*, i8** %4
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 47
br i1 %22, label %23, label %39
23: ; preds = %18
%24 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %23
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 (i32, i8*, ...) @err(i32 %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %26, %23
br label %30
30: ; preds = %35, %29
%31 = load i8*, i8** %4
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 47
br i1 %34, label %35, label %38
35: ; preds = %30
%36 = load i8*, i8** %4
%37 = getelementptr inbounds i8, i8* %36, i32 1
store i8* %37, i8** %4
br label %30
38: ; preds = %30
br label %39
39: ; preds = %38, %18
%40 = load i8*, i8** %4
%41 = call i8* @strrchr(i8* %40, i8 signext 47)
store i8* %41, i8** %7
%42 = load i8*, i8** %7
%43 = icmp ne i8* %42, null
br i1 %43, label %44, label %62
44: ; preds = %39
%45 = load i8*, i8** %7
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %62
50: ; preds = %44
br label %51
51: ; preds = %56, %50
%52 = load i8*, i8** %7
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = icmp eq i32 %54, 47
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = load i8*, i8** %7
%58 = getelementptr inbounds i8, i8* %57, i32 -1
store i8* %58, i8** %7
store i8 0, i8* %57
br label %51
59: ; preds = %51
%60 = load i8*, i8** %4
%61 = call i8* @strrchr(i8* %60, i8 signext 47)
store i8* %61, i8** %7
br label %62
62: ; preds = %59, %44, %39
%63 = load i8*, i8** %7
%64 = icmp ne i8* %63, null
br i1 %64, label %65, label %71
65: ; preds = %62
%66 = load i8*, i8** %7
store i8 0, i8* %66
%67 = load i8*, i8** %4
%68 = load i32, i32* %5
%69 = load i8*, i8** %7
%70 = getelementptr inbounds i8, i8* %69, i64 1
store i8* %70, i8** %4
br label %71
71: ; preds = %65, %62
%72 = load i8*, i8** %4
%73 = load i8, i8* %72
%74 = sext i8 %73 to i32
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %77
76: ; preds = %71
br label %178
77: ; preds = %71
%78 = load i32, i32* %5
%79 = load i32, i32* @IN_CREATE
%80 = load i32, i32* @IN_MOVED_TO
%81 = or i32 %79, %80
%82 = call i32 @inotify_add_watch(i32 %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %81)
store i32 %82, i32* %8
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %77
%85 = load i32, i32* @EXIT_FAILURE
%86 = call i32 (i32, i8*, ...) @err(i32 %85, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %87
87: ; preds = %84, %77
%88 = load i32, i32* %6
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %104
90: ; preds = %87
%91 = load i8*, i8** %4
%92 = call i64 @chdir(i8* %91)
%93 = icmp ne i64 %92, 0
br i1 %93, label %95, label %94
94: ; preds = %90
br label %174
95: ; preds = %90
%96 = load i64, i64* @errno
%97 = load i64, i64* @ENOENT
%98 = icmp ne i64 %96, %97
br i1 %98, label %99, label %103
99: ; preds = %95
%100 = load i32, i32* @EXIT_FAILURE
%101 = load i8*, i8** %4
%102 = call i32 (i32, i8*, ...) @err(i32 %100, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %101)
br label %103
103: ; preds = %99, %95
br label %118
104: ; preds = %87
%105 = load i8*, i8** %4
%106 = call i32 @stat(i8* %105, %struct.stat* %10)
%107 = icmp ne i32 %106, 0
br i1 %107, label %109, label %108
108: ; preds = %104
br label %174
109: ; preds = %104
%110 = load i64, i64* @errno
%111 = load i64, i64* @ENOENT
%112 = icmp ne i64 %110, %111
br i1 %112, label %113, label %117
113: ; preds = %109
%114 = load i32, i32* @EXIT_FAILURE
%115 = load i8*, i8** %4
%116 = call i32 (i32, i8*, ...) @err(i32 %114, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %115)
br label %117
117: ; preds = %113, %109
br label %118
118: ; preds = %117, %103
%119 = load i64, i64* @PATH_MAX
%120 = add i64 4, %119
%121 = add i64 %120, 1
%122 = call %struct.inotify_event* @malloc(i64 %121)
store %struct.inotify_event* %122, %struct.inotify_event** %9
%123 = icmp ne %struct.inotify_event* %122, null
br i1 %123, label %127, label %124
124: ; preds = %118
%125 = load i32, i32* @EXIT_FAILURE
%126 = call i32 (i32, i8*, ...) @err(i32 %125, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %127
127: ; preds = %124, %118
br label %128
128: ; preds = %127, %173
%129 = load i32, i32* %5
%130 = load %struct.inotify_event*, %struct.inotify_event** %9
%131 = load i64, i64* @PATH_MAX
%132 = add i64 4, %131
%133 = add i64 %132, 1
%134 = call i64 @read(i32 %129, %struct.inotify_event* %130, i64 %133)
%135 = icmp slt i64 %134, 0
br i1 %135, label %136, label %148
136: ; preds = %128
%137 = load i64, i64* @errno
%138 = load i64, i64* @EAGAIN
%139 = icmp ne i64 %137, %138
br i1 %139, label %140, label %147
140: ; preds = %136
%141 = load i64, i64* @errno
%142 = load i64, i64* @EINTR
%143 = icmp ne i64 %141, %142
br i1 %143, label %144, label %147
144: ; preds = %140
%145 = load i32, i32* @EXIT_FAILURE
%146 = call i32 (i32, i8*, ...) @err(i32 %145, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %147
147: ; preds = %144, %140, %136
br label %173
148: ; preds = %128
%149 = load i8*, i8** %4
%150 = load %struct.inotify_event*, %struct.inotify_event** %9
%151 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %150, i32 0, i32 0
%152 = load i32, i32* %151
%153 = call i32 @strcmp(i8* %149, i32 %152)
%154 = icmp ne i32 %153, 0
br i1 %154, label %172, label %155
155: ; preds = %148
%156 = load i32, i32* %6
%157 = icmp ne i32 %156, 0
br i1 %157, label %158, label %162
158: ; preds = %155
%159 = load i8*, i8** %4
%160 = call i64 @chdir(i8* %159)
%161 = icmp ne i64 %160, 0
br i1 %161, label %163, label %162
162: ; preds = %158, %155
br label %174
163: ; preds = %158
%164 = load i64, i64* @errno
%165 = load i64, i64* @ENOENT
%166 = icmp ne i64 %164, %165
br i1 %166, label %167, label %171
167: ; preds = %163
%168 = load i32, i32* @EXIT_FAILURE
%169 = load i8*, i8** %4
%170 = call i32 (i32, i8*, ...) @err(i32 %168, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %169)
br label %171
171: ; preds = %167, %163
br label %172
172: ; preds = %171, %148
br label %173
173: ; preds = %172, %147
br label %128
174: ; preds = %162, %108, %94
%175 = load i32, i32* %5
%176 = load i32, i32* %8
%177 = call i32 @inotify_rm_watch(i32 %175, i32 %176)
br label %178
178: ; preds = %174, %76, %17
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.inotify_event = type { i32 }
@.str = [2 x i8] c"/\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [8 x i8] c"chdir /\00"
@.str.2 = [2 x i8] c".\00"
@IN_CREATE = global i32 0
@IN_MOVED_TO = global i32 0
@.str.3 = [18 x i8] c"inotify_add_watch\00"
@errno = global i64 0
@ENOENT = global i64 0
@.str.4 = [9 x i8] c"chdir %s\00"
@.str.5 = [8 x i8] c"stat %s\00"
@PATH_MAX = global i64 0
@.str.6 = [7 x i8] c"malloc\00"
@EAGAIN = global i64 0
@EINTR = global i64 0
@.str.7 = [5 x i8] c"read\00"
define void @await(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = icmp eq i32 %2, 0
br i1 %6, label %10, label %7
7: ; preds = %3
%8 = tail call i64 @chdir(i8* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %122, label %10
10: ; preds = %7, %3
%11 = load i8, i8* %0
%12 = icmp eq i8 %11, 47
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = tail call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* @EXIT_FAILURE
%18 = tail call i32 (i32, i8*, ...) @err(i32 %17, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %16, %13
br label %20
20: ; preds = %19, %20
%21 = phi i8* [ %24, %20 ], [ %0, %19 ]
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 47
%24 = getelementptr inbounds i8, i8* %21, i64 1
br i1 %23, label %20, label %25
25: ; preds = %20, %10
%26 = phi i8* [ %0, %10 ], [ %21, %20 ]
%27 = tail call i8* @strrchr(i8* %26, i8 signext 47)
%28 = icmp eq i8* %27, null
br i1 %28, label %47, label %29
29: ; preds = %25
%30 = getelementptr inbounds i8, i8* %27, i64 1
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 0
br i1 %32, label %33, label %44
33: ; preds = %29
%34 = load i8, i8* %27
%35 = icmp eq i8 %34, 47
br i1 %35, label %36, label %41
36: ; preds = %33, %36
%37 = phi i8* [ %38, %36 ], [ %27, %33 ]
%38 = getelementptr inbounds i8, i8* %37, i64 -1
store i8 0, i8* %37
%39 = load i8, i8* %38
%40 = icmp eq i8 %39, 47
br i1 %40, label %36, label %41
41: ; preds = %36, %33
%42 = tail call i8* @strrchr(i8* %26, i8 signext 47)
%43 = icmp eq i8* %42, null
br i1 %43, label %47, label %44
44: ; preds = %29, %41
%45 = phi i8* [ %42, %41 ], [ %27, %29 ]
store i8 0, i8* %45
tail call void @await(i8* %26, i32 %1, i32 1)
%46 = getelementptr inbounds i8, i8* %45, i64 1
br label %47
47: ; preds = %25, %44, %41
%48 = phi i8* [ %46, %44 ], [ %26, %41 ], [ %26, %25 ]
%49 = load i8, i8* %48
%50 = icmp eq i8 %49, 0
br i1 %50, label %122, label %51
51: ; preds = %47
%52 = load i32, i32* @IN_CREATE
%53 = load i32, i32* @IN_MOVED_TO
%54 = or i32 %53, %52
%55 = tail call i32 @inotify_add_watch(i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %54)
%56 = icmp slt i32 %55, 0
br i1 %56, label %57, label %60
57: ; preds = %51
%58 = load i32, i32* @EXIT_FAILURE
%59 = tail call i32 (i32, i8*, ...) @err(i32 %58, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
br label %60
60: ; preds = %57, %51
br i1 %6, label %68, label %61
61: ; preds = %60
%62 = tail call i64 @chdir(i8* %48)
%63 = icmp eq i64 %62, 0
br i1 %63, label %120, label %64
64: ; preds = %61
%65 = load i64, i64* @errno
%66 = load i64, i64* @ENOENT
%67 = icmp eq i64 %65, %66
br i1 %67, label %79, label %75
68: ; preds = %60
%69 = call i32 @stat(i8* %48, %struct.stat* %4)
%70 = icmp eq i32 %69, 0
br i1 %70, label %120, label %71
71: ; preds = %68
%72 = load i64, i64* @errno
%73 = load i64, i64* @ENOENT
%74 = icmp eq i64 %72, %73
br i1 %74, label %79, label %75
75: ; preds = %71, %64
%76 = phi i8* [ getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %64 ], [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), %71 ]
%77 = load i32, i32* @EXIT_FAILURE
%78 = tail call i32 (i32, i8*, ...) @err(i32 %77, i8* %76, i8* %48)
br label %79
79: ; preds = %75, %71, %64
%80 = load i64, i64* @PATH_MAX
%81 = add i64 %80, 5
%82 = tail call %struct.inotify_event* @malloc(i64 %81)
%83 = icmp eq %struct.inotify_event* %82, null
br i1 %83, label %84, label %87
84: ; preds = %79
%85 = load i32, i32* @EXIT_FAILURE
%86 = tail call i32 (i32, i8*, ...) @err(i32 %85, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %87
87: ; preds = %84, %79
%88 = getelementptr inbounds %struct.inotify_event, %struct.inotify_event* %82, i64 0, i32 0
br label %89
89: ; preds = %108, %87
%90 = load i64, i64* @PATH_MAX
%91 = add i64 %90, 5
%92 = tail call i64 @read(i32 %1, %struct.inotify_event* %82, i64 %91)
%93 = icmp slt i64 %92, 0
br i1 %93, label %94, label %104
94: ; preds = %89
%95 = load i64, i64* @errno
%96 = load i64, i64* @EAGAIN
%97 = icmp eq i64 %95, %96
%98 = load i64, i64* @EINTR
%99 = icmp eq i64 %95, %98
%100 = select i1 %97, i1 true, i1 %99
br i1 %100, label %108, label %101
101: ; preds = %94
%102 = load i32, i32* @EXIT_FAILURE
%103 = tail call i32 (i32, i8*, ...) @err(i32 %102, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
br label %108
104: ; preds = %89
%105 = load i32, i32* %88
%106 = tail call i32 @strcmp(i8* %48, i32 %105)
%107 = icmp eq i32 %106, 0
br i1 %107, label %109, label %108
108: ; preds = %104, %117, %113, %94, %101
br label %89
109: ; preds = %104
br i1 %6, label %120, label %110
110: ; preds = %109
%111 = tail call i64 @chdir(i8* %48)
%112 = icmp eq i64 %111, 0
br i1 %112, label %120, label %113
113: ; preds = %110
%114 = load i64, i64* @errno
%115 = load i64, i64* @ENOENT
%116 = icmp eq i64 %114, %115
br i1 %116, label %108, label %117
117: ; preds = %113
%118 = load i32, i32* @EXIT_FAILURE
%119 = tail call i32 (i32, i8*, ...) @err(i32 %118, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i8* %48)
br label %108
120: ; preds = %109, %110, %68, %61
%121 = tail call i32 @inotify_rm_watch(i32 %1, i32 %55)
br label %122
122: ; preds = %47, %7, %120
ret void
}