// File: qmmlib[P]QmmLibrary/linear.cpp
// Function: mmcd_obj(problem const*, parameter const*, double*, double*, signed char*, double*, int*)
static double mmcd_obj(const problem *prob_col,const parameter *param,double *w, double *z, schar *y, double *C, int *nnzp) {

	loss_var loss_type = param->loss_type;
	double loss_param = param->loss_param;
	double reg_param = param->reg_param;
	int l = prob_col->l;  // N in paper
	int w_size = prob_col->n;  // M in paper

	double v = 0;
	int nnz = 0;
	int j;

	for(j=0; j<w_size; j++)
	{
		//x = prob_col->x[j];
		//while(x->index != -1)
		//{
		//	x->value *= prob_col->y[x->index-1]; // restore x->value
		//	x++;
		//}
		if(w[j] != 0)
		{
			v += (1-reg_param)*fabs(w[j]) + reg_param * 0.5 *w[j]*w[j];
			nnz++;
		}
	}
	if (loss_type == L2) {
		for(j=0; j<l; j++)
			if(z[j] < 1)
				v += C[GETI(j)]*(1-z[j])*(1-z[j]);
	} else if (loss_type == L1) {
		for(j=0; j<l; j++)
			if(z[j] < 1)
				v += C[GETI(j)]*(1-z[j]);
	} else if (loss_type == HU1) {
		for(j=0; j<l; j++)
			if(z[j] < 1-loss_param)
				v += C[GETI(j)]*(1-z[j]);
			else if (z[j] < 1 + loss_param)
				v += C[GETI(j)]*1/(4*loss_param)*(z[j]-1-loss_param)*(z[j]-1-loss_param);
	} else if (loss_type == HU2) {
		for(j=0; j<l; j++)
			if(z[j] < 1-loss_param)
				v += C[GETI(j)]*(1-z[j]-loss_param/2);
			else if (z[j] < 1)
				v += C[GETI(j)]*1/(2*loss_param)*(z[j]-1)*(z[j]-1);
	} else if (loss_type == LOG) {
		for(j=0; j<l; j++)
			v += C[GETI(j)]*log(1+exp(-z[j]));
	} else if (loss_type == LS) {
		for(j=0; j<l; j++)
			v += C[GETI(j)]*(1-z[j])*(1-z[j]);
	}
	*nnzp = nnz;
	return v;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x10(%rbp), %rax
movsd 0x20(%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x50(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x50(%rbp), %eax
jge 0x1ef80
movq -0x18(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1ef09
jp 0x1ef09
jmp 0x1ef70
movsd 0x5117(%rip), %xmm0     # 0x24028
subsd -0x48(%rbp), %xmm0
movq -0x18(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movaps 0x61f6(%rip), %xmm1     # 0x25120
pand %xmm1, %xmm2
movsd 0x50ea(%rip), %xmm1     # 0x24020
mulsd -0x48(%rbp), %xmm1
movq -0x18(%rbp), %rax
movslq -0x60(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm1
movq -0x18(%rbp), %rax
movslq -0x60(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1ef72
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1eee3
cmpl $0x1, -0x34(%rbp)
jne 0x1f024
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x1f01f
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd 0x507b(%rip), %xmm0     # 0x24028
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x1f00f
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x60(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd 0x5049(%rip), %xmm1     # 0x24028
subsd (%rax,%rcx,8), %xmm1
mulsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd 0x5030(%rip), %xmm2     # 0x24028
subsd (%rax,%rcx,8), %xmm2
movsd -0x58(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x1f011
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1ef91
jmp 0x1f457
cmpl $0x0, -0x34(%rbp)
jne 0x1f0a4
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x1f09f
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd 0x4fdf(%rip), %xmm0     # 0x24028
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x1f092
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x60(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd 0x4fad(%rip), %xmm2     # 0x24028
subsd (%rax,%rcx,8), %xmm2
movsd -0x58(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x1f094
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1f031
jmp 0x1f455
cmpl $0x3, -0x34(%rbp)
jne 0x1f1e9
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x1f1e4
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x4f52(%rip), %xmm0     # 0x24028
subsd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1f128
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x60(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd 0x4f1c(%rip), %xmm2     # 0x24028
subsd (%rax,%rcx,8), %xmm2
movsd -0x58(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x1f1d4
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x4eeb(%rip), %xmm0     # 0x24028
addsd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1f1d2
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x60(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd 0x4ebe(%rip), %xmm0     # 0x24028
mulsd (%rax,%rcx,8), %xmm0
movsd 0x5f69(%rip), %xmm1     # 0x250e0
mulsd -0x40(%rbp), %xmm1
divsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x4e93(%rip), %xmm2     # 0x24028
subsd %xmm2, %xmm1
subsd -0x40(%rbp), %xmm1
mulsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x4e71(%rip), %xmm1     # 0x24028
subsd %xmm1, %xmm2
subsd -0x40(%rbp), %xmm2
movsd -0x58(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x1f1d4
jmp 0x1f1d6
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1f0b5
jmp 0x1f453
cmpl $0x4, -0x34(%rbp)
jne 0x1f32c
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x1f327
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x4e0d(%rip), %xmm0     # 0x24028
subsd -0x40(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1f282
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x60(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd 0x4dd7(%rip), %xmm2     # 0x24028
subsd (%rax,%rcx,8), %xmm2
movsd -0x40(%rbp), %xmm1
movsd 0x6025(%rip), %xmm3     # 0x25288
divsd %xmm3, %xmm1
subsd %xmm1, %xmm2
movsd -0x58(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x1f317
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd 0x4d96(%rip), %xmm0     # 0x24028
ucomisd (%rax,%rcx,8), %xmm0
jbe 0x1f315
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x60(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd 0x4d71(%rip), %xmm0     # 0x24028
mulsd (%rax,%rcx,8), %xmm0
movsd 0x5fc4(%rip), %xmm1     # 0x25288
mulsd -0x40(%rbp), %xmm1
divsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd 0x4d46(%rip), %xmm2     # 0x24028
subsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd 0x4d29(%rip), %xmm1     # 0x24028
subsd %xmm1, %xmm2
movsd -0x58(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x1f317
jmp 0x1f319
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1f1fa
jmp 0x1f451
cmpl $0x2, -0x34(%rbp)
jne 0x1f3d0
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x1f3ce
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x60(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
callq 0x34d0
movaps %xmm0, %xmm1
movsd 0x4c8b(%rip), %xmm0     # 0x24028
addsd %xmm1, %xmm0
callq 0x3220
movaps %xmm0, %xmm2
movsd -0x68(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1f33d
jmp 0x1f44f
cmpl $0x5, -0x34(%rbp)
jne 0x1f44d
movl $0x0, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x1f44b
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq -0x60(%rbp), %rdx
movsbl (%rcx,%rdx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd 0x4c18(%rip), %xmm1     # 0x24028
subsd (%rax,%rcx,8), %xmm1
mulsd %xmm1, %xmm0
movq -0x20(%rbp), %rax
movslq -0x60(%rbp), %rcx
movsd 0x4bff(%rip), %xmm2     # 0x24028
subsd (%rax,%rcx,8), %xmm2
movsd -0x58(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x1f3dd
jmp 0x1f44d
jmp 0x1f44f
jmp 0x1f451
jmp 0x1f453
jmp 0x1f455
jmp 0x1f457
movl -0x5c(%rbp), %ecx
movq 0x10(%rbp), %rax
movl %ecx, (%rax)
movsd -0x58(%rbp), %xmm0
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax,%rax)