// File: /workspace/github_c_makefile_star2_O1/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 0x8332
movq %rdi, %rbx
testq %rsi, %rsi
je 0x819a
movq 0x18(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%rsi,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x8351
decq %rcx
movq %rcx, (%rax)
jne 0x819a
callq 0x10885
movq 0x20(%rbx), %rax
testb $0x2, 0x1c(%rax)
sete %cl
jne 0x821f
movsbl 0x1d(%rax), %edx
cmpl %edx, 0x30(%rbx)
jge 0x8224
movq 0x28(%rbx), %rsi
movq %rax, %rdi
callq 0x7fd9
movq %rax, %r15
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x81fb
movq 0x20(%rbx), %rax
cmpq 0x38(%rax), %r15
jae 0x81fb
callq 0x2040
movq 0x20(%rbx), %rax
movq 0x40(%rax), %rax
movq (%rax,%r15,8), %rdi
movzbl (%rdi), %esi
incq %rdi
callq 0x1028c
movq %rax, 0x38(%rbx)
testq %rax, %rax
je 0x82d1
movq 0x20(%rbx), %r14
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x20(%rbx)
testb $0x2, 0x1c(%rax)
sete %cl
jne 0x8281
movsbl 0x1d(%rax), %edx
cmpl %edx, 0x30(%rbx)
jl 0x81b0
jmp 0x8227
xorl %r14d, %r14d
jmp 0x8281
xorl %r14d, %r14d
testb %cl, %cl
je 0x8281
movsbl 0x1d(%rax), %ecx
cmpl %ecx, 0x30(%rbx)
jl 0x8370
testq %rax, %rax
je 0x8264
movq 0x18(%rbx), %rcx
movq 0x30(%rcx), %rdi
movq 0x20(%rdi), %rcx
movq (%rax,%rcx), %rcx
movq (%rcx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rcx)
testq %rdx, %rdx
jne 0x8264
movq %rax, %rsi
callq 0x107a3
movq 0x38(%rbx), %rdx
testq %rdx, %rdx
je 0x8311
movq 0x10(%rbx), %rdi
movq 0x20(%rbx), %rsi
callq *0x8(%rbx)
jmp 0x831b
testq %r14, %r14
je 0x82ad
movq 0x18(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rax)
testq %rcx, %rcx
jne 0x82ad
movq %r14, %rsi
callq 0x107a3
movq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rsi
leaq -0x168(%rip), %rdx      # 0x8154
movq %rbx, %rcx
callq 0x8c20
testl %eax, %eax
je 0x82e0
movq 0x38(%rbx), %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x8581
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x8325
xorl %ebp, %ebp
testq %r14, %r14
je 0x8325
movq 0x18(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x8351
decq %rcx
movq %rcx, (%rax)
jne 0x8325
movq %r14, %rsi
callq 0x10885
jmp 0x8325
movq 0x10(%rbx), %rdi
movq 0x20(%rbx), %rsi
callq *(%rbx)
movl %eax, %ebp
movq %rbx, %rdi
callq 0x8581
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xcc1e(%rip), %rdi      # 0x14f57
leaq 0xcb5f(%rip), %rsi      # 0x14e9f
leaq 0xcc23(%rip), %rcx      # 0x14f6a
movl $0x7f, %edx
callq 0x21c0
leaq 0xc328(%rip), %rdi      # 0x14680
leaq 0xc347(%rip), %rsi      # 0x146a6
leaq 0xc359(%rip), %rcx      # 0x146bf
movl $0x88, %edx
callq 0x21c0
leaq 0xcc08(%rip), %rdi      # 0x14f7f
leaq 0xcb21(%rip), %rsi      # 0x14e9f
leaq 0xcbe5(%rip), %rcx      # 0x14f6a
movl $0xaa, %edx
callq 0x21c0