#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 */
int IN_CREATE;
int IN_DELETE;
int IN_MODIFY;
int inotify_add_watch(int, char *, int);
int /*<<< orphan*/ log_print(int /*<<< orphan*/, char *, int, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int watch_dir(int fd, char *_path) {
  int wd;
  char path[4096] = {0};
  strcat(path, _path);
  wd = inotify_add_watch(fd, path, IN_MODIFY | IN_CREATE | IN_DELETE);
  if (wd < 0) {
    log_print(
        stderr,
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/nirmoy/dbus-pam/refs/heads/master/watcher.c",
        41, "inotify_init");
    return -1;
  };
  return wd;
}


x86 assembly (clang, -O0):
<watch_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x1020(%rbp),%rdi
xor    %esi,%esi
mov    $0x1000,%edx
call   1040 <memset@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
mov    -0x8(%rbp),%edi
lea    -0x1020(%rbp),%rsi
mov    0x2e6a(%rip),%rax
mov    (%rax),%edx
mov    0x2e39(%rip),%rax
or     (%rax),%edx
mov    0x2e48(%rip),%rax
or     (%rax),%edx
call   1050 <inotify_add_watch@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d9 <watch_dir+0x99>
mov    0x2e1d(%rip),%rax
mov    (%rax),%edi
lea    0xe44(%rip),%rsi
mov    $0x29,%edx
lea    0xebe(%rip),%rcx
call   1030 <log_print@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11df <watch_dir+0x9f>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<watch_dir>:
push   %rbp
push   %r14
push   %rbx
sub    $0x1000,%rsp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsp,%rbp
mov    $0x1000,%edx
mov    %rbp,%rdi
xor    %esi,%esi
call   1040 <memset@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1060 <strcat@plt>
mov    0x2e7b(%rip),%rax
mov    0x2e4c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e59(%rip),%rax
or     (%rax),%edx
mov    %r14d,%edi
mov    %rbp,%rsi
call   1050 <inotify_add_watch@plt>
test   %eax,%eax
jns    11be <watch_dir+0x7e>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe58(%rip),%rsi
lea    0xed7(%rip),%rcx
mov    $0x29,%edx
call   1030 <log_print@plt>
mov    $0xffffffff,%eax
add    $0x1000,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@IN_MODIFY = global i32 0
@IN_CREATE = global i32 0
@IN_DELETE = global i32 0
@stderr = global i32 0
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/nirmoy/dbus-pam/refs/heads/master/watcher.c\00"
@.str.1 = [13 x i8] c"inotify_init\00"
define i32 @watch_dir(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca [4096 x i8]
store i32 %0, i32* %4
store i8* %1, i8** %5
%8 = bitcast [4096 x i8]* %7 to i8*
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%10 = load i8*, i8** %5
%11 = call i32 @strcat(i8* %9, i8* %10)
%12 = load i32, i32* %4
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %7, i64 0, i64 0
%14 = load i32, i32* @IN_MODIFY
%15 = load i32, i32* @IN_CREATE
%16 = or i32 %14, %15
%17 = load i32, i32* @IN_DELETE
%18 = or i32 %16, %17
%19 = call i32 @inotify_add_watch(i32 %12, i8* %13, i32 %18)
store i32 %19, i32* %6
%20 = load i32, i32* %6
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 @log_print(i32 %23, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 41, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %27
25: ; preds = %2
%26 = load i32, i32* %6
store i32 %26, i32* %3
br label %27
27: ; preds = %25, %22
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
@IN_MODIFY = global i32 0
@IN_CREATE = global i32 0
@IN_DELETE = global i32 0
@stderr = global i32 0
@.str = [134 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/nirmoy/dbus-pam/refs/heads/master/watcher.c\00"
@.str.1 = [13 x i8] c"inotify_init\00"
define i32 @watch_dir(i32 %0, i8* %1) {
%3 = alloca [4096 x i8]
%4 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%5 = call i32 @strcat(i8* %4, i8* %1)
%6 = load i32, i32* @IN_MODIFY
%7 = load i32, i32* @IN_CREATE
%8 = or i32 %7, %6
%9 = load i32, i32* @IN_DELETE
%10 = or i32 %8, %9
%11 = call i32 @inotify_add_watch(i32 %0, i8* %4, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @log_print(i32 %14, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str, i64 0, i64 0), i32 41, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %2, %13
%17 = phi i32 [ -1, %13 ], [ %11, %2 ]
ret i32 %17
}