// File: /workspace/github_c_makefile_star2_O3/sharpyfox[P]citrusleaf-client/tests/key_c/src/key.c
// Function: make_key_value
static key_value *make_key_value(uint seed, uint key_len, uint value_len)
{
	int i;
	size_t	sz = sizeof(key_value) + key_len + value_len + 2 + value_len;
	key_value *kv = malloc(sz);
	if (!kv)	return(0);

	// save before molesting
	kv->key_int = kv->value_int = seed * g_config.value_factor;
	
	// a little hinky, pointing internally to local memory, but so much more efficient
	kv->key_str = ((char *)kv)+ sizeof(key_value);
	kv->value_str = ((char *)kv)+ sizeof(key_value) + key_len + 1;
	kv->value_blob = kv->value_str + value_len + 1;
	kv->value_blob_len = value_len;
	
	// generate the string key
	kv->key_str[key_len] = 0;
	for (i = key_len-1; i >= 0; i--) {
		kv->key_str[i] = (seed % 10) + '0';
		seed = seed / 10;
	}
	
	// build a string out of the value, might be different from key
	// (optimization: don't build if integer test, or if value_factor == 1
	char value_str_short[key_len];
	seed = kv->value_int;
	value_str_short[key_len] = 0;
	for (i = key_len-1; i >= 0; i--) {
		value_str_short[i] = (seed % 10) + '0';
		seed = seed / 10;
	}
	
	
	// longer value likely required: multiple copies of value_str_short
	i=0;
	while (i < value_len) {
		if (value_len - i > key_len) {
			memcpy(&kv->value_str[i], value_str_short, key_len);
			i += key_len;
		}
		else {
			memcpy(&kv->value_str[i], value_str_short, value_len - i);
			i += (value_len - i);
		}
	}	
	kv->value_str[value_len] = 0;

	// And how's about a fine blob!
	uint64_t t = kv->value_int;
	memcpy(kv->value_blob, &t, sizeof(t)); // this will make sure some nulls, always a good idea
	memcpy(kv->value_blob + sizeof(t), kv->value_str,kv->value_blob_len - sizeof(t));

	
#ifdef DEBUG_VERBOSE
	fprintf(stderr, "make key value: key_len %d key %s value_len %d value_str %s value_int %"PRIu64"\n",key_len,kv->key,value_len,kv->value_str,kv->value_int);
#endif
	
	return(kv);	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %r12d
movl %edx, %r15d
movl %edi, %r13d
movl %esi, %r14d
movl %edx, -0x2c(%rbp)
leaq 0x32(%r12,%r15,2), %rdi
callq 0x22f0
movq %rax, %rbx
testq %rax, %rax
je 0x4201
leaq 0x1829d(%rip), %rax     # 0x1c330
movl -0x2c(%rbp), %esi
leaq 0x30(%rbx), %rcx
movl %r14d, %r9d
movq %r12, %rdx
movq %r15, -0x40(%rbp)
movl 0x44(%rax), %eax
imull %r13d, %eax
movq %rax, 0x28(%rbx)
movq %rax, (%rbx)
movq %rcx, 0x8(%rbx)
leaq 0x31(%rbx,%r12), %rcx
leaq 0x30(%rbx,%r12), %rax
movq %rcx, 0x10(%rbx)
movl %r14d, %ecx
leaq 0x2(%r15,%rax), %rax
movl %esi, %r14d
decl %ecx
movq %rax, 0x20(%rbx)
movl %esi, 0x18(%rbx)
movb $0x0, 0x30(%rbx,%r12)
js 0x4166
movl %ecx, %eax
movl $0xcccccccd, %esi       # imm = 0xCCCCCCCD
leaq 0x1(%rax), %r10
movl %r13d, %edi
movq 0x8(%rbx), %r11
imulq %rsi, %rdi
shrq $0x23, %rdi
leal (%rdi,%rdi), %r8d
leal (%r8,%r8,4), %r8d
subl %r8d, %r13d
orb $0x30, %r13b
movb %r13b, -0x1(%r11,%r10)
decq %r10
movl %edi, %r13d
jne 0x40ef
leaq 0xf(%rdx), %rdi
movq %rsp, %rsi
movq %rsp, -0x38(%rbp)
andq $-0x10, %rdi
subq %rdi, %rsi
movq %rsi, %rsp
testl %ecx, %ecx
movq 0x28(%rbx), %rcx
movb $0x0, (%rdx,%rsi)
js 0x417f
movl $0xcccccccd, %r8d       # imm = 0xCCCCCCCD
movl %ecx, %r10d
imulq %r8, %r10
shrq $0x23, %r10
leal (%r10,%r10), %edi
leal (%rdi,%rdi,4), %edi
subl %edi, %ecx
orb $0x30, %cl
movb %cl, (%rsi,%rax)
addq $-0x1, %rax
movl %r10d, %ecx
jb 0x4141
jmp 0x417f
leaq 0xf(%rdx), %rax
movq %rsp, %rsi
movq %rsp, -0x38(%rbp)
andq $-0x10, %rax
subq %rax, %rsi
movq %rsi, %rsp
movb $0x0, (%rdx,%rsi)
testl %r14d, %r14d
je 0x41cd
movl -0x2c(%rbp), %eax
xorl %r14d, %r14d
movq %rbx, -0x48(%rbp)
movl %eax, %r12d
movslq %r14d, %rdi
addq 0x10(%rbx), %rdi
subl %r9d, %r12d
jbe 0x41c6
movl %r9d, %r15d
movq %rdx, %r13
movq %rsi, %rbx
callq 0x2180
addl %r15d, %r14d
movq %rbx, %rsi
movq -0x48(%rbp), %rbx
movq %r13, %rdx
movl %r15d, %r9d
movl %r12d, %eax
cmpl -0x2c(%rbp), %r14d
jb 0x4191
jmp 0x41cd
movl %eax, %edx
callq 0x2180
movq 0x10(%rbx), %rax
movq -0x40(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
movq %rcx, (%rax)
movq 0x20(%rbx), %rdi
movslq 0x18(%rbx), %rdx
movq 0x10(%rbx), %rsi
addq $0x8, %rdi
addq $-0x8, %rdx
callq 0x2180
movq -0x38(%rbp), %rsp
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq