// File: /workspace/github_cpp_makefile_star2_O1/cjlin1[P]liblinear/linear.cpp
// Function: solve_l2r_l1l2_svr(problem const*, parameter const*, double*, int)
static int solve_l2r_l1l2_svr(const problem *prob, const parameter *param, double *w, int max_iter=300)
{
	const int solver_type = param->solver_type;
	int l = prob->l;
	double C = param->C;
	double p = param->p;
	int w_size = prob->n;
	double eps = param->eps;
	int i, s, iter = 0;
	int active_size = l;
	int *index = new int[l];

	double d, G, H;
	double Gmax_old = INF;
	double Gmax_new, Gnorm1_new;
	double Gnorm1_init = -1.0; // Gnorm1_init is initialized at the first iteration
	double *beta = new double[l];
	double *QD = new double[l];
	double *y = prob->y;

	// L2R_L2LOSS_SVR_DUAL
	double lambda[1], upper_bound[1];
	lambda[0] = 0.5/C;
	upper_bound[0] = INF;

	if(solver_type == L2R_L1LOSS_SVR_DUAL)
	{
		lambda[0] = 0;
		upper_bound[0] = C;
	}

	// Initial beta can be set here. Note that
	// -upper_bound <= beta[i] <= upper_bound
	for(i=0; i<l; i++)
		beta[i] = 0;

	for(i=0; i<w_size; i++)
		w[i] = 0;
	for(i=0; i<l; i++)
	{
		feature_node * const xi = prob->x[i];
		QD[i] = sparse_operator::nrm2_sq(xi);
		sparse_operator::axpy(beta[i], xi, w);

		index[i] = i;
	}


	while(iter < max_iter)
	{
		Gmax_new = 0;
		Gnorm1_new = 0;

		for(i=0; i<active_size; i++)
		{
			int j = i+rand()%(active_size-i);
			swap(index[i], index[j]);
		}

		for(s=0; s<active_size; s++)
		{
			i = index[s];
			G = -y[i] + lambda[GETI(i)]*beta[i];
			H = QD[i] + lambda[GETI(i)];

			feature_node * const xi = prob->x[i];
			G += sparse_operator::dot(w, xi);

			double Gp = G+p;
			double Gn = G-p;
			double violation = 0;
			if(beta[i] == 0)
			{
				if(Gp < 0)
					violation = -Gp;
				else if(Gn > 0)
					violation = Gn;
				else if(Gp>Gmax_old && Gn<-Gmax_old)
				{
					active_size--;
					swap(index[s], index[active_size]);
					s--;
					continue;
				}
			}
			else if(beta[i] >= upper_bound[GETI(i)])
			{
				if(Gp > 0)
					violation = Gp;
				else if(Gp < -Gmax_old)
				{
					active_size--;
					swap(index[s], index[active_size]);
					s--;
					continue;
				}
			}
			else if(beta[i] <= -upper_bound[GETI(i)])
			{
				if(Gn < 0)
					violation = -Gn;
				else if(Gn > Gmax_old)
				{
					active_size--;
					swap(index[s], index[active_size]);
					s--;
					continue;
				}
			}
			else if(beta[i] > 0)
				violation = fabs(Gp);
			else
				violation = fabs(Gn);

			Gmax_new = max(Gmax_new, violation);
			Gnorm1_new += violation;

			// obtain Newton direction d
			if(Gp < H*beta[i])
				d = -Gp/H;
			else if(Gn > H*beta[i])
				d = -Gn/H;
			else
				d = -beta[i];

			if(fabs(d) < 1.0e-12)
				continue;

			double beta_old = beta[i];
			beta[i] = min(max(beta[i]+d, -upper_bound[GETI(i)]), upper_bound[GETI(i)]);
			d = beta[i]-beta_old;

			if(d != 0)
				sparse_operator::axpy(d, xi, w);
		}

		if(iter == 0)
			Gnorm1_init = Gnorm1_new;
		iter++;
		if(iter % 10 == 0)
			info(".");

		if(Gnorm1_new <= eps*Gnorm1_init)
		{
			if(active_size == l)
				break;
			else
			{
				active_size = l;
				info("*");
				Gmax_old = INF;
				continue;
			}
		}

		Gmax_old = Gmax_new;
	}

	info("\noptimization finished, #iter = %d\n", iter);

	// calculate objective value
	double v = 0;
	int nSV = 0;
	for(i=0; i<w_size; i++)
		v += w[i]*w[i];
	v = 0.5*v;
	for(i=0; i<l; i++)
	{
		v += p*fabs(beta[i]) - y[i]*beta[i] + 0.5*lambda[GETI(i)]*beta[i]*beta[i];
		if(beta[i] != 0)
			nSV++;
	}

	info("Objective value = %lf\n", v);
	info("nSV = %d\n",nSV);

	delete [] beta;
	delete [] QD;
	delete [] index;

	return iter;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdx, %r12
movl (%rsi), %ebp
movslq (%rdi), %rax
movsd 0x10(%rsi), %xmm0
movaps %xmm0, 0x40(%rsp)
movsd 0x30(%rsi), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rdi, 0x30(%rsp)
movl 0x4(%rdi), %ecx
movq %rcx, 0x58(%rsp)
movsd 0x8(%rsi), %xmm0
movsd %xmm0, 0x70(%rsp)
leaq (,%rax,4), %rdi
testq %rax, %rax
movq $-0x1, %r15
cmovsq %r15, %rdi
movq %rax, 0x38(%rsp)
leaq (,%rax,8), %r13
cmovnsq %r13, %r15
callq 0x2030
movq %rax, %rbx
movq %r15, %rdi
callq 0x2030
movq %rax, %r14
movq %r15, %rdi
callq 0x2030
movapd 0x40(%rsp), %xmm2
movq %rax, %r15
xorpd %xmm0, %xmm0
cmpl $0xd, %ebp
je 0xbc19
movsd 0x1ff3(%rip), %xmm0     # 0xdc08
divsd %xmm2, %xmm0
je 0xbc23
movsd 0x13e5(%rip), %xmm2     # 0xd008
movq 0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x60(%rsp)
movq 0x38(%rsp), %rbp
testq %rbp, %rbp
movsd %xmm0, 0x20(%rsp)
movapd %xmm2, 0x40(%rsp)
jle 0xbc5a
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x20c0
movapd 0x40(%rsp), %xmm2
movq 0x58(%rsp), %rax
testl %eax, %eax
jle 0xbc7b
leaq (,%rax,8), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x20c0
movapd 0x40(%rsp), %xmm2
testl %ebp, %ebp
jle 0xbcfe
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movl (%rdx), %esi
cmpl $-0x1, %esi
je 0xbcb5
leaq 0x10(%rdx), %rdi
xorpd %xmm0, %xmm0
movsd -0x8(%rdi), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
cmpl $-0x1, (%rdi)
leaq 0x10(%rdi), %rdi
jne 0xbc9d
jmp 0xbcb9
xorpd %xmm0, %xmm0
movsd %xmm0, (%r15,%rcx,8)
cmpl $-0x1, %esi
je 0xbcf3
movsd (%r14,%rcx,8), %xmm0
addq $0x10, %rdx
movslq %esi, %rsi
movsd -0x8(%rdx), %xmm1
mulsd %xmm0, %xmm1
addsd -0x8(%r12,%rsi,8), %xmm1
movsd %xmm1, -0x8(%r12,%rsi,8)
movl (%rdx), %esi
addq $0x10, %rdx
cmpl $-0x1, %esi
jne 0xbcce
movl %ecx, (%rbx,%rcx,4)
incq %rcx
cmpq %rbp, %rcx
jne 0xbc8a
movapd 0x1f49(%rip), %xmm11    # 0xdc50
xorpd %xmm2, %xmm11
movsd 0x1304(%rip), %xmm1     # 0xd018
movsd 0x12ec(%rip), %xmm0     # 0xd008
xorl %esi, %esi
movl %ebp, %r13d
movq %r15, 0x68(%rsp)
movapd %xmm11, 0x80(%rsp)
movapd %xmm0, 0x90(%rsp)
movsd %xmm1, 0x78(%rsp)
movl %esi, 0x8(%rsp)
testl %r13d, %r13d
jle 0xbd70
movl %r13d, %r15d
xorl %ebp, %ebp
callq 0x2090
cltd
idivl %r15d
movslq %edx, %rax
addq %rbp, %rax
movl (%rbx,%rbp,4), %ecx
movl (%rbx,%rax,4), %edx
movl %edx, (%rbx,%rbp,4)
movl %ecx, (%rbx,%rax,4)
incq %rbp
decq %r15
jne 0xbd4d
testl %r13d, %r13d
jle 0xbfda
movq 0x30(%rsp), %rax
movq 0x10(%rax), %rax
movapd 0x90(%rsp), %xmm15
movapd %xmm15, %xmm0
movapd 0x1eb6(%rip), %xmm12    # 0xdc50
xorpd %xmm12, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm1, 0x18(%rsp)
xorl %ecx, %ecx
movsd %xmm1, 0x10(%rsp)
movq 0x68(%rsp), %r15
movsd 0x28(%rsp), %xmm7
movsd 0x20(%rsp), %xmm8
movq 0x60(%rsp), %rbp
movapd 0x40(%rsp), %xmm9
movapd 0x1e68(%rip), %xmm10    # 0xdc40
movapd 0x80(%rsp), %xmm11
xorpd %xmm13, %xmm13
movsd 0x1e38(%rip), %xmm14    # 0xdc28
movslq %ecx, %r8
movl (%rbx,%r8,4), %r9d
movslq %r9d, %rdi
movq (%rax,%rdi,8), %rdx
movl (%rdx), %esi
xorpd %xmm1, %xmm1
cmpl $-0x1, %esi
je 0xbe31
leaq 0x10(%rdx), %r10
movl %esi, %r11d
movslq %r11d, %r11
movsd -0x8(%r12,%r11,8), %xmm2
mulsd -0x8(%r10), %xmm2
addsd %xmm2, %xmm1
movl (%r10), %r11d
addq $0x10, %r10
cmpl $-0x1, %r11d
jne 0xbe10
movsd (%r14,%rdi,8), %xmm2
movapd %xmm8, %xmm3
mulsd %xmm2, %xmm3
subsd (%rbp,%rdi,8), %xmm3
addsd %xmm1, %xmm3
movsd (%r15,%rdi,8), %xmm4
addsd %xmm8, %xmm4
movapd %xmm7, %xmm1
addsd %xmm3, %xmm1
subsd %xmm7, %xmm3
ucomisd %xmm13, %xmm2
jne 0xbe7c
jp 0xbe7c
ucomisd %xmm1, %xmm13
jbe 0xbe97
movapd %xmm1, %xmm5
xorpd %xmm12, %xmm5
jmp 0xbeed
ucomisd %xmm9, %xmm2
jae 0xbeb9
ucomisd %xmm2, %xmm11
jae 0xbed3
ucomisd %xmm13, %xmm2
jbe 0xbee4
movapd %xmm1, %xmm5
jmp 0xbee8
ucomisd %xmm13, %xmm3
movapd %xmm3, %xmm5
ja 0xbeed
ucomisd %xmm15, %xmm1
xorpd %xmm5, %xmm5
jbe 0xbeed
ucomisd %xmm3, %xmm0
ja 0xbfb4
jmp 0xbeed
ucomisd %xmm13, %xmm1
movapd %xmm1, %xmm5
ja 0xbeed
xorpd %xmm5, %xmm5
ucomisd %xmm1, %xmm0
jbe 0xbeed
jmp 0xbfb4
ucomisd %xmm3, %xmm13
jbe 0xbfa5
movapd %xmm3, %xmm5
jmp 0xbe75
movapd %xmm3, %xmm5
andpd %xmm10, %xmm5
movapd %xmm2, %xmm6
mulsd %xmm4, %xmm6
ucomisd %xmm1, %xmm6
jbe 0xbf06
xorpd %xmm12, %xmm1
divsd %xmm4, %xmm1
jmp 0xbf24
ucomisd %xmm6, %xmm3
jbe 0xbf1b
xorpd %xmm12, %xmm3
divsd %xmm4, %xmm3
movapd %xmm3, %xmm1
jmp 0xbf24
movapd %xmm2, %xmm1
xorpd %xmm12, %xmm1
movsd 0x18(%rsp), %xmm3
maxsd %xmm5, %xmm3
movsd %xmm3, 0x18(%rsp)
movsd 0x10(%rsp), %xmm3
addsd %xmm5, %xmm3
movsd %xmm3, 0x10(%rsp)
movapd %xmm1, %xmm3
andpd %xmm10, %xmm3
ucomisd %xmm3, %xmm14
ja 0xbfcd
addsd %xmm2, %xmm1
maxsd %xmm11, %xmm1
minsd %xmm9, %xmm1
movsd %xmm1, (%r14,%rdi,8)
subsd %xmm2, %xmm1
ucomisd %xmm13, %xmm1
jne 0xbf75
jnp 0xbfcd
cmpl $-0x1, %esi
je 0xbfcd
addq $0x10, %rdx
movslq %esi, %rsi
movsd -0x8(%rdx), %xmm2
mulsd %xmm1, %xmm2
addsd -0x8(%r12,%rsi,8), %xmm2
movsd %xmm2, -0x8(%r12,%rsi,8)
movl (%rdx), %esi
addq $0x10, %rdx
cmpl $-0x1, %esi
jne 0xbf7e
jmp 0xbfcd
xorpd %xmm5, %xmm5
ucomisd %xmm15, %xmm3
jbe 0xbeed
movslq %r13d, %rcx
decl %r13d
movl -0x4(%rbx,%rcx,4), %edx
movl %edx, (%rbx,%r8,4)
movl %r9d, -0x4(%rbx,%rcx,4)
decl %r8d
movl %r8d, %ecx
incl %ecx
cmpl %r13d, %ecx
jl 0xbdf0
jmp 0xbfef
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd %xmm0, 0x18(%rsp)
movq 0x68(%rsp), %r15
movsd 0x10(%rsp), %xmm1
movapd %xmm1, %xmm2
movl 0x8(%rsp), %esi
testl %esi, %esi
movq 0x38(%rsp), %rbp
je 0xc00c
movsd 0x78(%rsp), %xmm2
incl %esi
imull $0xcccccccd, %esi, %eax # imm = 0xCCCCCCCD
rorl %eax
cmpl $0x19999999, %eax       # imm = 0x19999999
ja 0xc046
leaq 0x1ec4(%rip), %rdi      # 0xdee8
xorl %eax, %eax
movl %esi, %ebp
movsd %xmm2, 0x8(%rsp)
callq 0x5ab4
movsd 0x8(%rsp), %xmm2
movsd 0x10(%rsp), %xmm1
movl %ebp, %esi
movq 0x38(%rsp), %rbp
movsd 0x70(%rsp), %xmm0
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jae 0xc05e
movsd 0x18(%rsp), %xmm0
jmp 0xc08f
cmpl %ebp, %r13d
je 0xc0a4
leaq 0x1e80(%rip), %rdi      # 0xdeea
xorl %eax, %eax
movq %rbp, %r13
movl %esi, %ebp
movsd %xmm2, 0x8(%rsp)
callq 0x5ab4
movsd 0x8(%rsp), %xmm2
movl %ebp, %esi
movq %r13, %rbp
movsd 0xf79(%rip), %xmm0      # 0xd008
movapd %xmm2, %xmm1
cmpl $0x12c, %esi            # imm = 0x12C
jne 0xbd30
movl $0x12c, %esi            # imm = 0x12C
leaq 0x1e41(%rip), %rdi      # 0xdeec
xorl %r13d, %r13d
movl %esi, 0x8(%rsp)
xorl %eax, %eax
callq 0x5ab4
movq 0x58(%rsp), %rcx
xorpd %xmm0, %xmm0
testl %ecx, %ecx
jle 0xc0f4
xorl %eax, %eax
movsd 0x28(%rsp), %xmm5
movsd 0x20(%rsp), %xmm6
movsd (%r12,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
cmpq %rax, %rcx
jne 0xc0d4
mulsd 0x1b16(%rip), %xmm0     # 0xdc08
jmp 0xc100
movsd 0x28(%rsp), %xmm5
movsd 0x20(%rsp), %xmm6
movapd 0x1b38(%rip), %xmm7     # 0xdc40
testl %ebp, %ebp
jle 0xc16a
mulsd 0x1af4(%rip), %xmm6     # 0xdc08
xorl %eax, %eax
xorpd %xmm1, %xmm1
xorl %r13d, %r13d
movq 0x60(%rsp), %rdx
movsd (%r14,%rax,8), %xmm2
movapd %xmm2, %xmm3
andpd %xmm7, %xmm3
movsd (%rdx,%rax,8), %xmm4
mulsd %xmm2, %xmm4
mulsd %xmm5, %xmm3
subsd %xmm4, %xmm3
movapd %xmm6, %xmm4
mulsd %xmm2, %xmm4
mulsd %xmm2, %xmm4
addsd %xmm3, %xmm4
addsd %xmm4, %xmm0
cmpneqsd %xmm1, %xmm2
movq %xmm2, %rcx
subl %ecx, %r13d
incq %rax
cmpq %rax, %rbp
jne 0xc122
leaq 0x1dcc(%rip), %rdi      # 0xdf3d
movb $0x1, %al
callq 0x5ab4
leaq 0x1dd5(%rip), %rdi      # 0xdf54
movl %r13d, %esi
xorl %eax, %eax
callq 0x5ab4
movq %r14, %rdi
callq 0x21e0
movq %r15, %rdi
callq 0x21e0
movq %rbx, %rdi
callq 0x21e0
movl 0x8(%rsp), %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq