// File: /workspace/github_c_makefile_star2_O1/sharpyfox[P]citrusleaf-client/src/citrusleaf.c
// Function: cl_value_to_op
int
cl_value_to_op(cl_bin *v, cl_operator operator, cl_operation *operation, cl_msg_op *op)
{
	cl_bin *bin = v?v:&operation->bin;
	int	bin_len = strlen(bin->bin_name);
	op->op_sz = sizeof(cl_msg_op) + bin_len - sizeof(uint32_t);
	op->name_sz = bin_len;
	op->version = 0;
	memcpy(op->name, bin->bin_name, bin_len);

	cl_operator tmpOp = 0;
	cl_bin      *tmpValue = 0;
	
	if( v ){
		tmpOp = operator;
		tmpValue = v;
	}else if( operation ){
		tmpOp = operation->op;
		tmpValue = &(operation->bin);
	}

	switch(tmpOp) {
		case CL_OP_WRITE:
			op->op = CL_MSG_OP_WRITE;
			break;
		case CL_OP_READ:
			op->op = CL_MSG_OP_READ;
			break;
		case CL_OP_INCR:
			op->op = CL_MSG_OP_INCR;
			break;
		case CL_OP_MC_INCR:
			op->op = CL_MSG_OP_MC_INCR;
			break;
		case CL_OP_APPEND:
			op->op = CL_MSG_OP_APPEND;
			break;
		case CL_OP_PREPEND:
			op->op = CL_MSG_OP_PREPEND;
			break;
		case CL_OP_MC_APPEND:
			op->op = CL_MSG_OP_MC_APPEND;
			break;
		case CL_OP_MC_PREPEND:
			op->op = CL_MSG_OP_MC_PREPEND;
			break;
		case CL_OP_TOUCH:
			op->op = CL_MSG_OP_TOUCH;
			break;
		case CL_OP_MC_TOUCH:
			op->op = CL_MSG_OP_MC_TOUCH;
			break;
		default:
			cf_error("API user requested unknown operation type %d, fail", (int)tmpOp);
			return(-1);
	}

	uint8_t *data = cl_msg_op_get_value_p(op);
	op->particle_type = tmpValue->object.type;
	switch(tmpValue->object.type) {
		case CL_NULL:
			break;
		case CL_INT:
			op->op_sz += value_to_op_int(tmpValue->object.u.i64, data);
			break;
		case CL_STR:
			op->op_sz += tmpValue->object.sz;
			memcpy(data, tmpValue->object.u.str, tmpValue->object.sz);
			break;
		case CL_BLOB:
		case CL_JAVA_BLOB:
		case CL_CSHARP_BLOB:
		case CL_PYTHON_BLOB:
		case CL_RUBY_BLOB:
		case CL_PHP_BLOB:
			if (op->op == CL_MSG_OP_MC_INCR) {
				op->op_sz += value_to_op_two_ints(tmpValue->object.u.blob, data);
			} else {
				op->op_sz += tmpValue->object.sz;
				memcpy(data, tmpValue->object.u.blob, tmpValue->object.sz);
			}
			break;
		default:
#ifdef DEBUG				
			cf_debug("internal error value_to_op has unknown value type %d",tmpValue->object.type);
#endif				
			return(-1);
	}
	return(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movl %esi, %r13d
movq %rdi, %rbp
testq %rdi, %rdi
movq %rdi, %r12
cmoveq %rdx, %r12
movq %r12, %rdi
callq 0x20e0
movq %rax, %r15
movslq %r15d, %rdx
leal 0x4(%rdx), %eax
movl %eax, 0xc(%rsp)
movl %eax, (%rbx)
movb %r15b, 0x7(%rbx)
movb $0x0, 0x6(%rbx)
leaq 0x8(%rbx), %rdi
movq %rdi, 0x10(%rsp)
movq %r12, %rsi
callq 0x21b0
testq %rbp, %rbp
jne 0x4a8f
testq %r14, %r14
je 0x4a8a
movl 0x40(%r14), %r13d
movq %r14, %rbp
jmp 0x4a8f
xorl %r13d, %r13d
xorl %ebp, %ebp
cmpl $0xa, %r13d
jae 0x4afe
movl %r13d, %eax
leaq 0xbd05(%rip), %rcx      # 0x107a4
movb (%rax,%rcx), %al
movb %al, 0x4(%rbx)
movb 0x20(%rbp), %al
movb %al, 0x5(%rbx)
movl 0x20(%rbp), %eax
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0xb, %rax
ja 0x4b57
movzbl %r15b, %ecx
movq 0x10(%rsp), %rdi
addq %rcx, %rdi
leaq 0xbc1b(%rip), %rcx      # 0x106ec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpb $-0x7f, 0x4(%rbx)
jne 0x4b2c
movq 0x30(%rbp), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
bswapq %rcx
bswapq %rax
movq %rcx, (%rdi)
movq %rax, 0x8(%rdi)
leal 0x14(%r15), %eax
jmp 0x4b52
leaq 0x127c3(%rip), %rax     # 0x172c8
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x0, (%rax)
js 0x4b57
leaq 0x127b9(%rip), %rax     # 0x172d0
movq (%rax), %rcx
leaq 0xbcee(%rip), %rsi      # 0x1080f
xorl %edi, %edi
movl %r13d, %edx
xorl %eax, %eax
callq *%rcx
jmp 0x4b57
movl 0xc(%rsp), %eax
addl 0x28(%rbp), %eax
movl %eax, (%rbx)
movq 0x28(%rbp), %rdx
movq 0x30(%rbp), %rsi
callq 0x21b0
jmp 0x4b54
movq 0x30(%rbp), %rax
bswapq %rax
movq %rax, (%rdi)
leal 0xc(%r15), %eax
movl %eax, (%rbx)
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq