// File: /workspace/github_c_makefile_star2_O2/sharpyfox[P]citrusleaf-client/tests/key_c/src/key.c
// Function: batch_getmany_cb
int
batch_getmany_cb(char *ns, cf_digest *keyd, char *set, uint32_t generation, uint32_t record_ttl, cl_bin *bins, int n_bins,
	bool is_last, void *udata)
{
	getmany_userdata *gm_udata = (getmany_userdata *) udata;
	cf_digest *keys = gm_udata->digests;
	int batch_factor = gm_udata->batch_factor;
	
	// find the kvs * key_int that matches the request we're making
	key_value *kv = 0;
	uint key_int = 0;
	for (int i=0;i<batch_factor;i++) {
		if (0 == memcmp(&keys[i],keyd,sizeof(cf_digest))) {
			kv = gm_udata->kvs[i];
			key_int = gm_udata->key_ints[i];
			break;
		}
	}
	if (kv == 0) {
		if (!g_config.silent) fprintf(stderr, "read batch value: digest does not match digests we are looking for\n");
		gm_udata->n_received_error++; // maybe needs atomic?
		return(-1);
	}
	
	// start validating	
	if (bins[0].object.type != g_config.value_type) {
		if (!g_config.silent) fprintf(stderr, "read value has wrong type: expect %d got %d\n",(int) g_config.value_type, (int) bins[0].object.type);
		gm_udata->n_received_error++; // maybe needs atomic?
		citrusleaf_object_free(&bins[0].object);
		return(-1);
	}
	
	if (g_config.value_type == CL_STR) {
		if (bins[0].object.u.str == 0) {
			gm_udata->n_received_error++; // maybe needs atomic?
			if (!g_config.silent) fprintf(stderr, "read value pointer is null. Yuck.\n");
			citrusleaf_object_free(&bins[0].object);
			return(-1);
		}
					
		if (bins[0].object.sz  != strlen(kv->value_str)) {
			gm_udata->n_received_error++; // maybe needs atomic?
			if (!g_config.silent) fprintf(stderr, "read value size doesn't match expected. Is %zd expecting %zd\n",
				bins[0].object.sz,strlen(kv->value_str)+1);
			citrusleaf_object_free(&bins[0].object);
			return(-1);
		}			
		
		if (strcmp(bins[0].object.u.str, kv->value_str) != 0) {
			gm_udata->n_received_error++; // maybe needs atomic?
			if (!g_config.silent) {
				fprintf(stderr, "read value does not match set value.\n");
				fprintf(stderr, "  expecting: %s\n",kv->value_str);
				fprintf(stderr, "  got:       %s\n",bins[0].object.u.str);
			}
			citrusleaf_object_free(&bins[0].object);
			return(-1);
		}
	}
	else if (g_config.value_type == CL_BLOB) {
		if (bins[0].object.u.blob == 0) {
			gm_udata->n_received_error++; // maybe needs atomic?
			if (!g_config.silent) fprintf(stderr, "read value pointer is null. Yuck.\n");
			citrusleaf_object_free(&bins[0].object);
			return(-1);
		}
		
		if (bins[0].object.sz  != kv->value_blob_len) {
			gm_udata->n_received_error++; // maybe needs atomic?
			if (!g_config.silent) fprintf(stderr, "read value size doesn't match expected. Is %zd expecting %d\n",
				bins[0].object.sz,kv->value_blob_len);
			citrusleaf_object_free(&bins[0].object);
			return(-1);
		}			
		
		if (memcmp(bins[0].object.u.blob, kv->value_blob, kv->value_blob_len) != 0) {
			gm_udata->n_received_error++; // maybe needs atomic?
			if (!g_config.silent) {
				int k;
				uint8_t *b1 = (uint8_t *) bins[0].object.u.blob;
				uint8_t *b2 = (uint8_t *) kv->value_blob;
				for (k=0;k<kv->value_blob_len;k++) {
					if (b1[k] != b2[k]) break;
				}
				
				fprintf(stderr, "read value does not match set value, key int %d, differ at byte %d (length correct).\n",key_int,k);
				dump_buf("got buf: ", b1, kv->value_blob_len);
				dump_buf("expecting buf: ", b2, kv->value_blob_len);

			}
			citrusleaf_object_free(&bins[0].object);
			return(-1);
		}
		
	}
	else if (g_config.value_type == CL_INT) {
		
		if (bins[0].object.u.i64 != kv->value_int) {
			gm_udata->n_received_error++; // maybe needs atomic?
			if (!g_config.silent) {
				fprintf(stderr, "read value does not match set value.\n");
				fprintf(stderr, "  expecting: %"PRIu64"\n",kv->value_int);
				fprintf(stderr, "  got:       %"PRIu64"\n",bins[0].object.u.i64);
			}
			citrusleaf_object_free(&bins[0].object);
			return(-1);

		}			
		
	}
	
	gm_udata->n_received_success++; // maybe needs atomic?

//	fprintf(stderr, "read value success\n");
//	fprintf(stderr, "  expecting: %"PRIu64"\n",kv->value_int);
//	fprintf(stderr, "  got:       %"PRIu64"\n",bins[0].object.u.i64);

	
	// have to hand back any possible malloced memory
//	citrusleaf_object_free(&values[0].object);
	
	return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x60(%rsp), %rbp
xorl %r13d, %r13d
movq %rsi, %rbx
movq %r9, 0x8(%rsp)
movl 0x18(%rbp), %r14d
movq (%rbp), %r15
testl %r14d, %r14d
cmovlel %r13d, %r14d
pushq $0x14
popq %r12
cmpq %r13, %r14
je 0x3cd2
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x2240
incq %r13
addq $0x14, %r15
testl %eax, %eax
jne 0x3bcb
movq 0x8(%rbp), %rax
movq -0x8(%rax,%r13,8), %r12
testq %r12, %r12
je 0x3cd2
movq 0x8(%rsp), %rsi
leaq 0x16725(%rip), %rbx     # 0x1a330
movl 0x20(%rsi), %ecx
movl 0x48(%rbx), %edx
leaq 0x20(%rsi), %r14
cmpl %edx, %ecx
jne 0x3ce4
cmpl $0x1, %ecx
je 0x3da1
cmpl $0x4, %ecx
je 0x3d29
cmpl $0x3, %ecx
jne 0x3dac
movq 0x30(%rsi), %r15
testq %r15, %r15
je 0x3db6
movq 0x10(%r12), %r13
movq %r14, 0x10(%rsp)
movq 0x28(%rsi), %r14
movq %r13, %rdi
callq 0x20d0
cmpq %rax, %r14
jne 0x3e73
movq %r15, %rdi
movq %r13, %rsi
callq 0x2360
testl %eax, %eax
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rax
je 0x3dac
incl 0x20(%rbp)
cmpb $0x0, 0x29(%rbx)
jne 0x3cf1
movq 0x1434f(%rip), %rbx     # 0x17fe0
leaq 0xcdf8(%rip), %rdi      # 0x10a90
movq %rax, %r15
movq (%rbx), %rcx
pushq $0x25
popq %rsi
pushq $0x1
popq %rdx
callq 0x2550
movq (%rbx), %rdi
movq 0x10(%r12), %rdx
leaq 0xcdfe(%rip), %rsi      # 0x10ab6
xorl %eax, %eax
callq 0x2390
movq (%rbx), %rdi
movq 0x30(%r15), %rdx
leaq 0xcdfa(%rip), %rsi      # 0x10ac7
jmp 0x3e34
leaq 0x16657(%rip), %rax     # 0x1a330
cmpb $0x0, 0x29(%rax)
je 0x3d0b
incl 0x20(%rbp)
jmp 0x3cf9
cmpb $0x0, 0x29(%rbx)
je 0x3e89
incl 0x20(%rbp)
movq %r14, %rdi
callq 0x56e9
pushq $-0x1
popq %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x142ce(%rip), %rax     # 0x17fe0
leaq 0xce90(%rip), %rdi      # 0x10ba9
movq (%rax), %rcx
pushq $0x43
popq %rsi
pushq $0x1
popq %rdx
callq 0x2550
jmp 0x3cdf
movq 0x30(%rsi), %rdi
testq %rdi, %rdi
je 0x3db6
movq 0x28(%rsi), %rdx
movslq 0x18(%r12), %rax
cmpq %rax, %rdx
jne 0x3e40
movq 0x10(%rbp), %rax
movq 0x20(%r12), %rsi
movl -0x4(%rax,%r13,4), %r13d
callq 0x2240
movq 0x8(%rsp), %rcx
testl %eax, %eax
je 0x3dac
incl 0x20(%rbp)
cmpb $0x0, 0x29(%rbx)
jne 0x3cf1
movq 0x30(%rcx), %r15
movl 0x18(%r12), %ecx
movq %r14, %rbx
movq 0x20(%r12), %r14
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
cmpq %rax, %rcx
je 0x3ee4
movb (%r15,%rax), %dl
cmpb (%r14,%rax), %dl
jne 0x3ee2
incq %rax
jmp 0x3d85
movq 0x30(%rsi), %rax
cmpq 0x28(%r12), %rax
jne 0x3de4
incl 0x1c(%rbp)
xorl %eax, %eax
jmp 0x3cfc
incl 0x20(%rbp)
cmpb $0x0, 0x29(%rbx)
jne 0x3cf1
movq 0x14216(%rip), %rax     # 0x17fe0
leaq 0xcc5e(%rip), %rdi      # 0x10a2f
movq (%rax), %rcx
pushq $0x22
popq %rsi
pushq $0x1
popq %rdx
callq 0x2550
jmp 0x3cf1
incl 0x20(%rbp)
cmpb $0x0, 0x29(%rbx)
jne 0x3cf1
movq 0x141e8(%rip), %rbx     # 0x17fe0
leaq 0xcc91(%rip), %rdi      # 0x10a90
movq %rsi, %r15
movq (%rbx), %rcx
pushq $0x25
popq %rsi
pushq $0x1
popq %rdx
callq 0x2550
movq (%rbx), %rdi
movq 0x28(%r12), %rdx
leaq 0xcd66(%rip), %rsi      # 0x10b85
xorl %eax, %eax
callq 0x2390
movq (%rbx), %rdi
movq 0x30(%r15), %rdx
leaq 0xcd63(%rip), %rsi      # 0x10b97
xorl %eax, %eax
callq 0x2390
jmp 0x3cf1
incl 0x20(%rbp)
cmpb $0x0, 0x29(%rbx)
jne 0x3cf1
movq 0x1418c(%rip), %rax     # 0x17fe0
movq 0x28(%rsi), %rdx
movl 0x18(%r12), %ecx
leaq 0xcc74(%rip), %rsi      # 0x10ad8
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2390
jmp 0x3cf1
incl 0x20(%rbp)
cmpb $0x0, 0x29(%rbx)
movq 0x10(%rsp), %rbx
je 0x3ea6
movq %rbx, %rdi
jmp 0x3cf4
movq 0x14150(%rip), %rax     # 0x17fe0
leaq 0xcb6b(%rip), %rsi      # 0x10a02
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2390
jmp 0x3cee
movq 0x14133(%rip), %rax     # 0x17fe0
movq 0x8(%rsp), %rcx
movq 0x10(%r12), %rdi
movq (%rax), %r15
movq 0x28(%rcx), %r14
callq 0x20d0
movq 0x10(%rsp), %rbx
leaq 0x1(%rax), %rcx
leaq 0xcb7f(%rip), %rsi      # 0x10a52
movq %r15, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2390
jmp 0x3e81
movl %eax, %ecx
movq 0x140f5(%rip), %rax     # 0x17fe0
leaq 0xcc23(%rip), %rsi      # 0x10b15
movl %r13d, %edx
movq (%rax), %rdi
xorl %eax, %eax
callq 0x2390
movslq 0x18(%r12), %rdx
leaq 0xcc60(%rip), %rdi      # 0x10b6b
movq %r15, %rsi
callq 0x3adb
movslq 0x18(%r12), %rdx
leaq 0xcc56(%rip), %rdi      # 0x10b75
movq %r14, %rsi
callq 0x3adb
movq %rbx, %r14
jmp 0x3cf1