// File: /workspace/github_c_makefile_star2_O3/Tarsnap[P]kivaloo/kvlds/dispatch_nmr.c
// Function: callback_range_gotnode
static int
callback_range_gotnode(void * cookie, struct node * N,
    struct kvldskey * end)
{
	struct nmr_cookie * C = cookie;
	size_t start;
	size_t stop;
	size_t i;

	/* Record the end-of-range key. */
	C->end = end;

	/* Record how far all keys in the range must match. */
	C->mlen = N->mlen_t;

	/* Create a heap for holding key-value pairs. */
	if ((C->H = ptrheap_init(kvpair_cmp, NULL, (void *)&C->mlen)) == NULL)
		goto err1;

	/* We don't have any key-value pairs yet. */
	C->nkeys = 0;
	C->rlen = 0;

	/* Leaves and parents get handled differently. */
	switch (N->height) {
	case 0:
		/* Descend into a single leaf. */
		C->leavesleft = 1;
		if (btree_node_descend(C->T, N, callback_range_gotleaf, C))
			goto err2;
		break;
	case 1:
		/* Not descending into any leaves yet. */
		C->leavesleft = 0;

		/* Figure out which leaf to start with. */
		start = btree_find_child(N, C->R->range_start);

		/* Figure out the maximum number of leaves to process. */
		stop = start + C->R->range_max / C->T->pagelen;
		if (stop == start)
			stop = start + 1;

		/* Process leaf nodes. */
		for (i = start; (i <= N->nkeys) && (i < stop); i++) {
			/* Do this leaf. */
			C->leavesleft += 1;
			if (btree_node_descend(C->T, N->v.children[i],
			    callback_range_gotleaf, C))
				goto err0;

			/* Stop if we've gone too far. */
			if ((i < N->nkeys) && (kvldskey_cmp(C->R->range_end,
			    N->u.keys[i]) < 0)) {
				i++;
				break;
			}
		}

		/* Adjust our end pointer if we didn't do all the leaves. */
		if (i < N->nkeys + 1) {
			kvldskey_free(C->end);
			if ((C->end = kvldskey_dup(N->u.keys[i - 1])) == NULL)
				goto err0;
		}
		break;
	}

	/* Release the lock picked up by btree_find_range. */
	btree_node_unlock(C->T, N);

	/* Success! */
	return (0);

err2:
	ptrheap_free(C->H);
err1:
	kvldskey_free(C->end);
	proto_kvlds_request_free(C->R);
	free(C);
err0:
	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq %rdx, 0x30(%rdi)
movzbl 0x1e(%rsi), %eax
leaq 0x38(%rdi), %rdx
movq %rax, 0x38(%rdi)
leaq 0xb146(%rip), %rdi      # 0x105fc
xorl %esi, %esi
callq 0xaf04
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x550e
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rbx)
movzbl 0x1d(%r14), %eax
cmpl $0x1, %eax
je 0x5532
testl %eax, %eax
jne 0x561c
movq $0x1, 0x50(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x184(%rip), %rdx       # 0x5676
movq %r14, %rsi
movq %rbx, %rcx
callq 0x9383
testl %eax, %eax
je 0x561c
movq 0x28(%rbx), %rdi
callq 0xb493
movq 0x30(%rbx), %rdi
callq 0x2040
movq 0x18(%rbx), %rdi
callq 0x10b73
movq %rbx, %rdi
callq 0x2040
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x5646
movq $0x0, 0x50(%rbx)
movq 0x18(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x7f81
movq %rax, %r15
movq 0x10(%rbx), %rax
movq 0x18(%rbx), %rcx
movl 0xc(%rcx), %ecx
movq (%rax), %rsi
movq %rcx, %rax
xorl %edx, %edx
divq %rsi
cmpq %rcx, %rsi
movl $0x1, %r13d
cmovbeq %rax, %r13
movq 0x38(%r14), %rax
cmpq %rax, %r15
ja 0x55e7
addq %r15, %r13
cmpq %r13, %r15
jae 0x55e7
leaq 0xee(%rip), %r12        # 0x5676
incq 0x50(%rbx)
movq 0x10(%rbx), %rdi
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x9383
testl %eax, %eax
jne 0x5528
movq 0x38(%r14), %rax
cmpq %rax, %r15
jae 0x55cd
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdi
movq 0x40(%r14), %rax
movq (%rax,%r15,8), %rsi
callq 0x102c6
testl %eax, %eax
js 0x55e0
movq 0x38(%r14), %rax
leaq 0x1(%r15), %rbp
cmpq %rax, %r15
jae 0x55ea
movq %rbp, %r15
cmpq %r13, %rbp
jb 0x5588
jmp 0x55ea
incq %r15
movq 0x38(%r14), %rax
movq %r15, %rbp
incq %rax
cmpq %rax, %rbp
jae 0x561c
movq 0x30(%rbx), %rdi
callq 0x2040
movq 0x40(%r14), %rax
movq -0x8(%rax,%rbp,8), %rdi
movzbl (%rdi), %esi
incq %rdi
callq 0x10214
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x5528
movq 0x10(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x5657
xorl %ebx, %ebx
decq %rcx
movq %rcx, (%rax)
jne 0x5646
movq %r14, %rsi
callq 0x107ea
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xeff2(%rip), %rdi      # 0x14650
leaq 0xf011(%rip), %rsi      # 0x14676
leaq 0xf023(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0