// File: /workspace/github_c_makefile_star2_O3/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 %rsi, %r12
movq %rdi, %r15
movq $0x0, 0x10(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movl (%rcx), %ecx
movl %ecx, 0x20(%rdi)
movq (%rsi), %rdi
movsd 0x10(%rbx), %xmm0
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x74e80
testl %eax, %eax
je 0x763e4
movq %r15, (%rsp)
movq 0x8(%r15), %r15
xorl %r13d, %r13d
cmpq $0x0, (%r14)
movq %r12, %rdi
je 0x762d5
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x18(%rsp), %rbp
movq %rbp, %rdx
movl $0x3, %ecx
callq 0x31019
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x74f52
testq %rax, %rax
je 0x763ae
movq %rax, %rbp
cmpq $0x0, 0x20(%rax)
je 0x763ae
cmpq $0x0, (%r14)
movl 0x4(%rbx), %edx
leaq 0x8(%rsp), %rax
cmoveq %r12, %rax
movq (%rax), %rsi
movq %rbp, %rdi
callq 0x750c1
cmpq $0x0, 0x20(%rbp)
je 0x763ae
addq $0x38, %r15
testl %r13d, %r13d
cmoveq (%rsp), %r15
movq %rbp, (%r15)
movq $0x0, 0x38(%rbp)
cmpq $0x0, (%r14)
je 0x76356
movq (%r12), %rdi
movq 0x18(%rsp), %rsi
callq 0x31345
movq %rax, (%r12)
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x30648
movq %r12, %rdi
leaq 0x10(%rsp), %rsi
movq %rbp, %rdx
callq 0x7533e
movl (%rbx), %ecx
cmpl $0x1, %ecx
jne 0x7637e
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x3ed51
movl (%rbx), %ecx
movq (%r12), %rdi
movsd 0x10(%rbx), %xmm0
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
callq 0x74e80
incl %r13d
movq %rbp, %r15
testl %eax, %eax
jne 0x762af
movq (%rsp), %r15
movq %rbp, 0x8(%r15)
jmp 0x763e7
movq (%rsp), %rax
movq %r15, 0x8(%rax)
movq %rax, %r15
movl %r13d, 0x30(%rax)
cmpq $0x0, (%r14)
je 0x763eb
movq (%r12), %rdi
movq 0x18(%rsp), %rsi
callq 0x31345
movq %rax, (%r12)
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x30648
jmp 0x763eb
xorl %r13d, %r13d
movl %r13d, 0x30(%r15)
cmpl $0x0, (%rbx)
je 0x763fc
movups 0x28(%rsp), %xmm0
movups %xmm0, 0x10(%r15)
jmp 0x76408
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x28(%r15)
movq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x30648
cmpl $0x0, 0x8(%rbx)
jle 0x7644c
xorl %ebp, %ebp
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x7462d
movq (%r14), %rsi
testq %rsi, %rsi
jne 0x7643a
movq (%r12), %rsi
movl 0x4(%rbx), %edx
movq %r15, %rdi
callq 0x74043
incl %ebp
cmpl 0x8(%rbx), %ebp
jl 0x7641d
movq %r15, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop