// File: /workspace/github_c_makefile_star2_O1/wahern[P]cqueues/src/lib/notify.c
// Function: notify_add
int notify_add(struct notify *nfy, const char *name, int flags) {
	size_t namelen = strlen(name);
	struct file *file;
	int error;

	if (namelen > NAME_MAX)
		return ENAMETOOLONG;
	if (memchr(name, '/', namelen))
		return EISDIR;

	if ((file = lookup(nfy, name, namelen)))
		return 0;

#if ENABLE_FEN
	size_t pathlen = nfy->dirlen + 1 + namelen;

	if (!(file = calloc(1, offsetof(struct file, path) + pathlen + 1)))
		return errno;

	memcpy(file->path, nfy->dirpath, nfy->dirlen);
	file->path[nfy->dirlen] = '/';
	file->pathlen = pathlen;
	file->name = &file->path[nfy->dirlen + 1];

	fenfo_init(&file->fo, file->path);
#else
	if (!(file = calloc(1, offsetof(struct file, name) + namelen + 1)))
		return errno;
#endif

	file->fd = -1;
	file->flags = flags;
	memcpy(file->name, name, namelen);
	file->namelen = namelen;

	LIST_INSERT_HEAD(&nfy->dormant, file, le);
	LIST_INSERT_HEAD(&nfy->defunct, file, sle);
	LLRB_INSERT(files, &nfy->files, file);

#if ENABLE_KQUEUE
	if ((error = kq_readd(nfy, file)))
		goto error;

	NFY_LIST_MOVE(&nfy->dormant, file, le);
	nfy->changes = 0;
#elif ENABLE_FEN
	if ((error = fen_readd(nfy, file)))
		goto error;

	NFY_LIST_MOVE(&nfy->dormant, file, le);
	nfy->changes = 0;
#endif

	return 0;
error:
	discard(nfy, file);

	return error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
movq %rsi, %rdi
callq 0xf560
movq %rax, %r13
movl $0x24, %eax
cmpq $0xff, %r13
ja 0x34882
movq %r12, %rdi
movl $0x2f, %esi
movq %r13, %rdx
callq 0xfe90
movq %rax, %rcx
movl $0x15, %eax
testq %rcx, %rcx
jne 0x34882
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x34891
testq %rax, %rax
jne 0x34880
movq %r13, %rsi
addq $0x61, %rsi
movl $0x1, %edi
callq 0xf8a0
testq %rax, %rax
je 0x3471c
movq %rax, %r14
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl %ebp, 0x4(%rax)
leaq 0x60(%rax), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xfa60
movq %r13, 0x58(%r14)
leaq 0x10(%rbx), %rax
movq 0x10(%rbx), %rcx
movq %rcx, 0x18(%r14)
testq %rcx, %rcx
je 0x346b0
leaq 0x18(%r14), %rdx
movq %rdx, 0x20(%rcx)
movq %r14, 0x10(%rbx)
movq %rax, 0x20(%r14)
leaq 0x28(%rbx), %rax
movq 0x28(%rbx), %rcx
movq %rcx, 0x28(%r14)
testq %rcx, %rcx
je 0x346d4
movq %r14, %rdx
addq $0x28, %rdx
movq %rdx, 0x30(%rcx)
movq %r14, 0x28(%rbx)
movq %rax, 0x30(%r14)
movq 0x8(%rbx), %rcx
addq $0x8, %rbx
testq %rcx, %rcx
je 0x34728
movq %rcx, %r12
leaq 0x60(%rcx), %rsi
movq %r15, %rdi
callq 0x10250
testl %eax, %eax
je 0x34880
notl %eax
shrl $0x1f, %eax
movq 0x38(%r12,%rax,8), %rcx
testq %rcx, %rcx
jne 0x346e9
leaq 0x38(,%rax,8), %rax
addq %r12, %rax
jmp 0x3472e
callq 0xf0a0
movl (%rax), %eax
jmp 0x34882
xorl %r12d, %r12d
movq %rbx, %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%r14)
movb $0x1, 0x50(%r14)
movq %r12, 0x48(%r14)
movq %r14, (%rax)
testq %r12, %r12
je 0x34879
movq 0x38(%r12), %rax
testq %rax, %rax
je 0x3475b
cmpb $0x0, 0x50(%rax)
jne 0x34773
movq 0x40(%r12), %rax
testq %rax, %rax
je 0x34879
cmpb $0x1, 0x50(%rax)
jne 0x34879
movq %rbx, %rax
cmpq (%rbx), %r12
je 0x34790
movq 0x48(%r12), %rax
cmpq 0x38(%rax), %r12
je 0x3478c
addq $0x40, %rax
jmp 0x34790
addq $0x38, %rax
movq 0x48(%r12), %r12
movq (%rax), %rcx
movq 0x40(%rcx), %rdx
testq %rdx, %rdx
je 0x347e6
cmpb $0x1, 0x50(%rdx)
jne 0x347e6
movq 0x38(%rcx), %rsi
testq %rsi, %rsi
je 0x347b6
cmpb $0x0, 0x50(%rsi)
jne 0x347e6
movq 0x38(%rdx), %rsi
movq %rsi, 0x40(%rcx)
testq %rsi, %rsi
je 0x347c7
movq %rcx, 0x48(%rsi)
movq %rcx, 0x38(%rdx)
movb 0x50(%rcx), %sil
movb %sil, 0x50(%rdx)
movb $0x1, 0x50(%rcx)
movq 0x48(%rcx), %rsi
movq %rsi, 0x48(%rdx)
movq %rdx, 0x48(%rcx)
movq %rdx, (%rax)
movq (%rax), %rcx
movq 0x38(%rcx), %rdx
testq %rdx, %rdx
je 0x34837
cmpb $0x1, 0x50(%rdx)
jne 0x34837
movq 0x38(%rdx), %rsi
testq %rsi, %rsi
je 0x34837
cmpb $0x1, 0x50(%rsi)
jne 0x34837
movq 0x40(%rdx), %rsi
movq %rsi, 0x38(%rcx)
testq %rsi, %rsi
je 0x34818
movq %rcx, 0x48(%rsi)
movq %rcx, 0x40(%rdx)
movb 0x50(%rcx), %sil
movb %sil, 0x50(%rdx)
movb $0x1, 0x50(%rcx)
movq 0x48(%rcx), %rsi
movq %rsi, 0x48(%rdx)
movq %rdx, 0x48(%rcx)
movq %rdx, (%rax)
movq (%rax), %rax
movq 0x38(%rax), %rcx
testq %rcx, %rcx
je 0x34742
cmpb $0x1, 0x50(%rcx)
jne 0x34742
movq 0x40(%rax), %rdx
testq %rdx, %rdx
je 0x34742
cmpb $0x1, 0x50(%rdx)
jne 0x34742
xorb $0x1, 0x50(%rax)
xorb $0x1, 0x50(%rcx)
xorb $0x1, 0x50(%rdx)
jmp 0x34742
movq (%rbx), %rax
movb $0x0, 0x50(%rax)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq