// File: /workspace/github_cpp_makefile_star2_O3/qmmlib[P]QmmLibrary/linear.cpp
// Function: solve_l2r_l1l2_svr(problem const*, double*, parameter const*, int)
static void solve_l2r_l1l2_svr(
	const problem *prob, double *w, const parameter *param,
	int 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 max_iter = 1000;
	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;
	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++)
	{
		QD[i] = 0;
		feature_node *xi = prob->x[i];
		while(xi->index != -1)
		{
			double val = xi->value;
			QD[i] += val*val;
			w[xi->index-1] += beta[i]*val;
			xi++;
		}

		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 *xi = prob->x[i];
			while(xi->index != -1)
			{
				int ind = xi->index-1;
				double val = xi->value;
				G += val*w[ind];
				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)
			{
				xi = prob->x[i];
				while(xi->index != -1)
				{
					w[xi->index-1] += d*xi->value;
					xi++;
				}
			}
		}

		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);
	if(iter >= max_iter)
		info("\nWARNING: reaching max number of iterations\nUsing -s 11 may be faster\n\n");

	// 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;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %ecx, (%rsp)
movq %rsi, %r12
movslq (%rdi), %r14
movsd 0x80(%rdx), %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x88(%rdx), %xmm0
movaps %xmm0, 0x40(%rsp)
movsd 0xa8(%rdx), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %rdi, 0x38(%rsp)
movl 0x4(%rdi), %eax
movq %rax, 0x50(%rsp)
leaq (,%r14,4), %rdi
testq %r14, %r14
movq $-0x1, %r15
cmovsq %r15, %rdi
leaq (,%r14,8), %rbp
cmovnsq %rbp, %r15
callq 0x3030
movq %rax, %rbx
movq %r15, %rdi
callq 0x3030
movq %rax, %r13
movq %r15, %rdi
callq 0x3030
movapd 0x40(%rsp), %xmm4
movq %rax, %r15
xorpd %xmm0, %xmm0
cmpl $0xd, (%rsp)
je 0x15872
movsd 0x3892(%rip), %xmm0     # 0x19100
divsd %xmm4, %xmm0
je 0x1587c
movsd 0x27b4(%rip), %xmm4     # 0x18030
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x58(%rsp)
testq %r14, %r14
movsd %xmm0, 0x28(%rsp)
movapd %xmm4, 0x40(%rsp)
jle 0x158ae
movq %r13, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x3110
movapd 0x40(%rsp), %xmm4
movq 0x50(%rsp), %rax
testl %eax, %eax
jle 0x158cf
leaq (,%rax,8), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x3110
movapd 0x40(%rsp), %xmm4
testl %r14d, %r14d
jle 0x15943
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
xorl %ecx, %ecx
movq $0x0, (%r15,%rcx,8)
movq (%rax,%rcx,8), %rdx
movl (%rdx), %esi
cmpl $-0x1, %esi
je 0x15938
movsd (%r13,%rcx,8), %xmm0
addq $0x10, %rdx
xorpd %xmm1, %xmm1
movsd -0x8(%rdx), %xmm2
movapd %xmm2, %xmm3
mulsd %xmm2, %xmm3
addsd %xmm3, %xmm1
movsd %xmm1, (%r15,%rcx,8)
movslq %esi, %rsi
mulsd %xmm0, %xmm2
addsd -0x8(%r12,%rsi,8), %xmm2
movsd %xmm2, -0x8(%r12,%rsi,8)
movl (%rdx), %esi
addq $0x10, %rdx
cmpl $-0x1, %esi
jne 0x15901
movl %ecx, (%rbx,%rcx,4)
incq %rcx
cmpq %r14, %rcx
jne 0x158df
movapd 0x37e5(%rip), %xmm0     # 0x19130
xorpd %xmm4, %xmm0
movapd %xmm0, 0x90(%rsp)
movsd 0x26d0(%rip), %xmm0     # 0x18030
xorl %eax, %eax
movq %r14, 0x60(%rsp)
movapd %xmm0, 0x10(%rsp)
movq %r13, 0x80(%rsp)
movq %r15, 0x68(%rsp)
movq %rax, 0x78(%rsp)
movl %r14d, %ebp
testl %r14d, %r14d
jle 0x15c29
movsd %xmm15, 0x70(%rsp)
movl %r14d, %r13d
xorl %r15d, %r15d
callq 0x30a0
cltd
idivl %r13d
movslq %edx, %rax
addq %r15, %rax
movl (%rbx,%r15,4), %ecx
movl (%rbx,%rax,4), %edx
movl %edx, (%rbx,%r15,4)
movl %ecx, (%rbx,%rax,4)
incq %r15
decl %r13d
cmpq %r15, %rbp
jne 0x15998
testl %r14d, %r14d
movq 0x80(%rsp), %r13
jle 0x15c3d
movq 0x38(%rsp), %rax
movq 0x10(%rax), %rax
movapd 0x10(%rsp), %xmm0
movapd 0x3747(%rip), %xmm12    # 0x19130
xorpd %xmm12, %xmm0
xorpd %xmm1, %xmm1
movsd %xmm1, 0x8(%rsp)
xorl %ecx, %ecx
movsd %xmm1, (%rsp)
movq 0x68(%rsp), %r15
movsd 0x30(%rsp), %xmm7
movsd 0x28(%rsp), %xmm8
movq 0x58(%rsp), %rbp
movapd 0x40(%rsp), %xmm9
movapd 0x36fa(%rip), %xmm10    # 0x19120
movapd 0x90(%rsp), %xmm11
xorpd %xmm13, %xmm13
movsd 0x36d2(%rip), %xmm14    # 0x19110
movsd 0x70(%rsp), %xmm15
movslq %ecx, %r8
movl (%rbx,%r8,4), %r9d
movslq %r9d, %rdi
movsd (%r13,%rdi,8), %xmm1
movapd %xmm8, %xmm3
mulsd %xmm1, %xmm3
subsd (%rbp,%rdi,8), %xmm3
movq (%rax,%rdi,8), %rdx
movl (%rdx), %esi
cmpl $-0x1, %esi
je 0x15a98
leaq 0x10(%rdx), %r10
movl %esi, %r11d
movsd -0x8(%r10), %xmm2
movslq %r11d, %r11
mulsd -0x8(%r12,%r11,8), %xmm2
addsd %xmm2, %xmm3
movl (%r10), %r11d
addq $0x10, %r10
cmpl $-0x1, %r11d
jne 0x15a77
movsd (%r15,%rdi,8), %xmm4
addsd %xmm8, %xmm4
movapd %xmm7, %xmm2
addsd %xmm3, %xmm2
subsd %xmm7, %xmm3
ucomisd %xmm13, %xmm1
jne 0x15aca
jp 0x15aca
ucomisd %xmm2, %xmm13
jbe 0x15ae5
movapd %xmm2, %xmm5
xorpd %xmm12, %xmm5
jmp 0x15b3c
ucomisd %xmm9, %xmm1
jae 0x15b08
ucomisd %xmm1, %xmm11
jae 0x15b22
ucomisd %xmm13, %xmm1
jbe 0x15b33
movapd %xmm2, %xmm5
jmp 0x15b37
ucomisd %xmm13, %xmm3
movapd %xmm3, %xmm5
ja 0x15b3c
ucomisd 0x10(%rsp), %xmm2
xorpd %xmm5, %xmm5
jbe 0x15b3c
ucomisd %xmm3, %xmm0
ja 0x15c03
jmp 0x15b3c
ucomisd %xmm13, %xmm2
movapd %xmm2, %xmm5
ja 0x15b3c
xorpd %xmm5, %xmm5
ucomisd %xmm2, %xmm0
jbe 0x15b3c
jmp 0x15c03
ucomisd %xmm3, %xmm13
jbe 0x15bf3
movapd %xmm3, %xmm5
jmp 0x15ac3
movapd %xmm3, %xmm5
andpd %xmm10, %xmm5
movapd %xmm1, %xmm6
mulsd %xmm4, %xmm6
ucomisd %xmm2, %xmm6
jbe 0x15b55
xorpd %xmm12, %xmm2
divsd %xmm4, %xmm2
jmp 0x15b73
ucomisd %xmm6, %xmm3
jbe 0x15b6a
xorpd %xmm12, %xmm3
divsd %xmm4, %xmm3
movapd %xmm3, %xmm2
jmp 0x15b73
movapd %xmm1, %xmm2
xorpd %xmm12, %xmm2
movsd 0x8(%rsp), %xmm3
maxsd %xmm5, %xmm3
movsd %xmm3, 0x8(%rsp)
movsd (%rsp), %xmm3
addsd %xmm5, %xmm3
movsd %xmm3, (%rsp)
movapd %xmm2, %xmm3
andpd %xmm10, %xmm3
ucomisd %xmm3, %xmm14
ja 0x15c1c
addsd %xmm1, %xmm2
maxsd %xmm11, %xmm2
minsd %xmm9, %xmm2
movsd %xmm2, (%r13,%rdi,8)
subsd %xmm1, %xmm2
ucomisd %xmm13, %xmm2
jne 0x15bc3
jnp 0x15c1c
cmpl $-0x1, %esi
je 0x15c1c
addq $0x10, %rdx
movslq %esi, %rsi
movsd -0x8(%rdx), %xmm1
mulsd %xmm2, %xmm1
addsd -0x8(%r12,%rsi,8), %xmm1
movsd %xmm1, -0x8(%r12,%rsi,8)
movl (%rdx), %esi
addq $0x10, %rdx
cmpl $-0x1, %esi
jne 0x15bcc
jmp 0x15c1c
xorpd %xmm5, %xmm5
ucomisd 0x10(%rsp), %xmm3
jbe 0x15b3c
movslq %r14d, %rcx
decl %r14d
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 %r14d, %ecx
jl 0x15a45
jmp 0x15c5b
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movsd %xmm0, 0x8(%rsp)
movl %ebp, %r14d
jmp 0x15c5b
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movsd %xmm0, 0x8(%rsp)
movl %ebp, %r14d
movq 0x68(%rsp), %r15
movsd 0x70(%rsp), %xmm15
movsd (%rsp), %xmm1
movapd %xmm1, %xmm2
movq 0x78(%rsp), %rcx
testl %ecx, %ecx
je 0x15c72
movapd %xmm15, %xmm2
leal 0x1(%rcx), %ebp
imull $0xcccccccd, %ebp, %eax # imm = 0xCCCCCCCD
rorl %eax
cmpl $0x19999999, %eax       # imm = 0x19999999
ja 0x15ca8
leaq 0x3d33(%rip), %rdi      # 0x199be
xorl %eax, %eax
movsd %xmm2, 0x10(%rsp)
callq 0x735c
movsd 0x10(%rsp), %xmm2
movsd (%rsp), %xmm1
movq 0x78(%rsp), %rcx
movsd 0x88(%rsp), %xmm0
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jae 0x15cc3
movsd 0x8(%rsp), %xmm0
jmp 0x15cf2
movq 0x60(%rsp), %rax
cmpl %eax, %r14d
movq %rax, %r14
je 0x15d25
leaq 0x3811(%rip), %rdi      # 0x194e8
xorl %eax, %eax
movsd %xmm2, 0x10(%rsp)
callq 0x735c
movsd 0x10(%rsp), %xmm2
movsd 0x233e(%rip), %xmm0     # 0x18030
movl %ebp, %eax
movapd %xmm0, 0x10(%rsp)
movapd %xmm2, %xmm15
cmpl $0x3e8, %ebp            # imm = 0x3E8
jne 0x1597a
leaq 0x37d8(%rip), %rdi      # 0x194ea
movl $0x3e8, %esi            # imm = 0x3E8
xorl %eax, %eax
callq 0x735c
movq 0x60(%rsp), %r14
jmp 0x15d40
leaq 0x37be(%rip), %rdi      # 0x194ea
movl %ebp, %esi
xorl %eax, %eax
movq %rcx, %rbp
callq 0x735c
cmpl $0x3e7, %ebp            # imm = 0x3E7
jne 0x15d4e
leaq 0x3a7f(%rip), %rdi      # 0x197c6
xorl %eax, %eax
callq 0x735c
movq 0x50(%rsp), %rcx
testl %ecx, %ecx
movapd 0x33c3(%rip), %xmm7     # 0x19120
xorpd %xmm0, %xmm0
jle 0x15d91
xorl %eax, %eax
movsd 0x30(%rsp), %xmm5
movsd 0x28(%rsp), %xmm6
movsd (%r12,%rax,8), %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rax
cmpq %rax, %rcx
jne 0x15d71
mulsd 0x3371(%rip), %xmm0     # 0x19100
jmp 0x15d9d
movsd 0x30(%rsp), %xmm5
movsd 0x28(%rsp), %xmm6
testl %r14d, %r14d
jle 0x15e01
mulsd 0x3356(%rip), %xmm6     # 0x19100
xorl %eax, %eax
xorpd %xmm1, %xmm1
xorl %ebp, %ebp
movq 0x58(%rsp), %rdx
movsd (%r13,%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, %ebp
incq %rax
cmpq %rax, %r14
jne 0x15db7
jmp 0x15e03
xorl %ebp, %ebp
leaq 0x3731(%rip), %rdi      # 0x1953b
movb $0x1, %al
callq 0x735c
leaq 0x373a(%rip), %rdi      # 0x19552
movl %ebp, %esi
xorl %eax, %eax
callq 0x735c
movq %r13, %rdi
callq 0x32d0
movq %r15, %rdi
callq 0x32d0
movq %rbx, %rdi
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x32d0