// File: /workspace/github_c_makefile_star2_O1/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 %rsi, %rbx
movq %rdi, %r15
movq (%rdi), %r14
movl $0x0, 0x20(%r14)
movq 0x20(%rdi), %rax
leaq -0x1(%rax), %rcx
movq %rcx, 0x20(%rdi)
movq 0x10(%rsi), %r13
movq (%r14), %rdi
movq 0x10(%rdi), %rbp
movq 0x48(%rdi), %rcx
shrq %rcx
subq %rcx, %rbp
cmpq %rbp, %r13
jae 0x74a8
movb 0x1d(%rbx), %cl
cmpb $0x2, %cl
jl 0x74b5
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rdx
xorl %r12d, %r12d
movq (%rdx,%r12,8), %rsi
cmpq 0x10(%rsi), %r13
je 0x7533
incq %r12
cmpq %rcx, %r12
jbe 0x748d
jmp 0x755a
movq %r15, %rdi
callq 0x766b
jmp 0x75d8
cmpb $0x1, %cl
jne 0x757b
xorl %r12d, %r12d
movq 0x48(%rbx), %rax
movq (%rax,%r12,8), %rax
movq (%r14), %rdi
movq 0x10(%rdi), %rcx
movq 0x48(%rdi), %rdx
shrq %rdx
subq %rdx, %rcx
cmpq %rcx, 0x10(%rax)
jae 0x7517
incq 0x20(%r15)
incq 0x30(%r14)
movq 0x48(%rbx), %rax
movq (%rax,%r12,8), %rax
movq $-0x1, 0x10(%rax)
movq 0x48(%rbx), %rax
movq (%rax,%r12,8), %rsi
leaq 0x1e1(%rip), %rdx       # 0x76e8
movq %r15, %rcx
callq 0x93cd
testl %eax, %eax
jne 0x75a1
incq %r12
cmpq 0x38(%rbx), %r12
jbe 0x74c1
cmpq $0x0, 0x20(%r15)
je 0x764c
movq %rbx, %rdi
jmp 0x75d3
movl $0x1, 0x20(%r14)
movq %rax, 0x20(%r15)
movq 0x48(%rbx), %rax
movq (%rax,%r12,8), %rsi
leaq -0x116(%rip), %rdx      # 0x7438
movq %r15, %rcx
callq 0x93cd
testl %eax, %eax
jne 0x75a1
cmpq 0x38(%rbx), %r12
jbe 0x75d8
leaq 0xd6d7(%rip), %rdi      # 0x14c3e
xorl %eax, %eax
callq 0x10167
callq 0x20a0
movl $0x0, (%rax)
jmp 0x75a1
movq %rax, 0x20(%r15)
incq 0x30(%r14)
movq $-0x1, 0x10(%rbx)
leaq 0x156(%rip), %rdx       # 0x76e8
movq %rbx, %rsi
movq %r15, %rcx
callq 0x93cd
testl %eax, %eax
je 0x75cf
testq %rbx, %rbx
je 0x7617
movq (%r14), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%rbx,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x762d
decq %rcx
movq %rcx, (%rax)
jne 0x7617
movq %rbx, %rsi
callq 0x10885
jmp 0x7617
movq 0x20(%rbx), %rdi
callq 0x77d1
testq %rbx, %rbx
je 0x7604
movq (%r14), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%rbx,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x762d
decq %rcx
movq %rcx, (%rax)
jne 0x7604
movq %rbx, %rsi
callq 0x10885
xorl %ebx, %ebx
cmpq %rbp, %r13
jae 0x761c
movq %r14, %rdi
callq 0x7365
testl %eax, %eax
je 0x761c
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd04c(%rip), %rdi      # 0x14680
leaq 0xd06b(%rip), %rsi      # 0x146a6
leaq 0xd07d(%rip), %rcx      # 0x146bf
movl $0x88, %edx
callq 0x21c0
leaq 0xd623(%rip), %rdi      # 0x14c76
leaq 0xd5a8(%rip), %rsi      # 0x14c02
leaq 0xd629(%rip), %rcx      # 0x14c8a
movl $0xfd, %edx
callq 0x21c0