// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/kvlds/btree_find.c
// Function: findleaf
static int
findleaf(void * cookie)
{
	struct findleaf_cookie * C = cookie;
	struct node * NP = NULL;	/* Initialize to keep gcc happy. */
	size_t i;
	int rc;

	/* Sanity-check: We are now at a present node. */
	assert(node_present(C->N));

	/*
	 * Unlock the node we started at.  We don't need this lock as long as
	 * we pick up another lock before we return or make any calls which
	 * might evict a node.
	 */
	btree_node_unlock(C->T, C->N);

	/* Iterate down through parents. */
	while (node_present(C->N) && (C->N->height > C->h)) {
		/* Which child should we iterate into? */
		i = btree_find_child(C->N, C->k);

		/* Iterate into the child. */
		if ((C->e != NULL) && (i < C->N->nkeys)) {
			kvldskey_free(C->e);
			if ((C->e = kvldskey_dup(C->N->u.keys[i])) == NULL)
				goto err1;
		}
		NP = C->N;
		C->N = C->N->v.children[i];
	}

	/* If the node is not present, fetch it; else, do the callback. */
	if (!node_present(C->N)) {
		/*
		 * Lock the parent node, to make sure it doesn't get paged
		 * out before it is locked by the child we're paging in.
		 */
		btree_node_lock(C->T, NP);

		/* Fetch the child node.  This adds a lock to the parent. */
		if (btree_node_fetch(C->T, C->N, findleaf, C))
			goto err2;

		/* Release the lock we acquired on the parent node. */
		btree_node_unlock(C->T, NP);

		/* Success! */
		return (0);
	} else {
		/* We must have found a node of height <= h. */
		assert(C->N->height <= C->h);

		/* Lock the node. */
		btree_node_lock(C->T, C->N);

		/* Perform the callback. */
		if (C->e)
			rc = (C->callback_range)(C->cookie, C->N, C->e);
		else
			rc = (C->callback)(C->cookie, C->N);

		/* Free the cookie.  C->e was freed by the callback. */
		mpool_findleaf_free(C);

		/* Return status code from callback. */
		return (rc);
	}

err2:
	kvldskey_free(C->e);
err1:
	mpool_findleaf_free(C);

	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq 0x20(%rdi), %rsi
testb $0x2, 0x1c(%rsi)
jne 0x709d
movq %rdi, %rbx
movq 0x18(%rdi), %rdi
callq 0x72a9
movq 0x20(%rbx), %rax
xorl %r14d, %r14d
testb $0x2, 0x1c(%rax)
jne 0x700d
movsbl 0x1d(%rax), %ecx
cmpl %ecx, 0x30(%rbx)
jge 0x704a
movq 0x28(%rbx), %rsi
movq %rax, %rdi
callq 0x6e00
movq %rax, %r15
movq 0x20(%rbx), %r14
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x6fff
cmpq 0x38(%r14), %r15
jae 0x6fff
callq 0x2040
movq 0x20(%rbx), %rax
movq 0x40(%rax), %rax
movq (%rax,%r15,8), %rdi
movzbl (%rdi), %esi
incq %rdi
callq 0xe268
movq %rax, 0x38(%rbx)
testq %rax, %rax
je 0x703d
movq 0x20(%rbx), %r14
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x20(%rbx)
jmp 0x6fa1
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0x6f54
movq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rsi
leaq -0xaf(%rip), %rdx       # 0x6f79
movq %rbx, %rcx
callq 0x77c8
testl %eax, %eax
je 0x706c
movq 0x38(%rbx), %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x7152
pushq $-0x1
popq %rbp
jmp 0x7090
movq 0x18(%rbx), %rdi
movq %rax, %rsi
callq 0x6f54
movq 0x38(%rbx), %rdx
testq %rdx, %rdx
je 0x707c
movq 0x10(%rbx), %rdi
movq 0x20(%rbx), %rsi
callq *0x8(%rbx)
jmp 0x7086
movq 0x18(%rbx), %rdi
movq %r14, %rsi
callq 0x72a9
xorl %ebp, %ebp
jmp 0x7090
movq 0x10(%rbx), %rdi
movq 0x20(%rbx), %rsi
callq *(%rbx)
movl %eax, %ebp
movq %rbx, %rdi
callq 0x7152
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xaea3(%rip), %rdi      # 0x11f47
leaq 0xade4(%rip), %rsi      # 0x11e8f
leaq 0xaea8(%rip), %rcx      # 0x11f5a
pushq $0x7f
popq %rdx
callq 0x21c0