#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 */

/* Variables and functions */
scalar_t__ ENOSPC;
scalar_t__ errno;
int /*<<< orphan*/ init_watches();
int inotify_add_watch(int, char const *, unsigned int);
int add_watch(int inotify, const char *pathname, unsigned int flags) {
  int ret = inotify_add_watch(inotify, pathname, flags);
  if (ret == -1 && errno == ENOSPC) {
    init_watches();
    ret = inotify_add_watch(inotify, pathname, flags);
  }
  return ret;
}


x86 assembly (clang, -O0):
<add_watch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <inotify_add_watch@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1181 <add_watch+0x61>
mov    0x2e8b(%rip),%rax
mov    (%rax),%rax
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
jne    1181 <add_watch+0x61>
mov    $0x0,%al
call   1030 <init_watches@plt>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <inotify_add_watch@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_watch>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
call   1040 <inotify_add_watch@plt>
cmp    $0xffffffff,%eax
jne    1169 <add_watch+0x49>
mov    0x2ea3(%rip),%rax
mov    (%rax),%rcx
mov    0x2e91(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%rcx
jne    1169 <add_watch+0x49>
xor    %eax,%eax
call   1030 <init_watches@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <inotify_add_watch@plt>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@ENOSPC = global i64 0
define i32 @add_watch(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %4
%9 = load i8*, i8** %5
%10 = load i32, i32* %6
%11 = call i32 @inotify_add_watch(i32 %8, i8* %9, i32 %10)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %24
14: ; preds = %3
%15 = load i64, i64* @errno
%16 = load i64, i64* @ENOSPC
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %24
18: ; preds = %14
%19 = call i32 (...) @init_watches()
%20 = load i32, i32* %4
%21 = load i8*, i8** %5
%22 = load i32, i32* %6
%23 = call i32 @inotify_add_watch(i32 %20, i8* %21, i32 %22)
store i32 %23, i32* %7
br label %24
24: ; preds = %18, %14, %3
%25 = load i32, i32* %7
ret i32 %25
}

LLVM IR (-O2):
@errno = global i64 0
@ENOSPC = global i64 0
define i32 @add_watch(i32 %0, i8* %1, i32 %2) {
%4 = tail call i32 @inotify_add_watch(i32 %0, i8* %1, i32 %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %13
6: ; preds = %3
%7 = load i64, i64* @errno
%8 = load i64, i64* @ENOSPC
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = tail call i32 (...) @init_watches()
%12 = tail call i32 @inotify_add_watch(i32 %0, i8* %1, i32 %2)
br label %13
13: ; preds = %10, %6, %3
%14 = phi i32 [ %12, %10 ], [ -1, %6 ], [ %4, %3 ]
ret i32 %14
}