// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0xb510
cmpl $0x0, %eax
je 0xb000
jmp 0xb01f
leaq 0x14320(%rip), %rdi     # 0x1f327
leaq 0x14261(%rip), %rsi     # 0x1f26f
movl $0x7f, %edx
leaq 0x14320(%rip), %rcx     # 0x1f33a
callq 0x21d0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0xb550
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0xb510
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x2d(%rbp)
je 0xb066
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movsbl 0x1d(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x30(%rcx), %eax
setg %al
movb %al, -0x2d(%rbp)
movb -0x2d(%rbp), %al
testb $0x1, %al
jne 0xb072
jmp 0xb12d
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0xadc0
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0xb100
movq -0x28(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
cmpq 0x38(%rcx), %rax
jae 0xb100
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x2040
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x40(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
addq $0x1, %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x40(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movzbl (%rax), %eax
movl %eax, %esi
callq 0x18530
movq -0x18(%rbp), %rcx
movq %rax, 0x38(%rcx)
cmpq $0x0, %rax
jne 0xb0fe
jmp 0xb24e
jmp 0xb100
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq 0x48(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0xb034
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0xb510
cmpl $0x0, %eax
jne 0xb197
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0xafa0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x18(%rbp), %rcx
leaq -0x19b(%rip), %rdx      # 0xafd0
callq 0xc060
cmpl $0x0, %eax
je 0xb17a
jmp 0xb241
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0xb550
movl $0x0, -0x4(%rbp)
jmp 0xb25e
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movsbl 0x1d(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jg 0xb1ae
jmp 0xb1cd
leaq 0x1419a(%rip), %rdi     # 0x1f34f
leaq 0x140b3(%rip), %rsi     # 0x1f26f
movl $0xaa, %edx
leaq 0x14172(%rip), %rcx     # 0x1f33a
callq 0x21d0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
callq 0xafa0
movq -0x18(%rbp), %rax
cmpq $0x0, 0x38(%rax)
je 0xb214
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rdi
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rsi
movq -0x18(%rbp), %rcx
movq 0x38(%rcx), %rdx
callq *%rax
movl %eax, -0x2c(%rbp)
jmp 0xb230
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rdi
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rsi
callq *%rax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rdi
callq 0xb360
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xb25e
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x2040
movq -0x18(%rbp), %rdi
callq 0xb360
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)