// File: /workspace/github_c_makefile_star2_O3/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
testq %rdi, %rdi
movq %rdi, %r12
movq %rdi, %r15
movq %rcx, %rbx
movq %rdx, %r13
movl %esi, %ebp
cmoveq %rdx, %r12
movq %r12, %rdi
callq 0x20e0
movslq %eax, %rdx
leaq 0x8(%rbx), %r14
movq %r12, %rsi
movq %rax, 0x8(%rsp)
leal 0x4(%rdx), %ecx
movq %r14, %rdi
movl %ecx, (%rbx)
movb %al, 0x7(%rbx)
movl %ecx, 0x14(%rsp)
movb $0x0, 0x6(%rbx)
callq 0x21b0
testq %r15, %r15
jne 0x4a2a
testq %r13, %r13
je 0x4a45
movl 0x40(%r13), %ebp
movq %r13, %r15
cmpl $0x9, %ebp
ja 0x4a70
movl %ebp, %eax
leaq 0xacb4(%rip), %rcx      # 0xf6ec
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x2, %cl
jmp 0x4aa6
movb $0x2, %cl
xorl %eax, %eax
xorl %r15d, %r15d
jmp 0x4aa8
movb $0xa, %cl
jmp 0x4aa6
movb $-0x7c, %cl
jmp 0x4aa6
movb $0x5, %cl
jmp 0x4aa6
movb $0x1, %al
movb $-0x7f, %cl
jmp 0x4aa8
movb $-0x7e, %cl
jmp 0x4aa6
movb $0x1, %cl
jmp 0x4aa6
movb $0x9, %cl
jmp 0x4aa6
movb $-0x7d, %cl
jmp 0x4aa6
leaq 0x11851(%rip), %rax     # 0x162c8
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
cmpl $0x0, (%rax)
js 0x4b2d
leaq 0x11843(%rip), %rax     # 0x162d0
leaq 0xad99(%rip), %rsi      # 0xf82d
xorl %edi, %edi
movl %ebp, %edx
movq (%rax), %rcx
xorl %eax, %eax
callq *%rcx
jmp 0x4b2d
movb $0xb, %cl
xorl %eax, %eax
movb %cl, 0x4(%rbx)
movq 0x8(%rsp), %rsi
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movb 0x20(%r15), %cl
movb %cl, 0x5(%rbx)
movl 0x20(%r15), %ecx
cmpq $0xb, %rcx
ja 0x4b2d
leaq 0xac46(%rip), %rdi      # 0xf714
movzbl %sil, %edx
movslq (%rdi,%rcx,4), %rcx
addq %rdx, %r14
addq %rdi, %rcx
jmpq *%rcx
testb %al, %al
je 0x4aff
movq 0x30(%r15), %rax
movq (%rax), %rcx
movq 0x8(%rax), %rax
bswapq %rcx
bswapq %rax
movq %rcx, (%r14)
leal 0x14(%rsi), %ecx
movq %rax, 0x8(%r14)
jmp 0x4b28
movl 0x14(%rsp), %eax
movq %r14, %rdi
addl 0x28(%r15), %eax
movl %eax, (%rbx)
movq 0x28(%r15), %rdx
movq 0x30(%r15), %rsi
callq 0x21b0
jmp 0x4b2a
movq 0x30(%r15), %rax
leal 0xc(%rsi), %ecx
bswapq %rax
movq %rax, (%r14)
movl %ecx, (%rbx)
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq