// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/kvlds/btree_cleaning.c
// Function: callback_find
static int
callback_find(void * cookie, struct node * N)
{
	struct cleaning_group * CG = cookie;
	struct cleaner * C = CG->C;
	size_t i;
	int repoke = 1;

	/*
	 * We're no longer trying to find a group to clean (unless we decide
	 * to descend into another node, in which case we're still looking
	 * for the right group of nodes).  We're not fetching a node any more
	 * (unless we start fetching more nodes).
	 */
	C->group_pending = 0;
	CG->pending_fetches--;

	/*
	 * If there aren't any old leaves under this node which aren't
	 * already being cleaned, we have nothing to do except free the
	 * cleaner group.  This can happen if we have a small tree and are
	 * cleaning it very aggressively.
	 */
	if (N->oldestncleaf >= C->T->nextblk - C->T->nnodes / 2) {
		/* Release the cleaner group. */
		free_cg(CG);

		/*
		 * No need to poke the cleaner again quite yet; there isn't
		 * any useful cleaning to be done right now.
		 */
		repoke = 0;

		/* That's all. */
		goto done;
	}

	/* If we have a node of height > 1, descend further. */
	if (N->height > 1) {
		/* Find the node we need to descend into. */
		for (i = 0; i <= N->nkeys; i++) {
			if (N->oldestncleaf ==
			    N->v.children[i]->oldestncleaf) {
				/* This is where the next clean happens. */
				C->group_pending = 1;
				CG->pending_fetches++;
				if (btree_node_descend(C->T, N->v.children[i],
				    callback_find, CG))
					goto err1;
				break;
			}
		}

		/* We should have found a node. */
		if (i > N->nkeys) {
			warn0("Node has oldestncleaf not matching"
			    " any of its children!");
			goto err1;
		}

		/* That's all we need to do. */
		goto done;
	}

	/* If we have a node of height 1, figure out which leaves to clean. */
	if (N->height == 1) {
		/* Look for nodes with low oldestncleaf values. */
		for (i = 0; i <= N->nkeys; i++) {
			if (N->v.children[i]->oldestncleaf <
			    C->T->nextblk - C->T->nnodes / 2) {
				/* This child needs to be cleaned. */
				CG->pending_fetches++;
				C->pending_cleans++;
				N->v.children[i]->oldestncleaf =
				    (uint64_t)(-1);
				if (btree_node_descend(C->T, N->v.children[i],
				    callback_clean, CG))
					goto err1;
			}
		}

		/* We should have found at least one child to clean. */
		assert(CG->pending_fetches);

		/* Recompute oldestncleaf upwards. */
		recompute_oncl(N);

		/* That's all we need to do. */
		goto done;
	}

	/* This node needs to be cleaned. */
	CG->pending_fetches++;
	C->pending_cleans++;
	N->oldestncleaf = (uint64_t)(-1);
	if (btree_node_descend(C->T, N, callback_clean, CG))
		goto err1;

	/* Recompute oldestncleaf upwards. */
	recompute_oncl(N->p_shadow);

done:
	/* Unlock the node. */
	btree_node_unlock(C->T, N);

	/* Launch cleaning if possible and appropriate. */
	if (repoke && poke(C))
		goto err0;

	/* Success! */
	return (0);

err1:
	btree_node_unlock(C->T, N);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
movq (%rdi), %rbx
andl $0x0, 0x20(%rbx)
movq %rsi, %r14
movq 0x20(%rdi), %rax
leaq -0x1(%rax), %rcx
movq %rcx, 0x20(%rdi)
movq 0x10(%rsi), %r13
movq (%rbx), %rdi
movq 0x10(%rdi), %r12
movq 0x48(%rdi), %rcx
shrq %rcx
subq %rcx, %r12
cmpq %r12, %r13
jae 0x6430
movb 0x1d(%r14), %cl
cmpb $0x2, %cl
jl 0x643d
movq 0x38(%r14), %rcx
movq 0x48(%r14), %rdx
xorl %ebp, %ebp
cmpq %rcx, %rbp
ja 0x64f5
movq (%rdx,%rbp,8), %rsi
cmpq 0x10(%rsi), %r13
je 0x64cb
incq %rbp
jmp 0x6414
movq %r15, %rdi
callq 0x657d
jmp 0x652c
cmpb $0x1, %cl
jne 0x64a2
xorl %ebp, %ebp
cmpq 0x38(%r14), %rbp
ja 0x651d
movq 0x48(%r14), %rax
movq (%rax,%rbp,8), %rax
movq (%rbx), %rdi
movq 0x10(%rdi), %rcx
movq 0x48(%rdi), %rdx
shrq %rdx
subq %rdx, %rcx
cmpq %rcx, 0x10(%rax)
jae 0x649d
incq 0x20(%r15)
incq 0x30(%rbx)
movq 0x48(%r14), %rax
movq (%rax,%rbp,8), %rax
orq $-0x1, 0x10(%rax)
movq 0x48(%r14), %rax
movq (%rax,%rbp,8), %rsi
leaq 0x15d(%rip), %rdx       # 0x65ee
movq %r15, %rcx
callq 0x7e08
testl %eax, %eax
jne 0x6510
incq %rbp
jmp 0x6444
movq %rax, 0x20(%r15)
incq 0x30(%rbx)
orq $-0x1, 0x10(%r14)
leaq 0x138(%rip), %rdx       # 0x65ee
movq %r14, %rsi
movq %r15, %rcx
callq 0x7e08
testl %eax, %eax
jne 0x6510
movq 0x20(%r14), %rdi
jmp 0x6527
movl $0x1, 0x20(%rbx)
movq %rax, 0x20(%r15)
movq 0x48(%r14), %rax
movq (%rax,%rbp,8), %rsi
leaq -0x122(%rip), %rdx      # 0x63c3
movq %r15, %rcx
callq 0x7e08
testl %eax, %eax
jne 0x6510
movq 0x38(%r14), %rcx
cmpq %rcx, %rbp
jbe 0x652c
leaq 0xb72d(%rip), %rdi      # 0x11c2e
xorl %eax, %eax
callq 0xe0e4
callq 0x20a0
andl $0x0, (%rax)
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x66cf
jmp 0x654a
cmpq $0x0, 0x20(%r15)
je 0x655e
movq %r14, %rdi
callq 0x668d
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x66cf
xorl %ebp, %ebp
cmpq %r12, %r13
jae 0x654d
movq %rbx, %rdi
callq 0x6303
testl %eax, %eax
je 0x654d
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb701(%rip), %rdi      # 0x11c66
leaq 0xb686(%rip), %rsi      # 0x11bf2
leaq 0xb707(%rip), %rcx      # 0x11c7a
movl $0xfd, %edx
callq 0x21c0