// File: /workspace/github_c_makefile_star2_O0/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 %rbx
subq $0xb0, %rsp
movq 0x110(%rsp), %rax
movq 0x108(%rsp), %rax
movq 0x100(%rsp), %rax
movq 0xf8(%rsp), %rax
movq 0xf0(%rsp), %rax
movq 0xe8(%rsp), %rax
movl 0xe0(%rsp), %eax
movq 0xd8(%rsp), %rax
movl 0xd0(%rsp), %eax
movq 0xc8(%rsp), %rax
movq 0xc0(%rsp), %rax
movl %edi, 0xa8(%rsp)
movl %esi, 0xa4(%rsp)
movl %edx, 0xa0(%rsp)
movq %rcx, 0x98(%rsp)
movq %r8, 0x90(%rsp)
movq %r9, 0x88(%rsp)
cmpq $0x0, 0x98(%rsp)
je 0x605a
movq 0x98(%rsp), %rdi
callq 0x2100
movq %rax, 0x30(%rsp)
jmp 0x6063
xorl %eax, %eax
movq %rax, 0x30(%rsp)
jmp 0x6063
movq 0x30(%rsp), %rax
movl %eax, 0x84(%rsp)
cmpq $0x0, 0x90(%rsp)
je 0x608e
movq 0x90(%rsp), %rdi
callq 0x2100
movq %rax, 0x28(%rsp)
jmp 0x6097
xorl %eax, %eax
movq %rax, 0x28(%rsp)
jmp 0x6097
movq 0x28(%rsp), %rax
movl %eax, 0x80(%rsp)
movq $0x1e, 0x70(%rsp)
cmpq $0x0, 0x98(%rsp)
je 0x60cd
movslq 0x84(%rsp), %rax
addq $0x5, %rax
addq 0x70(%rsp), %rax
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x90(%rsp)
je 0x60ee
movslq 0x80(%rsp), %rax
addq $0x5, %rax
addq 0x70(%rsp), %rax
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x88(%rsp)
je 0x6113
movq 0x88(%rsp), %rax
movq 0x8(%rax), %rax
addq $0x6, %rax
addq 0x70(%rsp), %rax
movq %rax, 0x70(%rsp)
cmpq $0x0, 0xc0(%rsp)
je 0x612c
movq 0x70(%rsp), %rax
addq $0x1a, %rax
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x108(%rsp)
je 0x6145
movq 0x70(%rsp), %rax
addq $0xd, %rax
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x110(%rsp)
je 0x615e
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x70(%rsp)
movl $0x0, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
cmpl 0xe0(%rsp), %eax
jge 0x6250
movq $0x0, 0x68(%rsp)
cmpq $0x0, 0xc8(%rsp)
je 0x61a6
movq 0xc8(%rsp), %rax
movslq 0x7c(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, 0x68(%rsp)
jmp 0x61cc
cmpq $0x0, 0xd8(%rsp)
je 0x61ca
movq 0xd8(%rsp), %rax
movslq 0x7c(%rsp), %rcx
imulq $0x48, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x68(%rsp)
jmp 0x61cc
movq 0x68(%rsp), %rdi
callq 0x2100
addq $0x8, %rax
addq 0x70(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x68(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x5b10
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x623e
leaq 0x180d6(%rip), %rax     # 0x1e2d8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0x622e
leaq 0x180cf(%rip), %rax     # 0x1e2e0
movq (%rax), %r8
movq 0x68(%rsp), %rax
movl 0x20(%rax), %edx
movl 0x7c(%rsp), %ecx
xorl %edi, %edi
leaq 0x12683(%rip), %rsi     # 0x188ac
movb $0x0, %al
callq *%r8
movl $0xffffffff, 0xac(%rsp) # imm = 0xFFFFFFFF
jmp 0x6688
jmp 0x6240
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x6166
movq $0x0, 0x58(%rsp)
movq 0xe8(%rsp), %rax
cmpq $0x0, (%rax)
je 0x62b7
movq 0x70(%rsp), %rax
movq 0xf0(%rsp), %rcx
cmpq (%rcx), %rax
jbe 0x62b7
movq 0x70(%rsp), %rdi
callq 0x2310
movq %rax, 0x60(%rsp)
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x60(%rsp)
jne 0x62a5
movl $0xffffffff, 0xac(%rsp) # imm = 0xFFFFFFFF
jmp 0x6688
movq 0x60(%rsp), %rcx
movq 0xe8(%rsp), %rax
movq %rcx, (%rax)
jmp 0x62c7
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x70(%rsp), %rcx
movq 0xf0(%rsp), %rax
movq %rcx, (%rax)
movq 0x60(%rsp), %rdi
movq 0x70(%rsp), %rdx
xorl %esi, %esi
callq 0x2170
movl $0x0, 0x54(%rsp)
cmpq $0x0, 0xf8(%rsp)
je 0x63de
movq 0xf8(%rsp), %rax
testb $0x1, (%rax)
je 0x6322
movl 0xa4(%rsp), %eax
orl $0x20, %eax
movl %eax, 0xa4(%rsp)
jmp 0x63dc
movq 0xf8(%rsp), %rax
testb $0x1, 0x1(%rax)
je 0x6346
movl 0xa4(%rsp), %eax
orl $0x40, %eax
movl %eax, 0xa4(%rsp)
jmp 0x63da
movq 0xf8(%rsp), %rax
testb $0x1, 0x2(%rax)
je 0x6376
movl 0xa4(%rsp), %eax
orl $0x4, %eax
movl %eax, 0xa4(%rsp)
movq 0xf8(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x54(%rsp)
jmp 0x63d8
movq 0xf8(%rsp), %rax
testb $0x1, 0x3(%rax)
je 0x63a6
movl 0xa4(%rsp), %eax
orl $0x8, %eax
movl %eax, 0xa4(%rsp)
movq 0xf8(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x54(%rsp)
jmp 0x63d6
movq 0xf8(%rsp), %rax
testb $0x1, 0x4(%rax)
je 0x63d4
movl 0xa4(%rsp), %eax
orl $0x10, %eax
movl %eax, 0xa4(%rsp)
movq 0xf8(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x54(%rsp)
jmp 0x63d6
jmp 0x63d8
jmp 0x63da
jmp 0x63dc
jmp 0x63de
cmpq $0x0, 0xf8(%rsp)
je 0x63fa
movq 0xf8(%rsp), %rax
movl 0x10(%rax), %eax
movl %eax, 0x24(%rsp)
jmp 0x6402
xorl %eax, %eax
movl %eax, 0x24(%rsp)
jmp 0x6402
movl 0x24(%rsp), %eax
movl %eax, 0x50(%rsp)
cmpq $0x0, 0xf8(%rsp)
je 0x6426
movq 0xf8(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x20(%rsp)
jmp 0x642e
xorl %eax, %eax
movl %eax, 0x20(%rsp)
jmp 0x642e
movl 0x20(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x98(%rsp), %rdx
xorl %eax, %eax
movl $0x1, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movq 0x90(%rsp), %rsi
xorl %ecx, %ecx
movl $0x1, %edx
cmpq $0x0, %rsi
cmovnel %edx, %ecx
addl %ecx, %eax
movq 0x88(%rsp), %rsi
xorl %ecx, %ecx
movl $0x1, %edx
cmpq $0x0, %rsi
cmovnel %edx, %ecx
addl %ecx, %eax
movq 0xc0(%rsp), %rsi
xorl %ecx, %ecx
movl $0x1, %edx
cmpq $0x0, %rsi
cmovnel %edx, %ecx
addl %ecx, %eax
movq 0x108(%rsp), %rsi
xorl %ecx, %ecx
movl $0x1, %edx
cmpq $0x0, %rsi
cmovnel %edx, %ecx
addl %ecx, %eax
movq 0x110(%rsp), %rsi
xorl %ecx, %ecx
movl $0x1, %edx
cmpq $0x0, %rsi
cmovnel %edx, %ecx
addl %ecx, %eax
movl %eax, 0x48(%rsp)
movq 0x60(%rsp), %rdi
movq 0x70(%rsp), %rsi
movl 0xa8(%rsp), %edx
movl 0xa4(%rsp), %ecx
movl 0xa0(%rsp), %r8d
movl 0x54(%rsp), %r9d
movl 0x50(%rsp), %ebx
movl 0x4c(%rsp), %r11d
movl 0x48(%rsp), %r10d
movl 0xe0(%rsp), %eax
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x5a00
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rdi
movq 0x98(%rsp), %rsi
movl 0x84(%rsp), %edx
movq 0x90(%rsp), %rcx
movl 0x80(%rsp), %r8d
movq 0x88(%rsp), %r9
movq 0xc0(%rsp), %rbx
movq 0x100(%rsp), %r11
movq 0x108(%rsp), %r10
movq 0x110(%rsp), %rax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x66a0
movq %rax, 0x60(%rsp)
cmpq $0x0, 0x60(%rsp)
jne 0x65b0
cmpq $0x0, 0x58(%rsp)
je 0x65a0
movq 0x58(%rsp), %rdi
callq 0x22e0
movl $0xffffffff, 0xac(%rsp) # imm = 0xFFFFFFFF
jmp 0x6688
cmpl $0x0, 0xe0(%rsp)
je 0x667d
movq 0x60(%rsp), %rax
movq %rax, 0x40(%rsp)
movl $0x0, 0x7c(%rsp)
movl 0x7c(%rsp), %eax
cmpl 0xe0(%rsp), %eax
jge 0x667b
cmpq $0x0, 0xc8(%rsp)
je 0x6617
movq 0xc8(%rsp), %rdi
movslq 0x7c(%rsp), %rax
shlq $0x6, %rax
addq %rax, %rdi
movl 0xd0(%rsp), %esi
movq 0x40(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x5bf0
jmp 0x6648
cmpq $0x0, 0xd8(%rsp)
je 0x6646
movq 0xd8(%rsp), %rdx
movslq 0x7c(%rsp), %rax
imulq $0x48, %rax, %rax
addq %rax, %rdx
movq 0x40(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edi
xorl %esi, %esi
callq 0x5bf0
jmp 0x6648
movq 0x40(%rsp), %rdi
callq 0x6b00
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rdi
callq 0x13b70
movq 0x38(%rsp), %rax
movq %rax, 0x40(%rsp)
movl 0x7c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x65d0
jmp 0x667d
movl $0x0, 0xac(%rsp)
movl 0xac(%rsp), %eax
addq $0xb0, %rsp
popq %rbx
retq
nopl (%rax,%rax)