// File: /workspace/github_c_makefile_star2_O3/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 0x744d
movb 0x1d(%rbx), %cl
cmpb $0x2, %cl
jl 0x745a
movq 0x38(%rbx), %rcx
movq 0x48(%rbx), %rdx
xorl %r12d, %r12d
movq (%rdx,%r12,8), %rsi
cmpq 0x10(%rsi), %r13
je 0x74d8
incq %r12
cmpq %rcx, %r12
jbe 0x7432
jmp 0x7503
movq %r15, %rdi
callq 0x7609
jmp 0x757b
cmpb $0x1, %cl
jne 0x7523
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 0x74bc
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 0x1d6(%rip), %rdx       # 0x7682
movq %r15, %rcx
callq 0x9383
testl %eax, %eax
jne 0x7549
incq %r12
cmpq 0x38(%rbx), %r12
jbe 0x7466
cmpq $0x0, 0x20(%r15)
je 0x75ea
movq %rbx, %rdi
jmp 0x7576
movl $0x1, 0x20(%r14)
movq %rax, 0x20(%r15)
movq 0x48(%rbx), %rax
movq (%rax,%r12,8), %rsi
leaq -0x116(%rip), %rdx      # 0x73dd
movq %r15, %rcx
callq 0x9383
testl %eax, %eax
jne 0x7549
movq 0x38(%rbx), %rcx
cmpq %rcx, %r12
jbe 0x757b
leaq 0xd6ff(%rip), %rdi      # 0x14c0e
xorl %eax, %eax
callq 0x100ef
callq 0x20a0
movl $0x0, (%rax)
jmp 0x7549
movq %rax, 0x20(%r15)
incq 0x30(%r14)
movq $-0x1, 0x10(%rbx)
leaq 0x148(%rip), %rdx       # 0x7682
movq %rbx, %rsi
movq %r15, %rcx
callq 0x9383
testl %eax, %eax
je 0x7572
movq (%r14), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%rbx,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x75cb
decq %rcx
movq %rcx, (%rax)
jne 0x75b5
movq %rbx, %rsi
callq 0x107ea
jmp 0x75b5
movq 0x20(%rbx), %rdi
callq 0x7778
movq (%r14), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%rbx,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x75cb
decq %rcx
movq %rcx, (%rax)
jne 0x75a2
movq %rbx, %rsi
callq 0x107ea
xorl %ebx, %ebx
cmpq %rbp, %r13
jae 0x75ba
movq %r14, %rdi
callq 0x730a
testl %eax, %eax
je 0x75ba
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 0xd07e(%rip), %rdi      # 0x14650
leaq 0xd09d(%rip), %rsi      # 0x14676
leaq 0xd0af(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
leaq 0xd655(%rip), %rdi      # 0x14c46
leaq 0xd5da(%rip), %rsi      # 0x14bd2
leaq 0xd65b(%rip), %rcx      # 0x14c5a
movl $0xfd, %edx
callq 0x21c0