// File: /workspace/github_c_makefile_star2_O2/Tarsnap[P]kivaloo/liball/../lib/proto_kvlds/proto_kvlds_client.c
// Function: callback_range
static int
callback_range(void * cookie, uint8_t * buf, size_t buflen)
{
	struct range_cookie * C = cookie;
	int failed = 1;
	size_t bufpos = 0;
	size_t nkeys = 0;
	struct kvldskey * next = NULL;
	struct kvldskey ** keys = NULL;
	struct kvldskey ** values = NULL;
	size_t klen;
	size_t i;
	int rc;

	/* If we have a packet, parse it. */
	if (buf != NULL) {
		/* Is the status code sane? */
		if (buflen - bufpos < 4)
			BAD("RANGE", "bogus length");
		if (be32dec(&buf[bufpos]) != 0)
			BAD("RANGE", "bogus status code");
		bufpos += 4;

		/* Parse and sanity-check the number of key-value pairs. */
		if (buflen - bufpos < 4)
			BAD("RANGE", "bogus length");
		nkeys = be32dec(&buf[bufpos]);
		if ((nkeys > 1) && (nkeys > C->max / 2))
			BAD("RANGE", "too many key-value pairs");
		bufpos += 4;

		/* Parse next key. */
		if ((klen = kvldskey_unserialize(&next, &buf[bufpos],
		    buflen - bufpos)) == 0) {
			warnp("Error parsing RANGE response next key");
			goto failed;
		}
		bufpos += klen;

		/* Allocate buffer for keys. */
		if (IMALLOC(keys, nkeys, struct kvldskey *))
			goto failed;
		for (i = 0; i < nkeys; i++)
			keys[i] = NULL;

		/* Allocate buffer for values. */
		if (IMALLOC(values, nkeys, struct kvldskey *))
			goto failed;
		for (i = 0; i < nkeys; i++)
			values[i] = NULL;

		/* Parse keys and values. */
		for (i = 0; i < nkeys; i++) {
			if ((klen = kvldskey_unserialize(&keys[i],
			    &buf[bufpos], buflen - bufpos)) == 0) {
				warnp("Error parsing RANGE response key");
				goto failed;
			}
			bufpos += klen;

			if ((klen = kvldskey_unserialize(&values[i],
			    &buf[bufpos], buflen - bufpos)) == 0) {
				warnp("Error parsing RANGE response value");
				goto failed;
			}
			bufpos += klen;
		}

		/* Make sure we reached the end of the packet. */
		if (buflen != bufpos)
			BAD("RANGE", "wrong length");

		/* We successfully parsed this response. */
		failed = 0;
	}

failed:
	/* If we failed, clean up. */
	if (failed) {
		if (values) {
			for (i = 0; i < nkeys; i++)
				kvldskey_free(values[i]);
			free(values);
			values = NULL;
		}
		if (keys) {
			for (i = 0; i < nkeys; i++)
				kvldskey_free(keys[i]);
			free(keys);
			keys = NULL;
		}
		nkeys = 0;
		kvldskey_free(next);
		next = NULL;
	}

	/* Invoke the upstream callback. */
	rc = (C->callback)(C->cookie, failed, nkeys, next, keys, values);

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

	/* Return status from callback. */
	return (rc);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
andq $0x0, 0x10(%rsp)
testq %rsi, %rsi
je 0x5cff
movq %rdx, %r13
cmpq $0x3, %rdx
ja 0x5ccc
leaq 0x3f24(%rip), %rdi      # 0x9be0
leaq 0x3f92(%rip), %rsi      # 0x9c55
leaq 0x3f3a(%rip), %rdx      # 0x9c04
jmp 0x5cf0
movq %rsi, %rbp
movq %rsi, %rdi
callq 0x6104
testl %eax, %eax
je 0x5d47
leaq 0x3efe(%rip), %rdi      # 0x9be0
leaq 0x3f6c(%rip), %rsi      # 0x9c55
leaq 0x3f21(%rip), %rdx      # 0x9c11
xorl %eax, %eax
callq 0x4be4
callq 0x2090
andl $0x0, (%rax)
movq 0x10(%rsp), %rdi
callq 0x2040
andq $0x0, 0x10(%rsp)
pushq $0x1
popq %rsi
xorl %ecx, %ecx
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x8(%rbx), %rdi
movq %r14, %rdx
movq %r15, %r8
movq %r12, %r9
callq *(%rbx)
movq %rbx, %rdi
movl %eax, %ebx
callq 0x2040
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rax
andq $-0x4, %rax
cmpq $0x4, %rax
je 0x5cb5
leaq 0x4(%rbp), %rdi
callq 0x6104
movl %eax, %r14d
cmpl $0x2, %eax
jb 0x5d8f
movq 0x10(%rbx), %rax
shrq %rax
cmpq %r14, %rax
jae 0x5d8f
leaq 0x3e64(%rip), %rdi      # 0x9be0
leaq 0x3ed2(%rip), %rsi      # 0x9c55
leaq 0x3ed1(%rip), %rdx      # 0x9c5b
jmp 0x5cf0
leaq 0x8(%rbp), %rsi
leaq -0x8(%r13), %rdx
leaq 0x10(%rsp), %rdi
callq 0x50eb
testq %rax, %rax
movq %rbx, (%rsp)
je 0x5de5
movq %rax, 0x8(%rsp)
movq %r14, %rdi
callq 0x6292
movq %rax, %r15
testq %rax, %rax
sete %al
testq %r14, %r14
setne %cl
testb %al, %cl
jne 0x5cff
addq $0x8, 0x8(%rsp)
xorl %eax, %eax
cmpq %rax, %r14
je 0x5e0c
andq $0x0, (%r15,%rax,8)
incq %rax
jmp 0x5dd6
callq 0x2090
cmpl $0x0, (%rax)
je 0x5eb4
movq %rax, %rbx
leaq 0x3e77(%rip), %rdi      # 0x9c74
xorl %eax, %eax
callq 0x4a55
andl $0x0, (%rbx)
jmp 0x5f9b
testl %r14d, %r14d
setne %bl
movq %r14, %rdi
callq 0x6292
movq %rax, %r12
testq %rax, %rax
sete %al
testb %al, %bl
movq (%rsp), %rbx
jne 0x5f75
xorl %eax, %eax
cmpq %rax, %r14
je 0x5e40
andq $0x0, (%r12,%rax,8)
incq %rax
jmp 0x5e31
leaq (,%r14,8), %rax
movq %rax, 0x20(%rsp)
xorl %ecx, %ecx
movq 0x8(%rsp), %rax
cmpq %rcx, 0x20(%rsp)
je 0x5ec7
movq %rcx, 0x18(%rsp)
leaq (%r15,%rcx), %rdi
leaq (%rax,%rbp), %rsi
movq %r13, %rdx
subq %rax, %rdx
movq %rax, 0x8(%rsp)
callq 0x50eb
testq %rax, %rax
je 0x5ed8
movq %rax, %rbx
addq 0x8(%rsp), %rbx
movq 0x18(%rsp), %rax
leaq (%r12,%rax), %rdi
leaq (%rbx,%rbp), %rsi
movq %r13, %rdx
subq %rbx, %rdx
callq 0x50eb
testq %rax, %rax
je 0x5eee
addq %rbx, %rax
movq 0x18(%rsp), %rcx
addq $0x8, %rcx
movq (%rsp), %rbx
jmp 0x5e54
leaq 0x3db9(%rip), %rdi      # 0x9c74
xorl %eax, %eax
callq 0x4be4
jmp 0x5f9b
cmpq %rax, %r13
jne 0x5f0e
xorl %esi, %esi
movq 0x10(%rsp), %rcx
jmp 0x5d1d
callq 0x2090
cmpl $0x0, (%rax)
je 0x5f34
movq %rax, %rbx
leaq 0x3dae(%rip), %rdi      # 0x9c9a
jmp 0x5f02
callq 0x2090
cmpl $0x0, (%rax)
je 0x5f3d
movq %rax, %rbx
leaq 0x3db9(%rip), %rdi      # 0x9cbb
xorl %eax, %eax
callq 0x4a55
andl $0x0, (%rbx)
jmp 0x5f4b
leaq 0x3ccb(%rip), %rdi      # 0x9be0
leaq 0x3d39(%rip), %rsi      # 0x9c55
leaq 0x3d25(%rip), %rdx      # 0x9c48
xorl %eax, %eax
callq 0x4be4
callq 0x2090
andl $0x0, (%rax)
jmp 0x5f4f
leaq 0x3d5f(%rip), %rdi      # 0x9c9a
jmp 0x5f44
leaq 0x3d77(%rip), %rdi      # 0x9cbb
xorl %eax, %eax
callq 0x4be4
movq (%rsp), %rbx
testq %r12, %r12
je 0x5f75
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x5f69
movq (%r12,%rbx,8), %rdi
callq 0x2040
incq %rbx
jmp 0x5f56
movq %r12, %rdi
callq 0x2040
movq (%rsp), %rbx
testq %r15, %r15
je 0x5cff
xorl %ebx, %ebx
cmpq %rbx, %r14
je 0x5f93
movq (%r15,%rbx,8), %rdi
callq 0x2040
incq %rbx
jmp 0x5f80
movq %r15, %rdi
callq 0x2040
movq (%rsp), %rbx
jmp 0x5cff