// File: /workspace/github_c_makefile_star2_O0/wahern[P]cqueues/src/lib/notify.c
// Function: notify_opendir
struct notify *notify_opendir(const char *dirpath, int flags, int *_error) {
	struct notify *nfy = NULL;
	size_t dirlen = strlen(dirpath);
	size_t padlen = NAME_MAX + 2;
	int error;

	while (dirlen > 1 && dirpath[dirlen - 1] == '/')
		--dirlen;

	if (~padlen < dirlen) {
		error = ENAMETOOLONG;
		goto error;
	}

	if (!(nfy = calloc(1, offsetof(struct notify, dirpath) + dirlen + padlen)))
		goto syerr;

	nfy->fd = -1;
	nfy->flags = flags;

	nfy->dirfd = -1;
	nfy->dirwd = -1;
	nfy->dirlen = dirlen;
	memcpy(nfy->dirpath, dirpath, dirlen);

#if ENABLE_INOTIFY
#if HAVE_INOTIFY_INIT1 && HAVE_IN_NONBLOCK && HAVE_IN_CLOEXEC
	if (-1 == (nfy->fd = inotify_init1(IN_NONBLOCK|IN_CLOEXEC)))
		goto syerr;
#else
	if (-1 == (nfy->fd = inotify_init()))
		goto syerr;

	if ((error = cloexec(nfy->fd)))
		goto error;

	if ((error = nonblock(nfy->fd)))
		goto error;
#endif

	if (-1 == (nfy->dirwd = inotify_add_watch(nfy->fd, nfy->dirpath, IN_ATTRIB|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MODIFY|IN_MOVE|IN_MOVE_SELF|IN_ONLYDIR)))
		goto syerr;
#elif ENABLE_FEN
	if (-1 == (nfy->fd = port_create())) {
		if (errno == EAGAIN)
			errno = EMFILE;
		goto syerr;
	}

	if ((error = cloexec(nfy->fd)))
		goto error;

	if ((error = nfy_openfd(&nfy->dirfd, .path = nfy->dirpath, .rdonly = 1, .cloexec = 1, .directory = 1)))
		goto error;

	fenfo_init(&nfy->dirfo, nfy->dirpath);

	if (0 != port_associate(nfy->fd, PORT_SOURCE_FILE, (intptr_t)&nfy->dirfo, FILE_MODIFIED|FILE_ATTRIB|FILE_NOFOLLOW, nfy))
		goto syerr;
#else
#if HAVE_KQUEUE1 && HAVE_O_CLOEXEC
	if (-1 == (nfy->fd = kqueue1(O_CLOEXEC)))
		goto syerr;
#else
	if (-1 == (nfy->fd = kqueue()))
		goto syerr;

	if ((error = cloexec(nfy->fd)))
		goto error;
#endif

	if ((error = nfy_openfd(&nfy->dirfd, .path = nfy->dirpath, .rdonly = 1, .cloexec = 1, .directory = 1)))
		goto error;

	struct kevent event;

	NFY_SET(&event, nfy->dirfd, EVFILT_VNODE, EV_ADD|EV_CLEAR, NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_REVOKE, 0, nfy);

	if (0 != kevent(nfy->fd, &event, 1, NULL, 0, &(struct timespec){ 0, 0 }))
		goto syerr;
#endif

	return nfy;
syerr:
	error = errno;
error:
	*_error = error;

	notify_close(nfy);

	return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rdi
callq 0xf5c0
movq %rax, -0x30(%rbp)
movq $0x101, -0x38(%rbp)     # imm = 0x101
xorl %eax, %eax
cmpq $0x1, -0x30(%rbp)
movb %al, -0x3d(%rbp)
jbe 0x457e5
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x2f, %eax
sete %al
movb %al, -0x3d(%rbp)
movb -0x3d(%rbp), %al
testb $0x1, %al
jne 0x457ee
jmp 0x457fc
movq -0x30(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x457c0
movq -0x38(%rbp), %rax
xorq $-0x1, %rax
cmpq -0x30(%rbp), %rax
jae 0x45816
movl $0x24, -0x3c(%rbp)
jmp 0x45908
movq -0x30(%rbp), %rsi
addq $0x68, %rsi
addq -0x38(%rbp), %rsi
movl $0x1, %edi
callq 0xf930
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x4583b
jmp 0x458fe
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x48(%rax)
movq -0x28(%rbp), %rax
movl $0xffffffff, 0x54(%rax) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movl $0xffffffff, 0x58(%rax) # imm = 0xFFFFFFFF
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x28(%rbp), %rdi
addq $0x68, %rdi
movq -0x10(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0xfb40
callq 0x10a30
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x4589e
jmp 0x458fe
movq -0x28(%rbp), %rax
movl (%rax), %edi
callq 0x45930
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
je 0x458b3
jmp 0x45908
movq -0x28(%rbp), %rax
movl (%rax), %edi
callq 0x459a0
movl %eax, -0x3c(%rbp)
cmpl $0x0, %eax
je 0x458c8
jmp 0x45908
movq -0x28(%rbp), %rax
movl (%rax), %edi
movq -0x28(%rbp), %rsi
addq $0x68, %rsi
movl $0x1000fc6, %edx        # imm = 0x1000FC6
callq 0xf760
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x58(%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl %ecx, %eax
jne 0x458f4
jmp 0x458fe
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x45922
callq 0xf0a0
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rdi
callq 0x10850
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)