// File: /workspace/github_c_makefile_star2_O3/sharpyfox[P]citrusleaf-client/src/citrusleaf.c
// Function: cl_compile
int
cl_compile(uint info1, uint info2, uint info3, const char *ns, const char *set, const cl_object *key, const cf_digest *digest,
	cl_bin *values, cl_operator operator, cl_operation *operations, int n_values,  
	uint8_t **buf_r, size_t *buf_sz_r, const cl_write_parameters *cl_w_p, cf_digest *d_ret, uint64_t trid, cl_scan_param_field *scan_param_field)
{
	// I hate strlen
	int		ns_len = ns ? strlen(ns) : 0;
	int		set_len = set ? strlen(set) : 0;
	int		i;

	// determine the size
	size_t	msg_sz = sizeof(as_msg); // header
	// fields
	if (ns)     msg_sz += sizeof(cl_msg_field) + ns_len;
	if (set)    msg_sz += sizeof(cl_msg_field) + set_len;
	if (key)    msg_sz += sizeof(cl_msg_field) + 1 + key->sz;
	if (digest) msg_sz += sizeof(cl_msg_field) + 1 + sizeof(cf_digest);
	if (trid)   msg_sz += sizeof(cl_msg_field) + sizeof(trid);
	if (scan_param_field)	msg_sz += sizeof(cl_msg_field) + 1 + sizeof(cl_scan_param_field);

	// ops
	for (i=0;i<n_values;i++) {
		cl_bin *tmpValue = 0;
		if( values ){
			tmpValue = &values[i];
		}else if( operations ){
			tmpValue = &operations[i].bin;
		}
		
		msg_sz += sizeof(cl_msg_op) + strlen(tmpValue->bin_name);

        if (0 != cl_value_to_op_get_size(tmpValue, &msg_sz)) {
			cf_error("illegal parameter: bad type %d write op %d", tmpValue->object.type,i);
			return(-1);
		}
	}
	
	// size too small? malloc!
	uint8_t	*buf;
	uint8_t *mbuf = 0;
	if ((*buf_r) && (msg_sz > *buf_sz_r)) {
		mbuf = buf = malloc(msg_sz);
		if (!buf) 			return(-1);
		*buf_r = buf;
	}
	else
		buf = *buf_r;
	
	*buf_sz_r = msg_sz;
	
	// debug - shouldn't be required
	memset(buf, 0, msg_sz);
	
	// lay in some parameters
	uint32_t generation = 0;
	if (cl_w_p) {
		if (cl_w_p->unique) {
			info2 |= CL_MSG_INFO2_WRITE_UNIQUE;
		} else if (cl_w_p->unique_bin) {
			info2 |= CL_MSG_INFO2_WRITE_BINUNIQUE;
		} else if (cl_w_p->use_generation) {
			info2 |= CL_MSG_INFO2_GENERATION;
			generation = cl_w_p->generation;
		} else if (cl_w_p->use_generation_gt) {
			info2 |= CL_MSG_INFO2_GENERATION_GT;
			generation = cl_w_p->generation;
		} else if (cl_w_p->use_generation_dup) {
			info2 |= CL_MSG_INFO2_GENERATION_DUP;
			generation = cl_w_p->generation;
		}
	}
	
	uint32_t record_ttl = cl_w_p ? cl_w_p->record_ttl : 0;
	uint32_t transaction_ttl = cl_w_p ? cl_w_p->timeout_ms : 0;

	// lay out the header
	int n_fields = ( ns ? 1 : 0 ) + (set ? 1 : 0) + (key ? 1 : 0) + (digest ? 1 : 0) + (trid ? 1 : 0) + (scan_param_field ? 1 : 0);
	buf = cl_write_header(buf, msg_sz, info1, info2, info3, generation, record_ttl, transaction_ttl, n_fields, n_values);
		
	// now the fields
	buf = write_fields(buf, ns, ns_len, set, set_len, key, digest, d_ret, trid,scan_param_field);
	if (!buf) {
		if (mbuf)	free(mbuf);
		return(-1);
	}

	// lay out the ops
	if (n_values) {
		cl_msg_op *op = (cl_msg_op *) buf;
		cl_msg_op *op_tmp;
		for (i = 0; i< n_values;i++) {
			if( values ) {
				cl_value_to_op( &values[i], operator, NULL, op);
			}else if (operations) {
				cl_value_to_op( NULL, 0, &operations[i], op);
			}
	
			op_tmp = cl_msg_op_get_next(op);
			cl_msg_swap_op(op);
			op = op_tmp;
		}
	}
	return(0);	
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %r9, %r15
movq %r8, %r14
movq %rcx, %rbx
movl %edx, %ebp
testq %rcx, %rcx
movl %esi, 0x4(%rsp)
movl %edi, 0x28(%rsp)
je 0x4b75
movq %rbx, %rdi
callq 0x20e0
movq %rax, %r12
jmp 0x4b78
xorl %r12d, %r12d
testq %r14, %r14
movq %rbx, 0x48(%rsp)
je 0x4bab
movq %r14, %rdi
callq 0x20e0
movslq %r12d, %rcx
testq %rbx, %rbx
movl $0x23, %r8d
movslq %eax, %rdx
movq %rcx, 0x30(%rsp)
leaq 0x28(%rcx), %rcx
cmovneq %rcx, %r8
addq %rdx, %r8
jmp 0x4bc6
movslq %r12d, %rax
testq %rbx, %rbx
movl $0x1e, %r8d
leaq 0x23(%rax), %rcx
movq %rax, 0x30(%rsp)
cmovneq %rcx, %r8
xorl %eax, %eax
movq 0x150(%rsp), %r9
movq 0x148(%rsp), %rbx
movq 0x100(%rsp), %rdi
testq %r15, %r15
movq %r8, 0x8(%rsp)
movq %rax, 0x38(%rsp)
movq %r12, 0x40(%rsp)
movl %ebp, 0x2c(%rsp)
je 0x4c04
movq 0x8(%r15), %rcx
leaq 0x6(%rcx,%r8), %r8
movq %r8, 0x8(%rsp)
movq %rdi, %rcx
leaq 0x1a(%r8), %rdx
movl 0x120(%rsp), %esi
movq %r15, 0x18(%rsp)
movq %r14, 0x10(%rsp)
orq %rbx, %rcx
testq %rdi, %rdi
cmoveq %r8, %rdx
testq %rbx, %rbx
leaq 0xd(%rdx), %rax
cmoveq %rdx, %rax
testq %r9, %r9
leaq 0x8(%rax), %rbp
cmoveq %rax, %rbp
orq %r9, %rcx
je 0x4c46
movq %rbp, 0x8(%rsp)
movq 0x108(%rsp), %rax
testl %esi, %esi
jle 0x4cb6
movq 0x118(%rsp), %r12
movl %esi, %r14d
xorl %r13d, %r13d
leaq 0x8(%rsp), %rbp
testq %rax, %rax
movq %r12, %r15
je 0x4c77
movq %r13, %r15
shlq $0x6, %r15
addq %rax, %r15
movq %r15, %rdi
callq 0x20e0
movq 0x8(%rsp), %rcx
movq %r15, %rdi
movq %rbp, %rsi
leaq 0x8(%rax,%rcx), %rax
movq %rax, 0x8(%rsp)
callq 0x496a
testl %eax, %eax
jne 0x4cf5
movq 0x108(%rsp), %rax
incq %r13
addq $0x48, %r12
cmpq %r13, %r14
jne 0x4c65
movq 0x8(%rsp), %rbp
movq 0x128(%rsp), %r14
movq 0x130(%rsp), %r12
xorl %r13d, %r13d
movq (%r14), %r15
testq %r15, %r15
je 0x4d2e
cmpq (%r12), %rbp
jbe 0x4d31
movq %rbp, %rdi
callq 0x22e0
testq %rax, %rax
je 0x4d98
movq %rax, %r15
movq %rax, (%r14)
movq %rax, 0x20(%rsp)
jmp 0x4d3a
leaq 0x115cc(%rip), %rax     # 0x162c8
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x0, (%rax)
js 0x510e
leaq 0x115bf(%rip), %rax     # 0x162d0
leaq 0xab48(%rip), %rsi      # 0xf860
xorl %edi, %edi
movl %r13d, %ecx
movq (%rax), %r8
movl 0x20(%r15), %edx
xorl %eax, %eax
callq *%r8
jmp 0x510e
xorl %r15d, %r15d
movq $0x0, 0x20(%rsp)
movq 0x138(%rsp), %r14
movq %r15, %rdi
xorl %esi, %esi
movq %rbp, %rdx
movq %rbp, (%r12)
callq 0x2140
testq %r14, %r14
je 0x4d6a
cmpb $0x1, (%r14)
jne 0x4d74
orl $0x20, 0x4(%rsp)
movq 0x10(%rsp), %rax
jmp 0x4d85
movq 0x10(%rsp), %rax
xorps %xmm0, %xmm0
jmp 0x4dc9
cmpb $0x1, 0x1(%r14)
movq 0x10(%rsp), %rax
jne 0x4d8a
orl $0x40, 0x4(%rsp)
xorl %r13d, %r13d
jmp 0x4dc3
cmpb $0x1, 0x2(%r14)
jne 0x4da2
orl $0x4, 0x4(%rsp)
jmp 0x4dbf
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x510e
cmpb $0x1, 0x3(%r14)
jne 0x4db0
orl $0x8, 0x4(%rsp)
jmp 0x4dbf
xorl %r13d, %r13d
cmpb $0x1, 0x4(%r14)
jne 0x4dc3
orl $0x10, 0x4(%rsp)
movl 0x8(%r14), %r13d
movsd 0xc(%r14), %xmm0
movaps %xmm0, 0x50(%rsp)
movq 0x48(%rsp), %r12
xorl %r14d, %r14d
movq %r15, %rdi
movw $0x302, (%r15)          # imm = 0x302
testq %r12, %r12
setne %r14b
cmpq $0x1, %rax
sbbw $-0x1, %r14w
cmpq $0x1, 0x18(%rsp)
sbbw $-0x1, %r14w
cmpq $0x1, 0x100(%rsp)
sbbw $-0x1, %r14w
cmpq $0x1, %rbx
sbbw $-0x1, %r14w
cmpq $0x1, 0x150(%rsp)
sbbw $-0x1, %r14w
addq $-0x8, %rbp
movl %ebp, 0x2(%r15)
shrq $0x20, %rbp
movw %bp, 0x6(%r15)
callq 0xc8a8
movl 0x28(%rsp), %eax
movb $0x16, 0x8(%r15)
pshufd $0xe1, 0x50(%rsp), %xmm0 # xmm0 = mem[1,0,2,3]
leaq 0x8(%r15), %rdi
movb %al, 0x9(%r15)
movl 0x4(%rsp), %eax
movb %al, 0xa(%r15)
movl 0x2c(%rsp), %eax
movb %al, 0xb(%r15)
movw $0x0, 0xc(%r15)
movl %r13d, 0xe(%r15)
movl 0x120(%rsp), %r13d
movq %xmm0, 0x12(%r15)
movw %r14w, 0x1a(%r15)
movw %r13w, 0x1c(%r15)
callq 0xc8c5
leaq 0x1e(%r15), %rbp
testq %r12, %r12
je 0x4ec0
movq 0x40(%rsp), %r14
movq 0x30(%rsp), %rdx
leaq 0x23(%r15), %rdi
movq %r12, %rsi
movb $0x0, 0x22(%r15)
incl %r14d
movl %r14d, 0x1e(%r15)
callq 0x21b0
movq %rbp, %rdi
leaq 0x22(%r15,%r14), %r14
callq 0xc8f9
movq %r14, %rbp
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x4ef7
movq 0x38(%rsp), %rax
leaq 0x5(%rbp), %rdi
movb $0x1, 0x4(%rbp)
leal 0x1(%rax), %r14d
movslq %eax, %rdx
movl %r14d, (%rbp)
callq 0x21b0
movq %rbp, %rdi
leaq 0x4(%rbp,%r14), %r14
callq 0xc8f9
movq %r14, %rbp
movq 0x18(%rsp), %r14
movq 0x150(%rsp), %r15
testq %rbx, %rbx
je 0x4f2a
movq %rbp, %rdi
bswapq %rbx
movb $0x7, 0x4(%rbp)
movl $0x9, (%rbp)
movq %rbx, 0x5(%rbp)
leaq 0xd(%rbp), %rbx
callq 0xc8f9
movq %rbx, %rbp
testq %r15, %r15
je 0x4f51
movb $0x8, 0x4(%rbp)
movl $0x3, (%rbp)
movq %rbp, %rdi
leaq 0x7(%rbp), %rbx
movzwl (%r15), %eax
movw %ax, 0x5(%rbp)
callq 0xc8f9
movq %rbx, %rbp
movq 0x108(%rsp), %rax
movq 0x140(%rsp), %r15
testq %r14, %r14
je 0x501e
movb $0x2, 0x4(%rbp)
movl (%r14), %edx
leal -0x1(%rdx), %eax
cmpl $0xa, %eax
ja 0x5156
leaq 0xa7c0(%rip), %rcx      # 0xf744
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb %dl, 0x5(%rbp)
movl 0x8(%r14), %ebx
leaq 0x6(%rbp), %rdi
addl $0x2, %ebx
movl %ebx, (%rbp)
movq 0x8(%r14), %rdx
movq 0x10(%r14), %rsi
callq 0x21b0
movq %rbp, %rdi
leaq 0x4(%rbp), %rax
movl %ebx, %r12d
addq %rax, %r12
callq 0xc8f9
testq %r15, %r15
je 0x5031
movq 0x18(%rsp), %rax
addq $0x5, %rbp
movq 0x8(%rax), %rbx
movq 0x38(%rsp), %rax
incq %rbx
testl %eax, %eax
je 0x5023
leaq 0x68(%rsp), %r13
movslq %eax, %r14
movq %r13, %rdi
callq 0x2370
movq 0x10(%rsp), %rsi
movq %r13, %rdi
movq %r14, %rdx
callq 0x23c0
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
callq 0x23c0
movq %r13, %rsi
movl 0x120(%rsp), %r13d
movq %r15, %rdi
callq 0x2490
jmp 0x5031
movq %rbp, %r12
jmp 0x5039
movq %rbp, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2480
movq 0x108(%rsp), %rax
movq 0x100(%rsp), %r14
testq %r14, %r14
je 0x50a0
movb $0x4, 0x4(%r12)
movl $0x15, (%r12)
movq %r12, %rdi
leaq 0x19(%r12), %rbx
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %rax, 0x5(%r12)
movq %rcx, 0xd(%r12)
movl 0x10(%r14), %eax
movl %eax, 0x15(%r12)
callq 0xc8f9
testq %r15, %r15
je 0x5096
movl 0x10(%r14), %eax
movl %eax, 0x10(%r15)
movq (%r14), %rax
movq 0x8(%r14), %rcx
movq %rcx, 0x8(%r15)
movq %rax, (%r15)
movq 0x108(%rsp), %rax
jmp 0x50a3
movq %r12, %rbx
testl %r13d, %r13d
jle 0x510c
movl 0x110(%rsp), %ebp
movq 0x118(%rsp), %r15
movl %r13d, %r12d
movq %rax, %r14
testq %rax, %rax
je 0x50cb
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
jmp 0x50dd
cmpq $0x0, 0x118(%rsp)
je 0x50e5
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x49c7
movl (%rbx), %eax
movq %rbx, %rdi
leaq 0x4(%rbx,%rax), %r13
callq 0xc8e8
movq 0x108(%rsp), %rax
addq $0x48, %r15
addq $0x40, %r14
decq %r12
movq %r13, %rbx
jne 0x50bd
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x3, 0x5(%rbp)
jmp 0x4f90
movb $0x1, 0x5(%rbp)
movl $0xa, %ebx
movq 0x10(%r14), %rax
bswapq %rax
movq %rax, 0x6(%rbp)
movl $0xa, (%rbp)
movq 0x10(%r14), %rax
bswapq %rax
movq %rax, 0x6(%rbp)
jmp 0x4fab
leaq 0x1116b(%rip), %rax     # 0x162c8
cmpl $0x0, (%rax)
js 0x5179
leaq 0x11167(%rip), %rax     # 0x162d0
leaq 0xa74a(%rip), %rsi      # 0xf8ba
xorl %edi, %edi
movq (%rax), %rcx
xorl %eax, %eax
callq *%rcx
movq 0x20(%rsp), %rdi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testq %rdi, %rdi
je 0x510e
callq 0x22c0
jmp 0x510e