// File: /workspace/github_c_makefile_star2_O1/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 $0xb8, %rsp
movq %r9, %r14
movq %r8, %rbx
movq %rcx, %rbp
movl %edx, 0x3c(%rsp)
movl %esi, 0xc(%rsp)
movl %edi, 0x38(%rsp)
xorl %r12d, %r12d
testq %rcx, %rcx
movl $0x0, %r15d
je 0x4ba8
movq %rbp, %rdi
callq 0x20e0
movq %rax, %r15
testq %rbx, %rbx
je 0x4bb8
movq %rbx, %rdi
callq 0x20e0
movq %rax, %r12
movslq %r15d, %rax
movq %rax, 0x50(%rsp)
addq $0x23, %rax
testq %rbp, %rbp
movl $0x1e, %ecx
cmovneq %rax, %rcx
testq %rbx, %rbx
movslq %r12d, %rax
movq %rax, 0x40(%rsp)
leaq 0x5(%rcx,%rax), %rax
cmoveq %rcx, %rax
movq %rax, 0x10(%rsp)
testq %r14, %r14
je 0x4c01
movq 0x8(%r14), %rax
movq 0x10(%rsp), %rcx
leaq 0x6(%rax,%rcx), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, 0xf0(%rsp)
je 0x4c12
addq $0x1a, 0x10(%rsp)
cmpq $0x0, 0x138(%rsp)
je 0x4c23
addq $0xd, 0x10(%rsp)
movq %r14, 0x20(%rsp)
movq %rbx, 0x30(%rsp)
cmpq $0x0, 0x140(%rsp)
je 0x4c3e
addq $0x8, 0x10(%rsp)
movq %r12, 0x48(%rsp)
movq 0xf8(%rsp), %rax
cmpl $0x0, 0x110(%rsp)
jle 0x4cbc
movl 0x110(%rsp), %ebx
xorl %r15d, %r15d
leaq 0x10(%rsp), %r13
movq 0x108(%rsp), %r14
testq %rax, %rax
movq %r14, %r12
je 0x4c7e
movq %r15, %r12
shlq $0x6, %r12
addq %rax, %r12
movq %r12, %rdi
callq 0x20e0
movq 0x10(%rsp), %rcx
leaq 0x8(%rax,%rcx), %rax
movq %rax, 0x10(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x49c8
testl %eax, %eax
jne 0x4d4e
incq %r15
addq $0x48, %r14
cmpq %r15, %rbx
movq 0xf8(%rsp), %rax
jne 0x4c6c
movq 0x120(%rsp), %rbx
movq 0x118(%rsp), %r14
movq (%r14), %r12
testq %r12, %r12
je 0x4d02
movq 0x10(%rsp), %rdi
cmpq (%rbx), %rdi
jbe 0x4d02
callq 0x22e0
testq %rax, %rax
je 0x4dae
movq %rax, %r12
movq $0x0, 0x18(%rsp)
movq %rax, (%r14)
movq %r12, 0x28(%rsp)
jmp 0x4d14
movq $0x0, 0x18(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x128(%rsp), %r15
movq 0x10(%rsp), %r13
movq %r13, (%rbx)
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x2140
testq %r15, %r15
je 0x4d88
cmpb $0x1, (%r15)
movq 0x140(%rsp), %rax
jne 0x4d92
orl $0x20, 0xc(%rsp)
jmp 0x4ddb
leaq 0x12573(%rip), %rax     # 0x172c8
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x0, (%rax)
js 0x5174
leaq 0x12566(%rip), %rax     # 0x172d0
movq (%rax), %r8
movl 0x20(%r12), %edx
leaq 0xbac9(%rip), %rsi      # 0x10842
xorl %edi, %edi
movl %r15d, %ecx
xorl %eax, %eax
callq *%r8
jmp 0x5174
movq 0x140(%rsp), %rax
jmp 0x4ddb
cmpb $0x1, 0x1(%r15)
jne 0x4da0
orl $0x40, 0xc(%rsp)
jmp 0x4ddb
cmpb $0x1, 0x2(%r15)
jne 0x4db8
orl $0x4, 0xc(%rsp)
jmp 0x4dd2
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x5174
cmpb $0x1, 0x3(%r15)
jne 0x4dc6
orl $0x8, 0xc(%rsp)
jmp 0x4dd2
cmpb $0x1, 0x4(%r15)
jne 0x4ddb
orl $0x10, 0xc(%rsp)
movl 0x8(%r15), %ecx
movq %rcx, 0x18(%rsp)
xorl %r14d, %r14d
testq %r15, %r15
movl $0x0, %ebx
je 0x4dec
movl 0x10(%r15), %ebx
testq %r15, %r15
je 0x4df5
movl 0xc(%r15), %r14d
xorl %r15d, %r15d
testq %rbp, %rbp
setne %r15b
cmpq $0x1, 0x30(%rsp)
sbbw $-0x1, %r15w
cmpq $0x1, 0x20(%rsp)
sbbw $-0x1, %r15w
cmpq $0x1, 0xf0(%rsp)
sbbw $-0x1, %r15w
cmpq $0x1, 0x138(%rsp)
sbbw $-0x1, %r15w
cmpq $0x1, %rax
sbbw $-0x1, %r15w
movw $0x302, (%r12)          # imm = 0x302
addq $-0x8, %r13
movl %r13d, 0x2(%r12)
shrq $0x20, %r13
movw %r13w, 0x6(%r12)
movq %r12, %rdi
callq 0xccb0
leaq 0x8(%r12), %rdi
movb $0x16, 0x8(%r12)
movl 0x38(%rsp), %eax
movb %al, 0x9(%r12)
movl 0xc(%rsp), %eax
movb %al, 0xa(%r12)
movl 0x3c(%rsp), %eax
movb %al, 0xb(%r12)
movw $0x0, 0xc(%r12)
movq 0x18(%rsp), %rax
movl %eax, 0xe(%r12)
movl %ebx, 0x12(%r12)
movl %r14d, 0x16(%r12)
movw %r15w, 0x1a(%r12)
movl 0x110(%rsp), %r14d
movw %r14w, 0x1c(%r12)
callq 0xcccd
leaq 0x1e(%r12), %r13
testq %rbp, %rbp
je 0x4ef1
movb $0x0, 0x22(%r12)
movq 0x50(%rsp), %rdx
leal 0x1(%rdx), %ebx
movl %ebx, 0x1e(%r12)
leaq 0x23(%r12), %rdi
movq %rbp, %rsi
callq 0x21b0
leaq 0x22(%r12,%rbx), %rbx
movq %r13, %rdi
callq 0xcd01
movq %rbx, %r13
movq 0x30(%rsp), %rsi
testq %rsi, %rsi
movq 0xf0(%rsp), %r12
je 0x4f2d
movb $0x1, 0x4(%r13)
movq 0x40(%rsp), %rdx
leal 0x1(%rdx), %ebx
movl %ebx, (%r13)
leaq 0x5(%r13), %rdi
callq 0x21b0
leaq 0x4(%r13,%rbx), %rbx
movq %r13, %rdi
callq 0xcd01
movq %rbx, %r13
movq 0x138(%rsp), %rax
testq %rax, %rax
je 0x4f5d
movb $0x7, 0x4(%r13)
bswapq %rax
movl $0x9, (%r13)
movq %rax, 0x5(%r13)
leaq 0xd(%r13), %rbx
movq %r13, %rdi
callq 0xcd01
movq %rbx, %r13
movq 0x140(%rsp), %rax
testq %rax, %rax
je 0x4f8e
movb $0x8, 0x4(%r13)
movl $0x3, (%r13)
movzwl (%rax), %eax
movw %ax, 0x5(%r13)
leaq 0x7(%r13), %rbx
movq %r13, %rdi
callq 0xcd01
movq %rbx, %r13
movq 0xf8(%rsp), %rsi
movq 0x130(%rsp), %r15
movq 0x20(%rsp), %rax
testq %rax, %rax
je 0x5087
movb $0x2, 0x4(%r13)
movl (%rax), %edx
leal -0x1(%rdx), %eax
cmpl $0xa, %eax
ja 0x51bf
leaq 0xb756(%rip), %rcx      # 0x1071c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb %dl, 0x5(%r13)
movq 0x20(%rsp), %r14
movl 0x8(%r14), %eax
addl $0x2, %eax
movl %eax, (%r13)
leaq 0x6(%r13), %rdi
movq 0x8(%r14), %rdx
movq 0x10(%r14), %rsi
callq 0x21b0
leaq 0x4(%r13), %rax
movl (%r13), %ebp
addq %rax, %rbp
movq %r13, %rdi
callq 0xcd01
movb $0x1, %bl
testq %r15, %r15
je 0x5070
addq $0x5, %r13
movq 0x8(%r14), %r14
incq %r14
cmpl $0x0, 0x48(%rsp)
je 0x5062
leaq 0x58(%rsp), %r12
movq %r12, %rdi
callq 0x2370
movq %r12, %rdi
movq 0x30(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x23c0
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x23c0
movq %r15, %rdi
movq %r12, %rsi
movq 0xf0(%rsp), %r12
callq 0x2490
jmp 0x5070
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x2480
movq %rbp, %r13
movq 0xf8(%rsp), %rsi
movl 0x110(%rsp), %r14d
testb %bl, %bl
je 0x50e7
testq %r12, %r12
je 0x50eb
movb $0x4, 0x4(%r13)
movl $0x15, (%r13)
movq (%r12), %rax
movq 0x8(%r12), %rcx
movq %rax, 0x5(%r13)
movq %rcx, 0xd(%r13)
movl 0x10(%r12), %eax
movl %eax, 0x15(%r13)
leaq 0x19(%r13), %rbx
movq %r13, %rdi
callq 0xcd01
testq %r15, %r15
je 0x50dd
movl 0x10(%r12), %eax
movl %eax, 0x10(%r15)
movq (%r12), %rax
movq 0x8(%r12), %rcx
movq %rcx, 0x8(%r15)
movq %rax, (%r15)
movq 0xf8(%rsp), %rsi
jmp 0x50ee
xorl %ebx, %ebx
jmp 0x50ee
movq %r13, %rbx
testq %rbx, %rbx
je 0x5160
testl %r14d, %r14d
jle 0x515c
movl 0x100(%rsp), %ebp
movl %r14d, %r12d
movq %rsi, %r14
movq 0x108(%rsp), %r15
testq %rsi, %rsi
je 0x511b
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
jmp 0x512d
cmpq $0x0, 0x108(%rsp)
je 0x5135
xorl %edi, %edi
xorl %esi, %esi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x4a23
movl (%rbx), %eax
leaq 0x4(%rbx,%rax), %r13
movq %rbx, %rdi
callq 0xccf0
addq $0x48, %r15
addq $0x40, %r14
decq %r12
movq %r13, %rbx
movq 0xf8(%rsp), %rsi
jne 0x510d
xorl %ebx, %ebx
jmp 0x5174
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x5174
callq 0x22c0
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x3, 0x5(%r13)
jmp 0x4fd3
movb $0x1, 0x5(%r13)
movq 0x20(%rsp), %r14
movq 0x10(%r14), %rax
bswapq %rax
movq %rax, 0x6(%r13)
movl $0xa, (%r13)
movq 0x10(%r14), %rax
bswapq %rax
movq %rax, 0x6(%r13)
jmp 0x4ff4
leaq 0x12102(%rip), %rax     # 0x172c8
cmpl $0x0, (%rax)
js 0x51f1
leaq 0x120fe(%rip), %rax     # 0x172d0
movq (%rax), %rcx
leaq 0xb6c0(%rip), %rsi      # 0x1089c
xorl %ebx, %ebx
xorl %edi, %edi
xorl %eax, %eax
callq *%rcx
movq 0xf8(%rsp), %rsi
jmp 0x5083
xorl %ebx, %ebx
jmp 0x5083