// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl $0x1, -0x34(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movq -0x28(%rbp), %rdx
movq (%rdx), %rdx
movq 0x48(%rdx), %rdx
shrq %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jb 0x9ac3
movq -0x20(%rbp), %rdi
callq 0x9d60
movl $0x0, -0x34(%rbp)
jmp 0x9d0c
movq -0x18(%rbp), %rax
movsbl 0x1d(%rax), %eax
cmpl $0x1, %eax
jle 0x9b9c
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x38(%rcx), %rax
ja 0x9b69
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rcx
movq -0x30(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
cmpq 0x10(%rcx), %rax
jne 0x9b56
movq -0x28(%rbp), %rax
movl $0x1, 0x20(%rax)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x20(%rbp), %rcx
leaq -0x105(%rip), %rdx      # 0x9a40
callq 0xcb50
cmpl $0x0, %eax
je 0x9b54
jmp 0x9d3b
jmp 0x9b69
jmp 0x9b58
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x9adc
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jbe 0x9b97
jmp 0x9b79
leaq 0x1548e(%rip), %rdi     # 0x1f00e
movb $0x0, %al
callq 0x182f0
callq 0x20a0
movl $0x0, (%rax)
jmp 0x9d3b
jmp 0x9d0c
movq -0x18(%rbp), %rax
movsbl 0x1d(%rax), %eax
cmpl $0x1, %eax
jne 0x9cb1
movq $0x0, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x38(%rcx), %rax
ja 0x9c7a
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x10(%rax), %rax
movq -0x28(%rbp), %rcx
movq (%rcx), %rcx
movq 0x10(%rcx), %rcx
movq -0x28(%rbp), %rdx
movq (%rdx), %rdx
movq 0x48(%rdx), %rdx
shrq %rdx
subq %rdx, %rcx
cmpq %rcx, %rax
jae 0x9c67
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq $-0x1, 0x10(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x20(%rbp), %rcx
leaq 0x1da(%rip), %rdx       # 0x9e30
callq 0xcb50
cmpl $0x0, %eax
je 0x9c65
jmp 0x9d3b
jmp 0x9c67
jmp 0x9c69
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x9bb5
movq -0x20(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x9c87
jmp 0x9ca6
leaq 0x153b8(%rip), %rdi     # 0x1f046
leaq 0x1533d(%rip), %rsi     # 0x1efd2
movl $0xfd, %edx
leaq 0x153b9(%rip), %rcx     # 0x1f05a
callq 0x21d0
movq -0x18(%rbp), %rdi
callq 0x9f70
jmp 0x9d0c
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movq $-0x1, 0x10(%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rcx
leaq 0x13d(%rip), %rdx       # 0x9e30
callq 0xcb50
cmpl $0x0, %eax
je 0x9cff
jmp 0x9d3b
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x9f70
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0xa010
cmpl $0x0, -0x34(%rbp)
je 0x9d32
movq -0x28(%rbp), %rdi
callq 0x98d0
cmpl $0x0, %eax
je 0x9d32
jmp 0x9d4b
movl $0x0, -0x4(%rbp)
jmp 0x9d52
movq -0x28(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0xa010
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)