// File: /workspace/github_c_makefile_star2_O0/Tarsnap[P]kivaloo/kvlds/dispatch_nmr.c
// Function: rangedone
static int
rangedone(struct nmr_cookie * C)
{
	const struct kvldskey * next;
	struct kvldskey ** keys;
	struct kvldskey ** values;
	struct kvpair * kv;
	size_t i;

	/*
	 * If we've handled a range which goes beyond the ending key we were
	 * provided with, we want to return the ending key as the next key.
	 */
	if (C->end->len == 0)
		next = C->R->range_end;
	else if (C->R->range_end->len == 0)
		next = C->end;
	else if (kvldskey_cmp(C->end, C->R->range_end) < 0)
		next = C->end;
	else
		next = C->R->range_end;

	/* Allocate arrays for holding keys and values. */
	if (IMALLOC(keys, C->nkeys, struct kvldskey *))
		goto err2;
	if (IMALLOC(values, C->nkeys, struct kvldskey *))
		goto err3;

	/* Pull key-value pairs out of the heap. */
	for (i = 0; i < C->nkeys; i++) {
		/* Get a key-value pair. */
		kv = ptrheap_getmin(C->H);
		assert(kv != NULL);

		/* Remove it from the heap. */
		ptrheap_deletemin(C->H);

		/* Stuff the key and value into the respective arrays. */
		keys[i] = kv->k;
		values[i] = kv->v;

		/* Free the key-value pair structure. */
		free(kv);
	}

	/* Send the RANGE response. */
	if (proto_kvlds_response_range(C->WQ, C->R->ID, C->nkeys, next,
	    keys, values))
		goto err4;

	/* Free the values. */
	for (i = 0; i < C->nkeys; i++)
		kvldskey_free(values[i]);
	free(values);

	/* Free the keys. */
	for (i = 0; i < C->nkeys; i++)
		kvldskey_free(keys[i]);
	free(keys);

	/* Free the heap. */
	ptrheap_free(C->H);

	/* Free the end-of-range value provided by btree_find_range. */
	kvldskey_free(C->end);

	/* Free the RANGE request. */
	proto_kvlds_request_free(C->R);

	/* Schedule the completion callback. */
	if (!events_immediate_register(C->callback_done, C->cookie_done, 0))
		goto err1;

	/* Free the cookie. */
	free(C);

	/* Success! */
	return (0);

err4:
	for (i = 0; i < C->nkeys; i++)
		kvldskey_free(values[i]);
	for (i = 0; i < C->nkeys; i++)
		kvldskey_free(keys[i]);
	free(values);
err3:
	free(keys);
err2:
	ptrheap_free(C->H);
	kvldskey_free(C->end);
	proto_kvlds_request_free(C->R);
err1:
	free(C);

	/* Failure! */
	return (-1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x6cfe
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x6d60
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x6d20
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x6d5e
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rsi
callq 0x18660
cmpl $0x0, %eax
jge 0x6d4c
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x6d5c
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x6d5e
jmp 0x6d60
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movl $0x8, %esi
callq 0x7030
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x6d8c
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jbe 0x6d8c
jmp 0x6fe4
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movl $0x8, %esi
callq 0x7030
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x6db8
movq -0x10(%rbp), %rax
cmpq $0x0, 0x40(%rax)
jbe 0x6db8
jmp 0x6fdb
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x6e59
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x10700
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x6dec
jmp 0x6e0b
leaq 0x17dbc(%rip), %rdi     # 0x1ebaf
leaq 0x17d30(%rip), %rsi     # 0x1eb2a
movl $0x14e, %edx            # imm = 0x14E
leaq 0x17db4(%rip), %rcx     # 0x1ebba
callq 0x21d0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x10a40
movq -0x30(%rbp), %rax
movq (%rax), %rdx
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rdx
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rdi
callq 0x2040
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6dc0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
movq -0x28(%rbp), %r9
callq 0x19af0
cmpl $0x0, %eax
je 0x6e8f
jmp 0x6f68
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x6ec4
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2040
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6e97
movq -0x28(%rbp), %rdi
callq 0x2040
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x6f02
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2040
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6ed5
movq -0x20(%rbp), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x10b40
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x19810
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
xorl %edx, %edx
callq 0x111b0
cmpq $0x0, %rax
jne 0x6f53
jmp 0x700b
movq -0x10(%rbp), %rdi
callq 0x2040
movl $0x0, -0x4(%rbp)
jmp 0x701b
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x6f9d
movq -0x28(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2040
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6f70
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x40(%rcx), %rax
jae 0x6fd2
movq -0x20(%rbp), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2040
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x6fa5
movq -0x28(%rbp), %rdi
callq 0x2040
movq -0x20(%rbp), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x10b40
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
callq 0x2040
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x19810
movq -0x10(%rbp), %rdi
callq 0x2040
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)