// File: /workspace/github_c_makefile_star2_O0/sharpyfox[P]citrusleaf-client/src/cl_batch.c
// Function: batch_compile
static int
batch_compile(uint info1, uint info2, char *ns, cf_digest *digests, cl_cluster_node **nodes, int n_digests, cl_cluster_node *my_node, int n_my_digests, 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)
{
	// I hate strlen
	int		ns_len = ns ? strlen(ns) : 0;
	int		i;
	
	// determine the size
	size_t	msg_sz = sizeof(as_msg); // header
	// fields
	if (ns) msg_sz += ns_len + sizeof(cl_msg_field);
	msg_sz += sizeof(cl_msg_field) + 1 + (sizeof(cf_digest) * n_my_digests);
	// ops
	for (i=0;i<n_values;i++) {
		msg_sz += sizeof(cl_msg_op) + strlen(values[i].bin_name);

        if (0 != cl_value_to_op_get_size(&values[i], &msg_sz)) {
            cf_error("illegal parameter: bad type %d write op %d", values[i].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->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 - currently always 2, the digest array and the ns
	int n_fields = 2;
	buf = cl_write_header(buf, msg_sz, info1, info2, 0, generation, record_ttl, transaction_ttl, n_fields, n_values);
		
	// now the fields
	buf = write_fields_batch_digests(buf, ns, ns_len, digests, nodes, n_digests,n_my_digests, my_node);
	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, 0, op);
			}else{
				cl_value_to_op(0,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 $0xa0, %rsp
movq 0xf0(%rsp), %rax
movq 0xe8(%rsp), %rax
movq 0xe0(%rsp), %rax
movl 0xd8(%rsp), %eax
movq 0xd0(%rsp), %rax
movl 0xc8(%rsp), %eax
movq 0xc0(%rsp), %rax
movl 0xb8(%rsp), %eax
movq 0xb0(%rsp), %rax
movl %edi, 0x98(%rsp)
movl %esi, 0x94(%rsp)
movq %rdx, 0x88(%rsp)
movq %rcx, 0x80(%rsp)
movq %r8, 0x78(%rsp)
movl %r9d, 0x74(%rsp)
cmpq $0x0, 0x88(%rsp)
je 0xf454
movq 0x88(%rsp), %rdi
callq 0x2100
movq %rax, 0x28(%rsp)
jmp 0xf45d
xorl %eax, %eax
movq %rax, 0x28(%rsp)
jmp 0xf45d
movq 0x28(%rsp), %rax
movl %eax, 0x70(%rsp)
movq $0x1e, 0x60(%rsp)
cmpq $0x0, 0x88(%rsp)
je 0xf48d
movslq 0x70(%rsp), %rax
addq $0x5, %rax
addq 0x60(%rsp), %rax
movq %rax, 0x60(%rsp)
movslq 0xb8(%rsp), %rax
imulq $0x14, %rax, %rax
addq $0x6, %rax
addq 0x60(%rsp), %rax
movq %rax, 0x60(%rsp)
movl $0x0, 0x6c(%rsp)
movl 0x6c(%rsp), %eax
cmpl 0xd8(%rsp), %eax
jge 0xf571
movq 0xc0(%rsp), %rdi
movslq 0x6c(%rsp), %rax
shlq $0x6, %rax
addq %rax, %rdi
callq 0x2100
addq $0x8, %rax
addq 0x60(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0xc0(%rsp), %rdi
movslq 0x6c(%rsp), %rax
shlq $0x6, %rax
addq %rax, %rdi
leaq 0x60(%rsp), %rsi
callq 0x5b10
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0xf55f
leaq 0xedc4(%rip), %rax      # 0x1e2d8
movl (%rax), %ecx
xorl %eax, %eax
cmpl %ecx, %eax
jg 0xf54f
leaq 0xedbd(%rip), %rax      # 0x1e2e0
movq (%rax), %r8
movq 0xc0(%rsp), %rax
movslq 0x6c(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movl 0x20(%rax), %edx
movl 0x6c(%rsp), %ecx
xorl %edi, %edi
leaq 0x9362(%rip), %rsi      # 0x188ac
movb $0x0, %al
callq *%r8
movl $0xffffffff, 0x9c(%rsp) # imm = 0xFFFFFFFF
jmp 0xf8c4
jmp 0xf561
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0xf4af
movq $0x0, 0x50(%rsp)
movq 0xe0(%rsp), %rax
cmpq $0x0, (%rax)
je 0xf5d8
movq 0x60(%rsp), %rax
movq 0xe8(%rsp), %rcx
cmpq (%rcx), %rax
jbe 0xf5d8
movq 0x60(%rsp), %rdi
callq 0x2310
movq %rax, 0x58(%rsp)
movq %rax, 0x50(%rsp)
cmpq $0x0, 0x58(%rsp)
jne 0xf5c6
movl $0xffffffff, 0x9c(%rsp) # imm = 0xFFFFFFFF
jmp 0xf8c4
movq 0x58(%rsp), %rcx
movq 0xe0(%rsp), %rax
movq %rcx, (%rax)
jmp 0xf5e8
movq 0xe0(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x58(%rsp)
movq 0x60(%rsp), %rcx
movq 0xe8(%rsp), %rax
movq %rcx, (%rax)
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rdx
xorl %esi, %esi
callq 0x2170
movl $0x0, 0x4c(%rsp)
cmpq $0x0, 0xf0(%rsp)
je 0xf6d9
movq 0xf0(%rsp), %rax
testb $0x1, (%rax)
je 0xf643
movl 0x94(%rsp), %eax
orl $0x20, %eax
movl %eax, 0x94(%rsp)
jmp 0xf6d7
movq 0xf0(%rsp), %rax
testb $0x1, 0x2(%rax)
je 0xf673
movl 0x94(%rsp), %eax
orl $0x4, %eax
movl %eax, 0x94(%rsp)
movq 0xf0(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x4c(%rsp)
jmp 0xf6d5
movq 0xf0(%rsp), %rax
testb $0x1, 0x3(%rax)
je 0xf6a3
movl 0x94(%rsp), %eax
orl $0x8, %eax
movl %eax, 0x94(%rsp)
movq 0xf0(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x4c(%rsp)
jmp 0xf6d3
movq 0xf0(%rsp), %rax
testb $0x1, 0x4(%rax)
je 0xf6d1
movl 0x94(%rsp), %eax
orl $0x10, %eax
movl %eax, 0x94(%rsp)
movq 0xf0(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x4c(%rsp)
jmp 0xf6d3
jmp 0xf6d5
jmp 0xf6d7
jmp 0xf6d9
cmpq $0x0, 0xf0(%rsp)
je 0xf6f5
movq 0xf0(%rsp), %rax
movl 0x10(%rax), %eax
movl %eax, 0x24(%rsp)
jmp 0xf6fd
xorl %eax, %eax
movl %eax, 0x24(%rsp)
jmp 0xf6fd
movl 0x24(%rsp), %eax
movl %eax, 0x48(%rsp)
cmpq $0x0, 0xf0(%rsp)
je 0xf721
movq 0xf0(%rsp), %rax
movl 0xc(%rax), %eax
movl %eax, 0x20(%rsp)
jmp 0xf729
xorl %eax, %eax
movl %eax, 0x20(%rsp)
jmp 0xf729
movl 0x20(%rsp), %eax
movl %eax, 0x44(%rsp)
movl $0x2, 0x40(%rsp)
movq 0x58(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x98(%rsp), %edx
movl 0x94(%rsp), %ecx
movl 0x4c(%rsp), %r9d
movl 0x48(%rsp), %ebx
movl 0x44(%rsp), %r11d
movl 0x40(%rsp), %r10d
movl 0xd8(%rsp), %eax
xorl %r8d, %r8d
movl %ebx, (%rsp)
movl %r11d, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x5a00
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rdi
movq 0x88(%rsp), %rsi
movl 0x70(%rsp), %edx
movq 0x80(%rsp), %rcx
movq 0x78(%rsp), %r8
movl 0x74(%rsp), %r9d
movl 0xb8(%rsp), %r10d
movq 0xb0(%rsp), %rax
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xfb00
movq %rax, 0x58(%rsp)
cmpq $0x0, 0x58(%rsp)
jne 0xf7f9
cmpq $0x0, 0x50(%rsp)
je 0xf7e9
movq 0x50(%rsp), %rdi
callq 0x22e0
movl $0xffffffff, 0x9c(%rsp) # imm = 0xFFFFFFFF
jmp 0xf8c4
cmpl $0x0, 0xd8(%rsp)
je 0xf8b9
movq 0x58(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x6c(%rsp)
movl 0x6c(%rsp), %eax
cmpl 0xd8(%rsp), %eax
jge 0xf8b7
cmpq $0x0, 0xc0(%rsp)
je 0xf860
movq 0xc0(%rsp), %rdi
movslq 0x6c(%rsp), %rax
shlq $0x6, %rax
addq %rax, %rdi
movl 0xc8(%rsp), %esi
movq 0x38(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x5bf0
jmp 0xf884
movq 0xd0(%rsp), %rdx
movslq 0x6c(%rsp), %rax
imulq $0x48, %rax, %rax
addq %rax, %rdx
movq 0x38(%rsp), %rcx
xorl %eax, %eax
movl %eax, %edi
xorl %esi, %esi
callq 0x5bf0
movq 0x38(%rsp), %rdi
callq 0xfae0
movq %rax, 0x30(%rsp)
movq 0x38(%rsp), %rdi
callq 0x13b70
movq 0x30(%rsp), %rax
movq %rax, 0x38(%rsp)
movl 0x6c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x6c(%rsp)
jmp 0xf819
jmp 0xf8b9
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
addq $0xa0, %rsp
popq %rbx
retq
nopw %cs:(%rax,%rax)
nop