// File: /workspace/github_c_makefile_star2_O3/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, %r15d
movq %rsi, %r12
movq %rdi, %rbx
movq %rsi, %rdi
callq 0xf560
movl $0x24, %ebp
cmpq $0xff, %rax
ja 0x34284
movq %rax, %r13
movq %r12, %rdi
movl $0x2f, %esi
movq %rax, %rdx
callq 0xfe90
movl $0x15, %ebp
testq %rax, %rax
jne 0x34284
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x34295
xorl %ebp, %ebp
testq %rax, %rax
jne 0x34284
movq %r13, %rsi
addq $0x61, %rsi
movl $0x1, %edi
callq 0xf8a0
testq %rax, %rax
je 0x3425e
movq %rax, %r14
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl %r15d, 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 0x340a0
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 0x340c4
movq %r14, %rdx
addq $0x28, %rdx
movq %rdx, 0x30(%rcx)
movq %r14, 0x28(%rbx)
movq %rax, 0x30(%r14)
movq 0x8(%rbx), %rax
addq $0x8, %rbx
testq %rax, %rax
je 0x34267
movq %rax, %r12
leaq 0x60(%rax), %rsi
movq %r15, %rdi
callq 0x10250
movl $0x38, %ecx
testl %eax, %eax
js 0x34100
movl $0x40, %ecx
je 0x34284
movq (%r12,%rcx), %rax
testq %rax, %rax
jne 0x340dd
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%r14)
movb $0x1, 0x50(%r14)
movq %r12, 0x48(%r14)
movq %r14, (%r12,%rcx)
movq %r12, %rax
movq 0x38(%r12), %rcx
testq %rcx, %rcx
je 0x34131
cmpb $0x0, 0x50(%rcx)
jne 0x34148
movq 0x40(%rax), %rcx
testq %rcx, %rcx
je 0x34259
cmpb $0x1, 0x50(%rcx)
jne 0x34259
movq (%rbx), %rdx
movq 0x48(%rax), %r12
movq %rbx, %rcx
cmpq %rdx, %rax
je 0x34175
leaq 0x38(%r12), %rdx
leaq 0x40(%r12), %rcx
xorl %esi, %esi
cmpq 0x38(%r12), %rax
setne %sil
cmoveq %rdx, %rcx
movq 0x38(%r12,%rsi,8), %rdx
movq 0x40(%rdx), %rax
testq %rax, %rax
je 0x34193
cmpb $0x1, 0x50(%rax)
jne 0x34193
movq 0x38(%rdx), %rsi
testq %rsi, %rsi
je 0x34198
cmpb $0x0, 0x50(%rsi)
je 0x34198
movq %rdx, %rax
jmp 0x341c8
movq 0x38(%rax), %rsi
movq %rsi, 0x40(%rdx)
testq %rsi, %rsi
je 0x341a9
movq %rdx, 0x48(%rsi)
movq %rdx, 0x38(%rax)
movb 0x50(%rdx), %sil
movb %sil, 0x50(%rax)
movb $0x1, 0x50(%rdx)
movq 0x48(%rdx), %rsi
movq %rsi, 0x48(%rax)
movq %rax, 0x48(%rdx)
movq %rax, (%rcx)
movq 0x38(%rax), %rdx
testq %rdx, %rdx
je 0x34250
movb 0x50(%rdx), %sil
cmpb $0x1, %sil
jne 0x3422c
movq 0x38(%rdx), %rdi
testq %rdi, %rdi
je 0x3422c
cmpb $0x1, 0x50(%rdi)
jne 0x3422c
movq 0x40(%rdx), %rsi
movq %rsi, 0x38(%rax)
testq %rsi, %rsi
je 0x341fb
movq %rax, 0x48(%rsi)
movq %rax, 0x40(%rdx)
movb 0x50(%rax), %sil
movb %sil, 0x50(%rdx)
movb $0x1, 0x50(%rax)
movq 0x48(%rax), %rsi
movq %rsi, 0x48(%rdx)
movq %rdx, 0x48(%rax)
movq %rdx, (%rcx)
movq 0x38(%rdx), %rcx
testq %rcx, %rcx
je 0x34250
movb 0x50(%rcx), %sil
movq %rdx, %rax
jmp 0x3422f
movq %rdx, %rcx
testb $0x1, %sil
je 0x34250
movq 0x40(%rax), %rdx
testq %rdx, %rdx
je 0x34250
cmpb $0x1, 0x50(%rdx)
jne 0x34250
xorb $0x1, 0x50(%rax)
xorb $0x1, 0x50(%rcx)
xorb $0x1, 0x50(%rdx)
testq %r12, %r12
jne 0x3411e
movq (%rbx), %r14
jmp 0x3427f
callq 0xf0a0
movl (%rax), %ebp
jmp 0x34284
xorps %xmm0, %xmm0
movups %xmm0, 0x38(%r14)
movb $0x1, 0x50(%r14)
movq $0x0, 0x48(%r14)
movq %r14, (%rbx)
movb $0x0, 0x50(%r14)
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq