// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/regressionrule.c
// Function: regression_rule_learner
Regressionruleset regression_rule_learner(Instanceptr* traindata, Instanceptr* cvdata, Regrule_parameterptr param)
{
	/*!Last Changed 06.03.2005*/
	Regressionruleset result;
	matrix w;
	double regvalue;
	int exitnow, i;
	Regressionruleptr newrule;
	Instanceptr grow, prune, coveredtrain = NULL;
	result = empty_regression_ruleset();
	result.leaftype = param->leaftype;
	while (can_be_divided_rule(*traindata, param->sigma, &w, &regvalue, param->leaftype))
	 {
		 exitnow = 0;
			if (*cvdata)
				{
     divide_instancelist(traindata, &prune, &grow, 3);
     newrule = grow_regression_rule(&grow, param);
				}
			else
					newrule = grow_regression_rule(traindata, param);
  	if (newrule && newrule->start)
			 {
				 if (*cvdata)
						 prune_regression_rule(newrule, prune, param->modelselectionmethod);
					else
						 prune_regression_rule(newrule, *traindata, param->modelselectionmethod);
					if (newrule->start)
					 {
						 add_regression_rule(&result, newrule);
							if (*cvdata)
							 {
  				   *traindata = restore_instancelist(*traindata, grow);
  				  	merge_instancelist(traindata, prune);
							 }
					 }
					else
						 exitnow = 1;
			 }
			else
				 exitnow = 1;
			if (!exitnow)
			 {
				 remove_regression_covered(traindata, &coveredtrain, newrule);
  		 if (param->leaftype == LINEARLEAF)
    		 matrix_free(w);				 
			 }
			else
			 {
				 if (*cvdata)
					 {
  		  	*traindata = restore_instancelist(*traindata, grow);
  			  merge_instancelist(traindata, prune);
					 }
				 break;
			 }
	 }
	if (param->leaftype == CONSTANTLEAF)
		 result.regressionvalue = regvalue;
	else
  	result.w = w;
	merge_instancelist(traindata, coveredtrain);
	for (i = 0; i < param->optimizecount; i++)
	 {
   optimize_regression_ruleset(&result, traindata, cvdata, param);
			if (*cvdata)
  			simplify_regression_ruleset(&result, *cvdata, param->modelselectionmethod);
			else
  			simplify_regression_ruleset(&result, *traindata, param->modelselectionmethod);
	 }
	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rdi, %r15
leaq 0x8(%rsp), %rax
andq $0x0, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
andl $0x0, 0x30(%rdi)
movq %rsi, %r12
movl (%rcx), %ecx
movl %ecx, 0x20(%rdi)
leaq 0x10(%rsp), %rbp
movq (%r12), %rdi
movsd 0x10(%rbx), %xmm0
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x6b081
testl %eax, %eax
je 0x6c392
cmpq $0x0, (%r14)
movq %r12, %rdi
je 0x6c2cd
movq %r12, %rdi
movq %rbp, %rsi
leaq 0x18(%rsp), %r13
movq %r13, %rdx
pushq $0x3
popq %rcx
callq 0x2cfe5
movq %r13, %rdi
movq %rbx, %rsi
callq 0x6b153
testq %rax, %rax
je 0x6c36d
movq %rax, %r13
cmpq $0x0, 0x20(%rax)
je 0x6c36d
cmpq $0x0, (%r14)
movl 0x4(%rbx), %edx
movq %rbp, %rax
cmoveq %r12, %rax
movq (%rax), %rsi
movq %r13, %rdi
callq 0x6b276
cmpq $0x0, 0x20(%r13)
je 0x6c36d
movq %r15, %rdi
movq %r13, %rsi
callq 0x6b511
cmpq $0x0, (%r14)
je 0x6c33c
movq (%r12), %rdi
movq 0x18(%rsp), %rsi
callq 0x2d2da
movq %rax, (%r12)
movq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x2c6e4
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
movq %r13, %rdx
callq 0x6b46d
movl (%rbx), %ecx
cmpl $0x1, %ecx
jne 0x6c28b
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x3929f
movl (%rbx), %ecx
jmp 0x6c28b
cmpq $0x0, (%r14)
je 0x6c392
movq (%r12), %rdi
movq 0x18(%rsp), %rsi
callq 0x2d2da
movq %rax, (%r12)
movq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x2c6e4
cmpl $0x0, (%rbx)
je 0x6c3a3
movups 0x28(%rsp), %xmm0
movups %xmm0, 0x10(%r15)
jmp 0x6c3af
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x28(%r15)
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x2c6e4
xorl %ebp, %ebp
cmpl 0x8(%rbx), %ebp
jge 0x6c3ef
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x6a957
movq (%r14), %rsi
testq %rsi, %rsi
jne 0x6c3e0
movq (%r12), %rsi
movl 0x4(%rbx), %edx
movq %r15, %rdi
callq 0x6a414
incl %ebp
jmp 0x6c3be
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)