// File: /workspace/github_cpp_makefile_star2_O3/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, 0x60(%rsp)
movsd 0x30(%rsi), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %rdi, 0x40(%rsp)
movl 0x4(%rdi), %ecx
movq %rcx, 0x70(%rsp)
movsd 0x8(%rsi), %xmm0
movsd %xmm0, 0x88(%rsp)
leaq (,%rax,4), %rdi
testq %rax, %rax
movq $-0x1, %r15
cmovsq %r15, %rdi
movq %rax, 0x18(%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 0x60(%rsp), %xmm2
movq %rax, 0x48(%rsp)
xorpd %xmm0, %xmm0
cmpl $0xd, %ebp
je 0xc73f
movsd 0x24f5(%rip), %xmm0     # 0xec30
divsd %xmm2, %xmm0
movsd %xmm0, 0x30(%rsp)
je 0xc74f
movsd 0x18e1(%rip), %xmm2     # 0xe030
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x18(%rsp), %r15
testq %r15, %r15
movq 0x70(%rsp), %rbp
movapd %xmm2, 0x60(%rsp)
jle 0xc785
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x20c0
movapd 0x60(%rsp), %xmm2
testl %ebp, %ebp
jle 0xc7a1
leaq (,%rbp,8), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x20c0
movapd 0x60(%rsp), %xmm2
testl %r15d, %r15d
movq 0x48(%rsp), %r8
jle 0xc828
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
xorl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
movl (%rdx), %esi
cmpl $-0x1, %esi
je 0xc815
addq $0x10, %rdx
xorpd %xmm0, %xmm0
movq %rdx, %rdi
movsd -0x8(%rdi), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
cmpl $-0x1, (%rdi)
leaq 0x10(%rdi), %rdi
jne 0xc7cc
movsd %xmm0, (%r8,%rcx,8)
movsd (%r14,%rcx,8), %xmm0
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 0xc7ee
jmp 0xc81d
movq $0x0, (%r8,%rcx,8)
movl %ecx, (%rbx,%rcx,4)
incq %rcx
cmpq %r15, %rcx
jne 0xc7b6
movapd 0x2450(%rip), %xmm0     # 0xec80
xorpd %xmm2, %xmm0
movapd %xmm0, 0x90(%rsp)
movsd 0x17fa(%rip), %xmm15    # 0xe040
movsd 0x17e2(%rip), %xmm0     # 0xe030
xorl %r13d, %r13d
movl %r15d, %ebp
movapd %xmm0, 0x20(%rsp)
movq %r14, 0x80(%rsp)
movl %r13d, 0x5c(%rsp)
movl %ebp, %r15d
testl %ebp, %ebp
jle 0xcb1c
movsd %xmm15, 0x78(%rsp)
movl %ebp, %r13d
xorl %r14d, %r14d
callq 0x2090
cltd
idivl %r13d
movslq %edx, %rax
addq %r14, %rax
movl (%rbx,%r14,4), %ecx
movl (%rbx,%rax,4), %edx
movl %edx, (%rbx,%r14,4)
movl %ecx, (%rbx,%rax,4)
incq %r14
decl %r13d
cmpq %r14, %r15
jne 0xc87f
testl %ebp, %ebp
movq 0x80(%rsp), %r14
movq 0x48(%rsp), %r13
jle 0xcb36
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movapd 0x20(%rsp), %xmm0
movapd 0x23ac(%rip), %xmm12    # 0xec80
xorpd %xmm12, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm1, 0x10(%rsp)
xorl %ecx, %ecx
movsd %xmm1, 0x8(%rsp)
movq 0x18(%rsp), %r15
movsd 0x38(%rsp), %xmm7
movsd 0x30(%rsp), %xmm8
movapd 0x60(%rsp), %xmm9
movapd 0x2363(%rip), %xmm10    # 0xec70
movapd 0x90(%rsp), %xmm11
xorpd %xmm13, %xmm13
movsd 0x232b(%rip), %xmm14    # 0xec50
movsd 0x78(%rsp), %xmm15
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 0xc96d
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 0xc94c
movsd (%r14,%rdi,8), %xmm2
movapd %xmm8, %xmm3
mulsd %xmm2, %xmm3
movq 0x50(%rsp), %r10
subsd (%r10,%rdi,8), %xmm3
addsd %xmm1, %xmm3
movsd (%r13,%rdi,8), %xmm4
addsd %xmm8, %xmm4
movapd %xmm7, %xmm1
addsd %xmm3, %xmm1
subsd %xmm7, %xmm3
ucomisd %xmm13, %xmm2
jne 0xc9be
jp 0xc9be
ucomisd %xmm1, %xmm13
jbe 0xc9d9
movapd %xmm1, %xmm5
xorpd %xmm12, %xmm5
jmp 0xca30
ucomisd %xmm9, %xmm2
jae 0xc9fc
ucomisd %xmm2, %xmm11
jae 0xca16
ucomisd %xmm13, %xmm2
jbe 0xca27
movapd %xmm1, %xmm5
jmp 0xca2b
ucomisd %xmm13, %xmm3
movapd %xmm3, %xmm5
ja 0xca30
ucomisd 0x20(%rsp), %xmm1
xorpd %xmm5, %xmm5
jbe 0xca30
ucomisd %xmm3, %xmm0
ja 0xcaf8
jmp 0xca30
ucomisd %xmm13, %xmm1
movapd %xmm1, %xmm5
ja 0xca30
xorpd %xmm5, %xmm5
ucomisd %xmm1, %xmm0
jbe 0xca30
jmp 0xcaf8
ucomisd %xmm3, %xmm13
jbe 0xcae8
movapd %xmm3, %xmm5
jmp 0xc9b7
movapd %xmm3, %xmm5
andpd %xmm10, %xmm5
movapd %xmm2, %xmm6
mulsd %xmm4, %xmm6
ucomisd %xmm1, %xmm6
jbe 0xca49
xorpd %xmm12, %xmm1
divsd %xmm4, %xmm1
jmp 0xca67
ucomisd %xmm6, %xmm3
jbe 0xca5e
xorpd %xmm12, %xmm3
divsd %xmm4, %xmm3
movapd %xmm3, %xmm1
jmp 0xca67
movapd %xmm2, %xmm1
xorpd %xmm12, %xmm1
movsd 0x10(%rsp), %xmm3
maxsd %xmm5, %xmm3
movsd %xmm3, 0x10(%rsp)
movsd 0x8(%rsp), %xmm3
addsd %xmm5, %xmm3
movsd %xmm3, 0x8(%rsp)
movapd %xmm1, %xmm3
andpd %xmm10, %xmm3
ucomisd %xmm3, %xmm14
ja 0xcb10
addsd %xmm2, %xmm1
maxsd %xmm11, %xmm1
minsd %xmm9, %xmm1
movsd %xmm1, (%r14,%rdi,8)
subsd %xmm2, %xmm1
ucomisd %xmm13, %xmm1
jne 0xcab8
jnp 0xcb10
cmpl $-0x1, %esi
je 0xcb10
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 0xcac1
jmp 0xcb10
xorpd %xmm5, %xmm5
ucomisd 0x20(%rsp), %xmm3
jbe 0xca30
movslq %ebp, %rcx
decl %ebp
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 %ebp, %ecx
jl 0xc92c
jmp 0xcb55
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
movl %r15d, %ebp
movq 0x18(%rsp), %r15
jmp 0xcb55
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movsd %xmm0, 0x10(%rsp)
movl %r15d, %ebp
movq 0x18(%rsp), %r15
movsd 0x78(%rsp), %xmm15
movsd 0x8(%rsp), %xmm1
movapd %xmm1, %xmm2
movl 0x5c(%rsp), %r13d
testl %r13d, %r13d
je 0xcb6e
movapd %xmm15, %xmm2
incl %r13d
imull $0xcccccccd, %r13d, %eax # imm = 0xCCCCCCCD
rorl %eax
cmpl $0x19999999, %eax       # imm = 0x19999999
ja 0xcba1
leaq 0x2410(%rip), %rdi      # 0xef98
xorl %eax, %eax
movsd %xmm2, 0x20(%rsp)
callq 0x5d62
movsd 0x20(%rsp), %xmm2
movsd 0x8(%rsp), %xmm1
movsd 0x88(%rsp), %xmm0
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jae 0xcbbc
movsd 0x10(%rsp), %xmm0
jmp 0xcbe6
cmpl %r15d, %ebp
je 0xcbfe
leaq 0x23d2(%rip), %rdi      # 0xef9a
xorl %eax, %eax
movsd %xmm2, 0x20(%rsp)
callq 0x5d62
movsd 0x20(%rsp), %xmm2
movsd 0x144d(%rip), %xmm0     # 0xe030
movl %r15d, %ebp
movapd %xmm0, 0x20(%rsp)
movapd %xmm2, %xmm15
cmpl $0x12c, %r13d           # imm = 0x12C
jne 0xc862
leaq 0x2397(%rip), %rdi      # 0xef9c
movl %r13d, %esi
xorl %r13d, %r13d
movl %esi, %ebp
xorl %eax, %eax
callq 0x5d62
movq 0x70(%rsp), %rcx
xorpd %xmm0, %xmm0
testl %ecx, %ecx
jle 0xcc54
xorl %eax, %eax
movsd 0x38(%rsp), %xmm5
movsd 0x30(%rsp), %xmm6
movq 0x50(%rsp), %rdx
movsd (%r12,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
cmpq %rax, %rcx
jne 0xcc34
mulsd 0x1fde(%rip), %xmm0     # 0xec30
jmp 0xcc65
movsd 0x38(%rsp), %xmm5
movsd 0x30(%rsp), %xmm6
movq 0x50(%rsp), %rdx
movapd 0x2003(%rip), %xmm7     # 0xec70
testl %r15d, %r15d
jle 0xcccb
mulsd 0x1fb6(%rip), %xmm6     # 0xec30
xorl %eax, %eax
xorpd %xmm1, %xmm1
xorl %r13d, %r13d
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, %r15
jne 0xcc83
leaq 0x231b(%rip), %rdi      # 0xefed
movb $0x1, %al
callq 0x5d62
leaq 0x2324(%rip), %rdi      # 0xf004
movl %r13d, %esi
xorl %eax, %eax
callq 0x5d62
movq %r14, %rdi
callq 0x21e0
movq 0x48(%rsp), %rdi
callq 0x21e0
movq %rbx, %rdi
callq 0x21e0
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq