// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/kvlds/dispatch_nmr.c
// Function: callback_range_gotleaf
static int
callback_range_gotleaf(void * cookie, struct node * N)
{
	struct nmr_cookie * C = cookie;
	struct kvpair * kv;
	size_t i;

	/* Scan through the key-value pairs (maybe) copying them. */
	for (i = 0; i < N->nkeys; i++) {
		/* Is this key too small? */
		if (kvldskey_cmp(N->u.pairs[i].k, C->R->range_start) < 0)
			continue;

		/* Is this key too large? */
		if ((C->R->range_end->len > 0) &&
		    (kvldskey_cmp(N->u.pairs[i].k, C->R->range_end) > 0))
			continue;

		/* Does it fit? */
		C->rlen += kvldskey_serial_size(N->u.pairs[i].k);
		C->rlen += kvldskey_serial_size(N->u.pairs[i].v);
		if ((C->nkeys > 0) && (C->R->range_max < C->rlen))
			break;

		/* Add the pair to the heap. */
		if ((kv = malloc(sizeof(struct kvpair))) == NULL)
			goto err0;
		if ((kv->k = kvldskey_dup(N->u.pairs[i].k)) == NULL)
			goto err1;
		if ((kv->v = kvldskey_dup(N->u.pairs[i].v)) == NULL)
			goto err2;
		if (ptrheap_add(C->H, kv))
			goto err3;
		C->nkeys += 1;
	}

	/* If we exited early, adjust the end pointer. */
	if (i < N->nkeys) {
		kvldskey_free(C->end);
		if ((C->end = kvldskey_dup(N->u.pairs[i].k)) == NULL)
			goto err0;
	}

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

	/* We've handled a leaf. */
	C->leavesleft -= 1;

	/* Are we done all the leaves? */
	if (C->leavesleft == 0) {
		if (rangedone(C))
			goto err0;
	}

	/* Success! */
	return (0);

err3:
	kvldskey_free(kv->v);
err2:
	kvldskey_free(kv->k);
err1:
	free(kv);
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
xorl %r13d, %r13d
pushq $0x10
popq %r15
xorl %ebp, %ebp
movq 0x38(%r14), %rax
cmpq %rax, %rbp
jae 0x4af2
movq 0x40(%r14), %rax
movq (%rax,%r13), %rdi
movq 0x18(%rbx), %rax
movq 0x10(%rax), %rsi
callq 0xe315
testl %eax, %eax
js 0x4ac7
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rsi
cmpb $0x0, (%rsi)
je 0x4a1b
movq 0x40(%r14), %rax
movq (%rax,%r13), %rdi
callq 0xe315
testl %eax, %eax
jg 0x4ac7
movq 0x40(%r14), %rax
movq (%rax,%r13), %rax
movzbl (%rax), %eax
movq 0x48(%rbx), %rcx
leaq (%rax,%rcx), %rdx
leaq 0x1(%rax,%rcx), %rax
movq %rax, 0x48(%rbx)
movq 0x40(%r14), %rax
movq 0x8(%rax,%r13), %rax
movzbl (%rax), %eax
addq %rdx, %rax
addq $0x2, %rax
movq %rax, 0x48(%rbx)
cmpq $0x0, 0x40(%rbx)
je 0x4a65
movq 0x18(%rbx), %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
ja 0x4aee
movq %r15, %rdi
callq 0x22a0
testq %rax, %rax
je 0x4b62
movq %rax, %r12
movq 0x40(%r14), %rax
movq (%rax,%r13), %rdi
movzbl (%rdi), %esi
incq %rdi
callq 0xe268
movq %rax, (%r12)
testq %rax, %rax
je 0x4ae6
movq 0x40(%r14), %rax
movq 0x8(%rax,%r13), %rdi
movzbl (%rdi), %esi
incq %rdi
callq 0xe268
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x4add
movq 0x28(%rbx), %rdi
movq %r12, %rsi
callq 0x98bd
testl %eax, %eax
jne 0x4ad3
incq 0x40(%rbx)
incq %rbp
addq $0x10, %r13
jmp 0x49cf
movq 0x8(%r12), %rdi
callq 0x2040
movq (%r12), %rdi
callq 0x2040
movq %r12, %rbx
jmp 0x4c81
movq 0x38(%r14), %rax
cmpq %rax, %rbp
jae 0x4b1c
movq 0x30(%rbx), %rdi
callq 0x2040
movq 0x40(%r14), %rax
movq (%rax,%r13), %rdi
movzbl (%rdi), %esi
incq %rdi
callq 0xe268
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x4b62
movq 0x10(%rbx), %rdi
movq %r14, %rsi
callq 0x496f
xorl %eax, %eax
decq 0x50(%rbx)
jne 0x4c8e
movq 0x18(%rbx), %rax
movq 0x30(%rbx), %rdi
cmpb $0x0, (%rdi)
movq 0x18(%rax), %r12
je 0x4b76
cmpb $0x0, (%r12)
je 0x4b6a
movq %r12, %rsi
callq 0xe315
testl %eax, %eax
js 0x4b6f
movq 0x18(%rbx), %rax
addq $0x18, %rax
jmp 0x4b73
pushq $-0x1
popq %rax
jmp 0x4c8e
movq %rdi, %r12
jmp 0x4b76
leaq 0x30(%rbx), %rax
movq (%rax), %r12
movq 0x40(%rbx), %rdi
callq 0x4d36
movq %rax, %r14
testq %rax, %rax
setne %al
movq 0x40(%rbx), %rdi
testq %rdi, %rdi
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x4c66
callq 0x4d36
movq %rax, %r15
testq %rax, %rax
je 0x4c53
xorl %ebp, %ebp
movq 0x40(%rbx), %rdx
cmpq %rdx, %rbp
jae 0x4bf4
movq 0x28(%rbx), %rdi
callq 0x99b1
testq %rax, %rax
je 0x4d17
movq %rax, %r13
movq 0x28(%rbx), %rdi
callq 0x9b86
movq (%r13), %rax
movq %rax, (%r14,%rbp,8)
movq 0x8(%r13), %rax
movq %rax, (%r15,%rbp,8)
movq %r13, %rdi
callq 0x2040
incq %rbp
jmp 0x4bb0
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rdi
movq (%rax), %rsi
movq %r12, %rcx
movq %r14, %r8
movq %r15, %r9
callq 0xedec
testl %eax, %eax
je 0x4c9d
xorl %r12d, %r12d
movq 0x40(%rbx), %rax
cmpq %rax, %r12
jae 0x4c2f
movq (%r15,%r12,8), %rdi
callq 0x2040
incq %r12
jmp 0x4c18
xorl %r12d, %r12d
cmpq %rax, %r12
jae 0x4c49
movq (%r14,%r12,8), %rdi
callq 0x2040
incq %r12
movq 0x40(%rbx), %rax
jmp 0x4c32
movq %r15, %rdi
callq 0x2040
jmp 0x4c5e
cmpq $0x0, 0x40(%rbx)
je 0x4bae
movq %r14, %rdi
callq 0x2040
movq 0x28(%rbx), %rdi
callq 0x9bdc
movq 0x30(%rbx), %rdi
callq 0x2040
movq 0x18(%rbx), %rdi
callq 0xeb7a
pushq $-0x1
popq %rbp
movq %rbx, %rdi
callq 0x2040
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
movq 0x40(%rbx), %r12
cmpq %r12, %r13
jae 0x4cb7
movq (%r15,%r13,8), %rdi
callq 0x2040
incq %r13
jmp 0x4ca0
movq %r15, %rdi
callq 0x2040
xorl %r15d, %r15d
cmpq %r12, %r15
jae 0x4cd9
movq (%r14,%r15,8), %rdi
callq 0x2040
incq %r15
movq 0x40(%rbx), %r12
jmp 0x4cc2
movq %r14, %rdi
callq 0x2040
movq 0x28(%rbx), %rdi
callq 0x9bdc
movq 0x30(%rbx), %rdi
callq 0x2040
movq 0x18(%rbx), %rdi
callq 0xeb7a
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x9f40
cmpq $0x1, %rax
sbbl %ebp, %ebp
jmp 0x4c84
leaq 0xca79(%rip), %rdi      # 0x11797
leaq 0xc9ed(%rip), %rsi      # 0x11712
leaq 0xca76(%rip), %rcx      # 0x117a2
movl $0x14e, %edx            # imm = 0x14E
callq 0x21c0