// File: /workspace/github_c_makefile_star2_O3/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
cmpq $0x0, 0x38(%rsi)
je 0x57e9
xorl %r13d, %r13d
xorl %r12d, %r12d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x40(%r14), %rax
movq (%rax,%r13), %rdi
movq 0x18(%rbx), %rax
movq 0x10(%rax), %rsi
callq 0x102c6
testl %eax, %eax
js 0x5788
movq 0x18(%rbx), %rax
movq 0x18(%rax), %rsi
cmpb $0x0, (%rsi)
je 0x56dc
movq 0x40(%r14), %rax
movq (%rax,%r13), %rdi
callq 0x102c6
testl %eax, %eax
jg 0x5788
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 0x5726
movq 0x18(%rbx), %rcx
movl 0xc(%rcx), %ecx
cmpq %rcx, %rax
ja 0x57b7
movl $0x10, %edi
callq 0x22a0
testq %rax, %rax
je 0x584f
movq %rax, %r15
movq 0x40(%r14), %rax
movq (%rax,%r13), %rdi
movzbl (%rdi), %esi
incq %rdi
callq 0x10214
movq %rax, (%r15)
testq %rax, %rax
je 0x57af
movq 0x40(%r14), %rax
movq 0x8(%rax,%r13), %rdi
movzbl (%rdi), %esi
incq %rdi
callq 0x10214
movq %rax, 0x8(%r15)
testq %rax, %rax
je 0x57a7
movq 0x28(%rbx), %rdi
movq %r15, %rsi
callq 0xb117
testl %eax, %eax
jne 0x579e
incq 0x40(%rbx)
incq %r12
movq 0x38(%r14), %rax
addq $0x10, %r13
cmpq %rax, %r12
jb 0x569d
jmp 0x57bb
movq 0x8(%r15), %rdi
callq 0x2040
movq (%r15), %rdi
callq 0x2040
movq %r15, %rbx
jmp 0x598d
movq 0x38(%r14), %rax
cmpq %rax, %r12
jae 0x57e9
movq 0x30(%rbx), %rdi
callq 0x2040
movq 0x40(%r14), %rax
shlq $0x4, %r12
movq (%rax,%r12), %rdi
movzbl (%rdi), %esi
incq %rdi
callq 0x10214
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x584f
movq 0x10(%rbx), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rdi), %rax
movq (%r14,%rax), %rax
movq (%rax), %rcx
testq %rcx, %rcx
je 0x5a4f
decq %rcx
movq %rcx, (%rax)
jne 0x5815
movq %r14, %rsi
callq 0x107ea
xorl %ebp, %ebp
decq 0x50(%rbx)
jne 0x5995
movq 0x18(%rbx), %rax
movq 0x30(%rbx), %rdi
cmpb $0x0, (%rdi)
movq 0x18(%rax), %r12
je 0x5865
cmpb $0x0, (%r12)
je 0x5859
movq %r12, %rsi
callq 0x102c6
testl %eax, %eax
js 0x585e
movq 0x18(%rbx), %rax
addq $0x18, %rax
jmp 0x5862
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x5995
movq %rdi, %r12
jmp 0x5865
leaq 0x30(%rbx), %rax
movq (%rax), %r12
movq 0x40(%rbx), %r15
testq %r15, %r15
je 0x5887
movq %r15, %rax
shrq $0x3d, %rax
je 0x5891
callq 0x20a0
movl $0xc, (%rax)
jmp 0x596d
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %edx, %edx
jmp 0x5901
shlq $0x3, %r15
movq %r15, %rdi
callq 0x22a0
testq %rax, %rax
je 0x596d
movq %rax, %r14
movq %r15, %rdi
callq 0x22a0
testq %rax, %rax
je 0x5965
movq %rax, %r15
xorl %ebp, %ebp
movq 0x28(%rbx), %rdi
callq 0xb228
testq %rax, %rax
je 0x5a30
movq %rax, %r13
movq 0x28(%rbx), %rdi
callq 0xb43d
movq (%r13), %rax
movq %rax, (%r14,%rbp,8)
movq 0x8(%r13), %rax
movq %rax, (%r15,%rbp,8)
movq %r13, %rdi
callq 0x2040
incq %rbp
movq 0x40(%rbx), %rdx
cmpq %rdx, %rbp
jb 0x58bf
movq 0x18(%rbx), %rax
movq 0x20(%rbx), %rdi
movq (%rax), %rsi
movq %r12, %rcx
movq %r14, %r8
movq %r15, %r9
callq 0x10df7
movq 0x40(%rbx), %rcx
testl %eax, %eax
je 0x59a6
testq %rcx, %rcx
je 0x595d
xorl %r12d, %r12d
movq (%r15,%r12,8), %rdi
callq 0x2040
incq %r12
movq 0x40(%rbx), %rax
cmpq %rax, %r12
jb 0x592e
testq %rax, %rax
je 0x595d
xorl %r12d, %r12d
movq (%r14,%r12,8), %rdi
callq 0x2040
incq %r12
cmpq 0x40(%rbx), %r12
jb 0x594b
movq %r15, %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
movq 0x28(%rbx), %rdi
callq 0xb493
movq 0x30(%rbx), %rdi
callq 0x2040
movq 0x18(%rbx), %rdi
callq 0x10b73
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rbx, %rdi
callq 0x2040
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rcx, %rcx
je 0x59e7
xorl %r12d, %r12d
movq (%r15,%r12,8), %rdi
callq 0x2040
incq %r12
movq 0x40(%rbx), %r13
cmpq %r13, %r12
jb 0x59ae
movq %r15, %rdi
callq 0x2040
testq %r13, %r13
je 0x59ef
xorl %r15d, %r15d
movq (%r14,%r15,8), %rdi
callq 0x2040
incq %r15
cmpq 0x40(%rbx), %r15
jb 0x59d3
jmp 0x59ef
movq %r15, %rdi
callq 0x2040
movq %r14, %rdi
callq 0x2040
movq 0x28(%rbx), %rdi
callq 0xb493
movq 0x30(%rbx), %rdi
callq 0x2040
movq 0x18(%rbx), %rdi
callq 0x10b73
movq (%rbx), %rdi
movq 0x8(%rbx), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0xb910
testq %rax, %rax
jne 0x598d
jmp 0x5988
leaq 0xed48(%rip), %rdi      # 0x1477f
leaq 0xecbc(%rip), %rsi      # 0x146fa
leaq 0xed45(%rip), %rcx      # 0x1478a
movl $0x14e, %edx            # imm = 0x14E
callq 0x21c0
leaq 0xebfa(%rip), %rdi      # 0x14650
leaq 0xec19(%rip), %rsi      # 0x14676
leaq 0xec2b(%rip), %rcx      # 0x1468f
movl $0x88, %edx
callq 0x21c0
nop