// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movl %esi, 0x54(%rsp)
movq %rdx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x5c1b
movq 0x58(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x5c25
movq 0x48(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
callq 0x2100
movl %eax, 0x34(%rsp)
movslq 0x34(%rsp), %rax
addq $0x8, %rax
subq $0x4, %rax
movl %eax, %ecx
movq 0x40(%rsp), %rax
movl %ecx, (%rax)
movl 0x34(%rsp), %eax
movb %al, %cl
movq 0x40(%rsp), %rax
movb %cl, 0x7(%rax)
movq 0x40(%rsp), %rax
movb $0x0, 0x6(%rax)
movq 0x40(%rsp), %rdi
addq $0x8, %rdi
movq 0x38(%rsp), %rsi
movslq 0x34(%rsp), %rdx
callq 0x21e0
movl $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
cmpq $0x0, 0x58(%rsp)
je 0x5caf
movl 0x54(%rsp), %eax
movl %eax, 0x30(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0x5ccf
cmpq $0x0, 0x48(%rsp)
je 0x5ccd
movq 0x48(%rsp), %rax
movl 0x40(%rax), %eax
movl %eax, 0x30(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0x5ccf
movl 0x30(%rsp), %eax
movq %rax, 0x10(%rsp)
subq $0x9, %rax
ja 0x5d6e
movq 0x10(%rsp), %rax
leaq 0x12a4a(%rip), %rcx     # 0x18738
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x40(%rsp), %rax
movb $0x2, 0x4(%rax)
jmp 0x5da5
movq 0x40(%rsp), %rax
movb $0x1, 0x4(%rax)
jmp 0x5da5
movq 0x40(%rsp), %rax
movb $0x5, 0x4(%rax)
jmp 0x5da5
movq 0x40(%rsp), %rax
movb $-0x7f, 0x4(%rax)
jmp 0x5da5
movq 0x40(%rsp), %rax
movb $0x9, 0x4(%rax)
jmp 0x5da5
movq 0x40(%rsp), %rax
movb $0xa, 0x4(%rax)
jmp 0x5da5
movq 0x40(%rsp), %rax
movb $-0x7e, 0x4(%rax)
jmp 0x5da5
movq 0x40(%rsp), %rax
movb $-0x7d, 0x4(%rax)
jmp 0x5da5
movq 0x40(%rsp), %rax
movb $0xb, 0x4(%rax)
jmp 0x5da5
movq 0x40(%rsp), %rax
movb $-0x7c, 0x4(%rax)
jmp 0x5da5
leaq 0x18563(%rip), %rax     # 0x1e2d8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x5d98
leaq 0x1855c(%rip), %rax     # 0x1e2e0
movq (%rax), %rcx
movl 0x30(%rsp), %edx
xorl %edi, %edi
leaq 0x12ae5(%rip), %rsi     # 0x18879
movb $0x0, %al
callq *%rcx
movl $0xffffffff, 0x64(%rsp) # imm = 0xFFFFFFFF
jmp 0x5ec0
movq 0x40(%rsp), %rdi
callq 0x5ed0
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
movb 0x20(%rax), %cl
movq 0x40(%rsp), %rax
movb %cl, 0x5(%rax)
movq 0x28(%rsp), %rax
movl 0x20(%rax), %eax
movq %rax, 0x8(%rsp)
subq $0xb, %rax
ja 0x5eae
movq 0x8(%rsp), %rax
leaq 0x12979(%rip), %rcx     # 0x18760
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
jmp 0x5eb8
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x5ef0
movl %eax, %ecx
movq 0x40(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x5eb8
movq 0x28(%rsp), %rax
movq 0x28(%rax), %rdx
movq 0x40(%rsp), %rax
movl (%rax), %ecx
addq %rdx, %rcx
movl %ecx, (%rax)
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rsi
movq 0x28(%rsp), %rax
movq 0x28(%rax), %rdx
callq 0x21e0
jmp 0x5eb8
movq 0x40(%rsp), %rax
movzbl 0x4(%rax), %eax
cmpl $0x81, %eax
jne 0x5e7b
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rdi
movq 0x20(%rsp), %rsi
callq 0x5f30
movl %eax, %ecx
movq 0x40(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
jmp 0x5eac
movq 0x28(%rsp), %rax
movq 0x28(%rax), %rdx
movq 0x40(%rsp), %rax
movl (%rax), %ecx
addq %rdx, %rcx
movl %ecx, (%rax)
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rsi
movq 0x28(%rsp), %rax
movq 0x28(%rax), %rdx
callq 0x21e0
jmp 0x5eb8
movl $0xffffffff, 0x64(%rsp) # imm = 0xFFFFFFFF
jmp 0x5ec0
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopl (%rax)