// File: /workspace/github_c_makefile_star2_O2/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 0xf580
cmpq $0xff, %rax
jbe 0x2eb32
pushq $0x24
jmp 0x2eb4a
movq %rax, %r13
pushq $0x2f
popq %rsi
movq %r12, %rdi
movq %rax, %rdx
callq 0xff20
testq %rax, %rax
je 0x2eb5a
pushq $0x15
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x2ec9d
testq %rax, %rax
jne 0x2ec8a
movq %r13, %rsi
addq $0x61, %rsi
pushq $0x1
popq %rdi
callq 0xf8f0
testq %rax, %rax
je 0x2ec91
movq %rax, %r14
orl $-0x1, (%rax)
movl %ebp, 0x4(%rax)
leaq 0x60(%rax), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0xfad0
movq %r13, 0x58(%r14)
leaq 0x10(%rbx), %rax
movq 0x10(%rbx), %rcx
movq %rcx, 0x18(%r14)
testq %rcx, %rcx
je 0x2ebc1
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 0x2ebe5
movq %r14, %rdx
addq $0x28, %rdx
movq %rdx, 0x30(%rcx)
movq %r14, 0x28(%rbx)
movq %rax, 0x30(%r14)
addq $0x8, %rbx
xorl %eax, %eax
pushq $0x38
popq %r12
pushq $0x40
popq %r13
movq %rbx, %rcx
movq (%rcx), %rbp
testq %rbp, %rbp
je 0x2ec26
leaq 0x60(%rbp), %rsi
movq %r15, %rdi
callq 0x102e0
movq %r12, %rcx
testl %eax, %eax
js 0x2ec1e
movq %r13, %rcx
je 0x2ec8a
addq %rbp, %rcx
movq %rbp, %rax
jmp 0x2ebfe
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%r14)
movb $0x1, 0x50(%r14)
movq %rax, 0x48(%r14)
movq %r14, (%rcx)
testq %rax, %rax
je 0x2ec83
movq 0x38(%rax), %rcx
testq %rcx, %rcx
je 0x2ec4e
cmpb $0x0, 0x50(%rcx)
jne 0x2ec5d
movq 0x40(%rax), %rcx
testq %rcx, %rcx
je 0x2ec83
cmpb $0x1, 0x50(%rcx)
jne 0x2ec83
movq 0x48(%rax), %r14
movq %rbx, %rdi
cmpq (%rbx), %rax
je 0x2ec79
cmpq 0x38(%r14), %rax
je 0x2ec75
leaq 0x40(%r14), %rdi
jmp 0x2ec79
leaq 0x38(%r14), %rdi
callq 0x2ee1b
movq %r14, %rax
jmp 0x2ec3a
movq (%rbx), %rax
movb $0x0, 0x50(%rax)
xorl %eax, %eax
jmp 0x2eb4b
callq 0xf0a0
movl (%rax), %eax
jmp 0x2eb4b