// File: /workspace/github_c_makefile_star2_O0/krinkinmu[P]64bit/vfs.c
// Function: vfs_lookup
static struct fs_entry *vfs_lookup(struct fs_entry *dir, const char *name,
			bool create, int *rc)
{
	struct fs_node *node = dir->node;
	struct rb_node **plink = &dir->children.root;
	struct rb_node *parent = 0;

	if (!node->ops->lookup) {
		*rc = -ENOTSUP;
		return 0;
	}

	const bool enabled = spin_lock_irqsave(&dir->lock);

	while (*plink) {
		struct fs_entry *entry = TREE_ENTRY(*plink, struct fs_entry,
			link);

		const int cmp = strcmp(entry->name, name);

		if (!cmp) {
			*rc = 0;
			vfs_entry_get(entry);
			spin_unlock_irqrestore(&dir->lock, enabled);
			return entry;
		}

		parent = *plink;
		if (cmp < 0)
			plink = &parent->right;
		else
			plink = &parent->left;
	}

	struct fs_entry *entry = vfs_entry_create(name);

	if (!entry) {
		spin_unlock_irqrestore(&dir->lock, enabled);
		*rc = -ENOMEM;
		return 0;
	}

	rb_link(&entry->link, parent, plink);
	rb_insert(&entry->link, &dir->children);
	entry->parent = vfs_entry_get(dir);
	entry->cached = true;
	spin_unlock_irqrestore(&dir->lock, enabled);

	*rc = node->ops->lookup(node, entry);
	if (*rc && !create) {
		vfs_entry_put(entry);
		return 0;
	}

	return entry;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
cmpq $0x0, 0x28(%rax)
jne 0xffffffff8010a2f1
movq -0x28(%rbp), %rax
movl $0xfffffffd, (%rax)     # imm = 0xFFFFFFFD
movq $0x0, -0x8(%rbp)
jmp 0xffffffff8010a481
movq -0x10(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
callq 0xffffffff80109590
andb $0x1, %al
movb %al, -0x41(%rbp)
movq -0x38(%rbp), %rax
cmpq $0x0, (%rax)
je 0xffffffff8010a39d
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rsi
callq 0xffffffff80101980
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jne 0xffffffff8010a371
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x50(%rbp), %rdi
callq 0xffffffff80109620
movq -0x10(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movb -0x41(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0xffffffff801095f0
movq -0x50(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xffffffff8010a481
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x54(%rbp)
jge 0xffffffff8010a390
movq -0x40(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x38(%rbp)
jmp 0xffffffff8010a398
movq -0x40(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0xffffffff8010a306
movq -0x18(%rbp), %rdi
callq 0xffffffff8010afa0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0xffffffff8010a3e0
movq -0x10(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movb -0x41(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0xffffffff801095f0
movq -0x28(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq $0x0, -0x8(%rbp)
jmp 0xffffffff8010a481
movq -0x60(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0xffffffff8010b020
movq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq $0x18, %rsi
callq 0xffffffff8010b5d0
movq -0x10(%rbp), %rdi
callq 0xffffffff80109620
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x60(%rbp), %rax
movb $0x1, 0x130(%rax)
movq -0x10(%rbp), %rdi
addq $0x138, %rdi            # imm = 0x138
movb -0x41(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0xffffffff801095f0
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x28(%rax), %rax
movq -0x30(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq *%rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0xffffffff8010a479
testb $0x1, -0x19(%rbp)
jne 0xffffffff8010a479
movq -0x60(%rbp), %rdi
callq 0xffffffff80109680
movq $0x0, -0x8(%rbp)
jmp 0xffffffff8010a481
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)