// File: /workspace/github_c_makefile_star2_O1/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 0xb202(%rip), %rdi      # 0x1068c
xorl %esi, %esi
callq 0xb058
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x54e2
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rbx)
movzbl 0x1d(%r14), %eax
cmpl $0x1, %eax
je 0x5506
testl %eax, %eax
jne 0x55e7
movq $0x1, 0x50(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x180(%rip), %rdx       # 0x5646
movq %r14, %rsi
movq %rbx, %rcx
callq 0x93cd
testl %eax, %eax
je 0x55e7
movq 0x28(%rbx), %rdi
callq 0xb5d8
movq 0x30(%rbx), %rdi
callq 0x2040
movq 0x18(%rbx), %rdi
callq 0x10bd2
movq %rbx, %rdi
callq 0x2040
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x5616
movq $0x0, 0x50(%rbx)
movq 0x18(%rbx), %rax
movq 0x10(%rax), %rsi
movq %r14, %rdi
callq 0x7fd9
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
cmpq 0x38(%r14), %r15
ja 0x55ae
addq %r15, %r13
cmpq %r13, %r15
jae 0x55ae
leaq 0xed(%rip), %r12        # 0x5646
incq 0x50(%rbx)
movq 0x10(%rbx), %rdi
movq 0x48(%r14), %rax
movq (%rax,%r15,8), %rsi
movq %r12, %rdx
movq %rbx, %rcx
callq 0x93cd
testl %eax, %eax
jne 0x54fc
cmpq 0x38(%r14), %r15
jae 0x5597
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rdi
movq 0x40(%r14), %rax
movq (%rax,%r15,8), %rsi
callq 0x10342
testl %eax, %eax
js 0x55ab
leaq 0x1(%r15), %rbp
cmpq 0x38(%r14), %r15
jae 0x55b1
movq %rbp, %r15
cmpq %r13, %rbp
jb 0x5559
jmp 0x55b1
incq %r15
movq %r15, %rbp
movq 0x38(%r14), %rax
incq %rax
cmpq %rax, %rbp
jae 0x55e7
movq 0x30(%rbx), %rdi
callq 0x2040
movq 0x40(%r14), %rax
movq -0x8(%rax,%rbp,8), %rdi
movzbl (%rdi), %esi
incq %rdi
callq 0x1028c
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x54fc
xorl %ebp, %ebp
testq %r14, %r14
je 0x5616
movq 0x10(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x5627
decq %rcx
movq %rcx, (%rax)
jne 0x5616
movq %r14, %rsi
callq 0x10885
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xf052(%rip), %rdi      # 0x14680
leaq 0xf071(%rip), %rsi      # 0x146a6
leaq 0xf083(%rip), %rcx      # 0x146bf
movl $0x88, %edx
callq 0x21c0