// File: /workspace/github_c_makefile_star2_O1/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 $0x0, 0x8(%rsp)
testq %rsi, %rsi
movq %rdi, 0x20(%rsp)
je 0x64b5
movq %rdx, %r13
cmpq $0x3, %rdx
ja 0x64ba
leaq 0x5799(%rip), %rdi      # 0xbc3e
leaq 0x5807(%rip), %rsi      # 0xbcb3
leaq 0x57af(%rip), %rdx      # 0xbc62
jmp 0x64de
xorl %r14d, %r14d
jmp 0x64f3
movq %rsi, %rbp
movl (%rsi), %eax
bswapl %eax
testl %eax, %eax
je 0x65a4
leaq 0x576e(%rip), %rdi      # 0xbc3e
leaq 0x57dc(%rip), %rsi      # 0xbcb3
leaq 0x5791(%rip), %rdx      # 0xbc6f
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x514b
callq 0x2090
movl $0x0, (%rax)
xorl %r15d, %r15d
xorl %r12d, %r12d
xorl %r13d, %r13d
movl $0x1, %ebp
testb %r13b, %r13b
jne 0x656c
testq %r12, %r12
je 0x652b
testq %r14, %r14
je 0x6523
xorl %ebx, %ebx
movq (%r12,%rbx,8), %rdi
callq 0x2040
incq %rbx
cmpq %rbx, %r14
jne 0x6512
movq %r12, %rdi
callq 0x2040
testq %r15, %r15
je 0x6550
testq %r14, %r14
je 0x6548
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rdi
callq 0x2040
incq %rbx
cmpq %rbx, %r14
jne 0x6537
movq %r15, %rdi
callq 0x2040
movq 0x8(%rsp), %rdi
callq 0x2040
movq $0x0, 0x8(%rsp)
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x20(%rsp), %r13
movq 0x8(%r13), %rdi
movq 0x8(%rsp), %rcx
movl %ebp, %esi
movq %r14, %rdx
movq %r15, %r8
movq %r12, %r9
callq *(%r13)
movl %eax, %ebx
movq %r13, %rdi
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 0x649e
movl 0x4(%rbp), %r14d
bswapl %r14d
cmpl $0x2, %r14d
jb 0x65fd
movq 0x10(%rdi), %rax
shrq %rax
cmpq %r14, %rax
jae 0x65fd
leaq 0x5669(%rip), %rdi      # 0xbc3e
leaq 0x56d7(%rip), %rsi      # 0xbcb3
leaq 0x56d6(%rip), %rdx      # 0xbcb9
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x514b
callq 0x2090
movl $0x0, (%rax)
jmp 0x64f6
leaq 0x8(%rbp), %rsi
leaq -0x8(%r13), %rdx
leaq 0x8(%rsp), %rdi
callq 0x5635
testq %rax, %rax
je 0x6630
movq %rax, 0x10(%rsp)
testq %r14, %r14
je 0x665b
leaq (,%r14,8), %rdi
callq 0x2220
movq %rax, %r15
jmp 0x665e
callq 0x2090
cmpl $0x0, (%rax)
movl $0x1, %ebp
je 0x66a0
movq %rax, %rbx
leaq 0x5689(%rip), %rdi      # 0xbcd2
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x502c
movl $0x0, (%rbx)
jmp 0x66b1
xorl %r15d, %r15d
testq %r15, %r15
sete %al
testq %r14, %r14
setne %cl
testb %al, %cl
jne 0x64f3
testq %r14, %r14
je 0x6689
leaq (,%r14,8), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0x21a0
testq %r14, %r14
je 0x66bc
leaq (,%r14,8), %rdi
callq 0x2220
movq %rax, %r12
jmp 0x66bf
leaq 0x562b(%rip), %rdi      # 0xbcd2
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x514b
xorl %r12d, %r12d
xorl %r13d, %r13d
jmp 0x6501
xorl %r12d, %r12d
testl %r14d, %r14d
setne %al
testq %r12, %r12
sete %cl
testb %cl, %al
jne 0x64f6
movq 0x10(%rsp), %rax
addq $0x8, %rax
testq %r14, %r14
je 0x6765
leaq (,%r14,8), %rdx
movq $0x0, (%rsp)
movq %r12, %rdi
xorl %esi, %esi
movq %rdx, 0x18(%rsp)
movq %rax, %rbx
callq 0x21a0
movq %rbx, %rax
movq %rax, 0x10(%rsp)
movq (%rsp), %rcx
leaq (%r15,%rcx), %rdi
leaq (%rax,%rbp), %rsi
movq %r13, %rdx
subq %rax, %rdx
callq 0x5635
testq %rax, %rax
je 0x67a3
movq %rax, %rbx
addq 0x10(%rsp), %rbx
movq (%rsp), %rax
leaq (%r12,%rax), %rdi
leaq (%rbx,%rbp), %rsi
movq %r13, %rdx
subq %rbx, %rdx
callq 0x5635
testq %rax, %rax
je 0x67b9
addq %rbx, %rax
movq (%rsp), %rdx
addq $0x8, %rdx
movq %rdx, (%rsp)
cmpq %rdx, 0x18(%rsp)
jne 0x670a
cmpq %r13, %rax
jne 0x6774
xorl %ebp, %ebp
movb $0x1, %r13b
jmp 0x6501
leaq 0x54c3(%rip), %rdi      # 0xbc3e
leaq 0x5531(%rip), %rsi      # 0xbcb3
leaq 0x551d(%rip), %rdx      # 0xbca6
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x514b
callq 0x2090
movl $0x0, (%rax)
jmp 0x64fc
callq 0x2090
cmpl $0x0, (%rax)
je 0x67e2
movq %rax, %rbx
leaq 0x5541(%rip), %rdi      # 0xbcf8
jmp 0x67cd
callq 0x2090
cmpl $0x0, (%rax)
je 0x67eb
movq %rax, %rbx
leaq 0x554c(%rip), %rdi      # 0xbd19
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x502c
movl $0x0, (%rbx)
jmp 0x64fc
leaq 0x550f(%rip), %rdi      # 0xbcf8
jmp 0x67f2
leaq 0x5527(%rip), %rdi      # 0xbd19
xorl %r13d, %r13d
xorl %eax, %eax
callq 0x514b
jmp 0x64fc