// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movzbl 0x1e(%rax), %eax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x28(%rbp), %rdx
addq $0x38, %rdx
leaq 0x126a7(%rip), %rdi     # 0x18d30
xorl %eax, %eax
movl %eax, %esi
callq 0x101b0
movq -0x28(%rbp), %rcx
movq %rax, 0x28(%rcx)
cmpq $0x0, %rax
jne 0x66a5
jmp 0x68da
movq -0x28(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x48(%rax)
movq -0x18(%rbp), %rax
movsbl 0x1d(%rax), %eax
movl %eax, -0x44(%rbp)
testl %eax, %eax
je 0x66db
jmp 0x66ce
movl -0x44(%rbp), %eax
subl $0x1, %eax
je 0x6712
jmp 0x68b3
movq -0x28(%rbp), %rax
movq $0x1, 0x50(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
movq -0x28(%rbp), %rcx
leaq 0x2d2(%rip), %rdx       # 0x69d0
callq 0xcb50
cmpl $0x0, %eax
je 0x670d
jmp 0x68cd
jmp 0x68b3
movq -0x28(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rsi
callq 0xadc0
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movl 0xc(%rax), %eax
movq -0x28(%rbp), %rcx
movq 0x10(%rcx), %rcx
xorl %edx, %edx
divq (%rcx)
movq %rax, %rcx
movq -0x50(%rbp), %rax
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jne 0x677b
movq -0x30(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rcx
movq -0x18(%rbp), %rdx
xorl %eax, %eax
cmpq 0x38(%rdx), %rcx
movb %al, -0x51(%rbp)
ja 0x67a4
movq -0x40(%rbp), %rax
cmpq -0x38(%rbp), %rax
setb %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x67b0
jmp 0x6847
movq -0x28(%rbp), %rax
movq 0x50(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x50(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x28(%rbp), %rcx
leaq 0x1ed(%rip), %rdx       # 0x69d0
callq 0xcb50
cmpl $0x0, %eax
je 0x67f2
jmp 0x68fd
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x6834
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x18660
cmpl $0x0, %eax
jge 0x6834
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x6847
jmp 0x6836
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x6783
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x38(%rcx), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0x68b1
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2040
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdi
addq $0x1, %rdi
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movzbl (%rax), %eax
movl %eax, %esi
callq 0x18530
movq -0x28(%rbp), %rcx
movq %rax, 0x30(%rcx)
cmpq $0x0, %rax
jne 0x68af
jmp 0x68fd
jmp 0x68b1
jmp 0x68b3
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x18(%rbp), %rsi
callq 0x6910
movl $0x0, -0x4(%rbp)
jmp 0x6904
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x10b40
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2040
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x19810
movq -0x28(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)