// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x98, %rsp
movq 0xb0(%rsp), %rax
movb 0xa8(%rsp), %al
movl 0xa0(%rsp), %r10d
movq %rdi, 0x88(%rsp)
movq %rsi, 0x80(%rsp)
movq %rdx, 0x78(%rsp)
movl %ecx, 0x74(%rsp)
movl %r8d, 0x70(%rsp)
movq %r9, 0x68(%rsp)
andb $0x1, %al
movb %al, 0x67(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rax
movl 0x18(%rax), %eax
movl %eax, 0x4c(%rsp)
movq $0x0, 0x40(%rsp)
movl $0x0, 0x3c(%rsp)
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x4c(%rsp), %eax
jge 0x4638
movq 0x50(%rsp), %rdi
movslq 0x38(%rsp), %rax
imulq $0x14, %rax, %rax
addq %rax, %rdi
movq 0x80(%rsp), %rsi
movl $0x14, %edx
callq 0x2100
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jne 0x4629
movq 0x58(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x38(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x40(%rsp)
movq 0x58(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x38(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x3c(%rsp)
jmp 0x4638
jmp 0x462b
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x45c6
cmpq $0x0, 0x40(%rsp)
jne 0x4683
leaq 0x20ce9(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x4665
movq 0x1e98c(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
leaq 0x18530(%rip), %rsi     # 0x1cb8e
movb $0x0, %al
callq 0x23b0
movq 0x58(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x4bb1
movq 0x68(%rsp), %rax
movl 0x20(%rax), %eax
leaq 0x20c9e(%rip), %rcx     # 0x25330
cmpl 0x48(%rcx), %eax
je 0x46fa
leaq 0x20c92(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x46ce
movq 0x1e935(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
leaq 0x20c7b(%rip), %rax     # 0x25330
movl 0x48(%rax), %edx
movq 0x68(%rsp), %rax
movl 0x20(%rax), %ecx
leaq 0x18320(%rip), %rsi     # 0x1c9e7
movb $0x0, %al
callq 0x23b0
movq 0x58(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
movq 0x68(%rsp), %rdi
addq $0x20, %rdi
callq 0x74b0
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x4bb1
leaq 0x20c2f(%rip), %rax     # 0x25330
cmpl $0x3, 0x48(%rax)
jne 0x48d0
movq 0x68(%rsp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x4768
movq 0x58(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
leaq 0x20c04(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x474a
movq 0x1e8a7(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
leaq 0x182d1(%rip), %rsi     # 0x1ca14
movb $0x0, %al
callq 0x23b0
movq 0x68(%rsp), %rdi
addq $0x20, %rdi
callq 0x74b0
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x4bb1
movq 0x68(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x20f0
movq %rax, %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
je 0x4818
movq 0x58(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
leaq 0x20b86(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x47fa
movq 0x1e829(%rip), %rax     # 0x22fe0
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x68(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x20f0
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rdx
movq %rax, %rcx
addq $0x1, %rcx
leaq 0x18244(%rip), %rsi     # 0x1ca37
movb $0x0, %al
callq 0x23b0
movq 0x68(%rsp), %rdi
addq $0x20, %rdi
callq 0x74b0
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x4bb1
movq 0x68(%rsp), %rax
movq 0x30(%rax), %rdi
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x2380
cmpl $0x0, %eax
je 0x48cb
movq 0x58(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
leaq 0x20ae3(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x48ad
movq 0x1e786(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
leaq 0x18211(%rip), %rsi     # 0x1ca75
movb $0x0, %al
callq 0x23b0
movq 0x1e76e(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rdx
leaq 0x18216(%rip), %rsi     # 0x1ca9b
movb $0x0, %al
callq 0x23b0
movq 0x1e74d(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movq 0x68(%rsp), %rax
movq 0x30(%rax), %rdx
leaq 0x18206(%rip), %rsi     # 0x1caac
movb $0x0, %al
callq 0x23b0
movq 0x68(%rsp), %rdi
addq $0x20, %rdi
callq 0x74b0
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x4bb1
jmp 0x4b98
leaq 0x20a59(%rip), %rax     # 0x25330
cmpl $0x4, 0x48(%rax)
jne 0x4ad9
movq 0x68(%rsp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x493e
movq 0x58(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
leaq 0x20a2e(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x4920
movq 0x1e6d1(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
leaq 0x180fb(%rip), %rsi     # 0x1ca14
movb $0x0, %al
callq 0x23b0
movq 0x68(%rsp), %rdi
addq $0x20, %rdi
callq 0x74b0
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x4bb1
movq 0x68(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x40(%rsp), %rcx
movslq 0x18(%rcx), %rcx
cmpq %rcx, %rax
je 0x49b7
movq 0x58(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
leaq 0x209c6(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x4999
movq 0x1e669(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movq 0x68(%rsp), %rax
movq 0x28(%rax), %rdx
movq 0x40(%rsp), %rax
movl 0x18(%rax), %ecx
leaq 0x1812b(%rip), %rsi     # 0x1cabd
movb $0x0, %al
callq 0x23b0
movq 0x68(%rsp), %rdi
addq $0x20, %rdi
callq 0x74b0
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x4bb1
movq 0x68(%rsp), %rax
movq 0x30(%rax), %rdi
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rsi
movq 0x40(%rsp), %rax
movslq 0x18(%rax), %rdx
callq 0x2100
cmpl $0x0, %eax
je 0x4ad4
movq 0x58(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
leaq 0x2093b(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x4ab6
movq 0x68(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x20(%rsp)
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
movq 0x40(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x4a62
movq 0x28(%rsp), %rax
movslq 0x34(%rsp), %rcx
movzbl (%rax,%rcx), %eax
movq 0x20(%rsp), %rcx
movslq 0x34(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
cmpl %ecx, %eax
je 0x4a53
jmp 0x4a62
jmp 0x4a55
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x4a23
movq 0x1e577(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movl 0x3c(%rsp), %edx
movl 0x34(%rsp), %ecx
leaq 0x1807f(%rip), %rsi     # 0x1cafa
movb $0x0, %al
callq 0x23b0
movq 0x28(%rsp), %rsi
movq 0x40(%rsp), %rax
movslq 0x18(%rax), %rdx
leaq 0x180b9(%rip), %rdi     # 0x1cb50
callq 0x43f0
movq 0x20(%rsp), %rsi
movq 0x40(%rsp), %rax
movslq 0x18(%rax), %rdx
leaq 0x180a9(%rip), %rdi     # 0x1cb5a
callq 0x43f0
movq 0x68(%rsp), %rdi
addq $0x20, %rdi
callq 0x74b0
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x4bb1
jmp 0x4b96
leaq 0x20850(%rip), %rax     # 0x25330
cmpl $0x1, 0x48(%rax)
jne 0x4b94
movq 0x68(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x40(%rsp), %rcx
cmpq 0x28(%rcx), %rax
je 0x4b92
movq 0x58(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
leaq 0x20819(%rip), %rax     # 0x25330
testb $0x1, 0x29(%rax)
jne 0x4b77
movq 0x1e4bc(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
leaq 0x17f47(%rip), %rsi     # 0x1ca75
movb $0x0, %al
callq 0x23b0
movq 0x1e4a4(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movq 0x40(%rsp), %rax
movq 0x28(%rax), %rdx
leaq 0x1801b(%rip), %rsi     # 0x1cb6a
movb $0x0, %al
callq 0x23b0
movq 0x1e483(%rip), %rax     # 0x22fe0
movq (%rax), %rdi
movq 0x68(%rsp), %rax
movq 0x30(%rax), %rdx
leaq 0x1800c(%rip), %rsi     # 0x1cb7c
movb $0x0, %al
callq 0x23b0
movq 0x68(%rsp), %rdi
addq $0x20, %rdi
callq 0x74b0
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
jmp 0x4bb1
jmp 0x4b94
jmp 0x4b96
jmp 0x4b98
movq 0x58(%rsp), %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq