// File: /workspace/github_c_makefile_star2_O3/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), %rcx
testb $0x2, 0x1c(%rcx)
jne 0x82f1
movq %rdi, %rbx
movq 0x18(%rdi), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%rcx,%rax), %rax
movq (%rax), %rdx
testq %rdx, %rdx
je 0x82d2
decq %rdx
movq %rdx, (%rax)
jne 0x8147
movq %rcx, %rsi
callq 0x107ea
movq 0x20(%rbx), %rcx
testb $0x2, 0x1c(%rcx)
jne 0x823e
movsbl 0x1d(%rcx), %eax
cmpl %eax, 0x30(%rbx)
jge 0x8270
movq 0x28(%rbx), %rsi
movq %rcx, %rdi
callq 0x7f81
movq %rax, %r15
movq 0x20(%rbx), %r14
movq 0x38(%rbx), %rdi
testq %rdi, %rdi
je 0x81ad
cmpq 0x38(%r14), %r15
jae 0x81ad
callq 0x2040
movq 0x20(%rbx), %rax
movq 0x40(%rax), %rax
movq (%rax,%r15,8), %rdi
movzbl (%rdi), %esi
incq %rdi
callq 0x10214
movq %rax, 0x38(%rbx)
testq %rax, %rax
je 0x8261
movq 0x20(%rbx), %r14
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %rcx
movq %rcx, 0x20(%rbx)
testb $0x2, 0x1c(%rcx)
je 0x8151
movq 0x18(%rbx), %rdi
movq 0x30(%rdi), %rax
movq 0x20(%rax), %rdx
movq (%r14,%rdx), %rdx
movq (%rdx), %rsi
leaq 0x1(%rsi), %r8
movq %r8, (%rdx)
testq %rsi, %rsi
jne 0x81f1
movq %rax, %rdi
movq %r14, %rsi
callq 0x1070f
movq 0x18(%rbx), %rdi
movq 0x20(%rbx), %rcx
leaq -0xf9(%rip), %rdx       # 0x80ff
movq %rcx, %rsi
movq %rbx, %rcx
callq 0x8ba0
testl %eax, %eax
jne 0x8258
movq 0x18(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x82d2
xorl %ebp, %ebp
decq %rcx
movq %rcx, (%rax)
jne 0x82c5
movq %r14, %rsi
callq 0x107ea
jmp 0x82c5
movq 0x18(%rbx), %rdi
leaq -0x14a(%rip), %rdx      # 0x80ff
movq %rcx, %rsi
movq %rbx, %rcx
callq 0x8ba0
testl %eax, %eax
je 0x82ad
movq 0x38(%rbx), %rdi
callq 0x2040
movq %rbx, %rdi
callq 0x850f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x82c5
movq 0x18(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%rcx,%rax), %rax
movq (%rax), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rax)
testq %rdx, %rdx
jne 0x8297
movq %rcx, %rsi
callq 0x1070f
movq 0x38(%rbx), %rdx
testq %rdx, %rdx
je 0x82b1
movq 0x10(%rbx), %rdi
movq 0x20(%rbx), %rsi
callq *0x8(%rbx)
jmp 0x82bb
xorl %ebp, %ebp
jmp 0x82c5
movq 0x10(%rbx), %rdi
movq 0x20(%rbx), %rsi
callq *(%rbx)
movl %eax, %ebp
movq %rbx, %rdi
callq 0x850f
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc377(%rip), %rdi      # 0x14650
leaq 0xc396(%rip), %rsi      # 0x14676
leaq 0xc3a8(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
leaq 0xcc2f(%rip), %rdi      # 0x14f27
leaq 0xcb70(%rip), %rsi      # 0x14e6f
leaq 0xcc34(%rip), %rcx      # 0x14f3a
movl $0x7f, %edx
callq 0x21c0