// File: /workspace/github_c_makefile_star2_O1/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, %r14d
movl %edi, %r13d
movl %esi, %r15d
movl %edx, -0x2c(%rbp)
movl %edx, %r12d
leaq 0x32(%r15,%r12,2), %rdi
callq 0x22f0
testq %rax, %rax
je 0x4259
movq %rax, %rbx
leaq 0x1822b(%rip), %rax     # 0x1c330
movl 0x44(%rax), %eax
imull %r13d, %eax
movq %rax, 0x28(%rbx)
movq %rax, (%rbx)
leaq 0x30(%rbx), %rax
movq %rax, 0x8(%rbx)
leaq 0x30(%rbx,%r15), %rax
leaq 0x31(%rbx,%r15), %rcx
movq %rcx, 0x10(%rbx)
movq %r12, -0x40(%rbp)
leaq 0x2(%r12,%rax), %rax
movq %rax, 0x20(%rbx)
movl -0x2c(%rbp), %r11d
movl %r11d, 0x18(%rbx)
movb $0x0, 0x30(%rbx,%r15)
movl %r14d, %ecx
decl %ecx
movl %ecx, %eax
movq %r15, %rdx
movl %r14d, %r12d
js 0x4187
leaq 0x1(%rax), %r9
movl $0xcccccccd, %esi       # imm = 0xCCCCCCCD
movl %r13d, %edi
imulq %rsi, %rdi
shrq $0x23, %rdi
leal (%rdi,%rdi), %r8d
leal (%r8,%r8,4), %r8d
subl %r8d, %r13d
orb $0x30, %r13b
movq 0x8(%rbx), %r8
movb %r13b, -0x1(%r8,%r9)
decq %r9
movl %edi, %r13d
jg 0x415c
movq %rsp, -0x38(%rbp)
movq %rsp, %r13
leaq 0xf(%rdx), %rsi
andq $-0x10, %rsi
subq %rsi, %r13
movq %r13, %rsp
movq 0x28(%rbx), %r8
movb $0x0, (%rdx,%r13)
testl %ecx, %ecx
js 0x41d6
incq %rax
movl $0xcccccccd, %ecx       # imm = 0xCCCCCCCD
movl %r8d, %esi
imulq %rcx, %rsi
shrq $0x23, %rsi
leal (%rsi,%rsi), %edi
leal (%rdi,%rdi,4), %edi
subl %edi, %r8d
orb $0x30, %r8b
movb %r8b, -0x1(%r13,%rax)
decq %rax
movl %esi, %r8d
jg 0x41b1
testl %r11d, %r11d
je 0x4223
xorl %r14d, %r14d
movq %rdx, -0x48(%rbp)
movl %r11d, %eax
subl %r14d, %eax
movslq %r14d, %rdi
movq %rbx, %r15
addq 0x10(%rbx), %rdi
cmpl %r12d, %eax
movl %r11d, %ebx
jbe 0x4207
movq %r13, %rsi
callq 0x2180
addl %r12d, %r14d
jmp 0x4214
movl %eax, %edx
movq %r13, %rsi
callq 0x2180
movl %ebx, %r14d
movl %ebx, %r11d
cmpl %ebx, %r14d
movq -0x48(%rbp), %rdx
movq %r15, %rbx
jb 0x41e2
movq 0x10(%rbx), %rax
movq -0x40(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
movq %rcx, (%rax)
movq 0x10(%rbx), %rsi
movq 0x20(%rbx), %rdi
addq $0x8, %rdi
movslq 0x18(%rbx), %rdx
addq $-0x8, %rdx
callq 0x2180
movq -0x38(%rbp), %rsp
jmp 0x425b
xorl %ebx, %ebx
movq %rbx, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq