// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movq $0x0, 0x18(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movl $0x0, 0x30(%rdi)
movl (%rcx), %eax
movl %eax, 0x20(%rdi)
movq (%rdi), %rbp
movq (%rsi), %rdi
movsd 0x10(%rcx), %xmm0
movl (%rcx), %ecx
leaq 0x30(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x735c2
testl %eax, %eax
je 0x74b2e
movq %rbp, (%rsp)
movq %r15, 0x10(%rsp)
movq 0x8(%r15), %r15
xorl %r13d, %r13d
cmpq $0x0, (%r14)
movq %r12, %rdi
je 0x74a06
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x20(%rsp), %rbp
movq %rbp, %rdx
movl $0x3, %ecx
callq 0x30746
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x73694
testq %rax, %rax
je 0x74af0
movq %rax, %rbp
cmpq $0x0, 0x20(%rax)
je 0x74af0
cmpq $0x0, (%r14)
leaq 0x8(%rsp), %rax
cmoveq %r12, %rax
movq (%rax), %rsi
movl 0x4(%rbx), %edx
movq %rbp, %rdi
callq 0x7380b
cmpq $0x0, 0x20(%rbp)
je 0x74af0
movq %rbp, %rax
testl %r13d, %r13d
je 0x74a5b
movq %rbp, 0x38(%r15)
movq (%rsp), %rax
movq %rax, 0x40(%rsp)
movq $0x0, 0x38(%rbp)
cmpq $0x0, (%r14)
je 0x74a8d
movq (%r12), %rdi
movq 0x20(%rsp), %rsi
callq 0x30ad5
movq %rax, (%r12)
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x2fd59
movq %r12, %rdi
leaq 0x18(%rsp), %rsi
movq %rbp, %rdx
callq 0x73a73
cmpl $0x1, (%rbx)
jne 0x74ab1
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3dbad
movq (%r12), %rdi
movsd 0x10(%rbx), %xmm0
movl (%rbx), %ecx
leaq 0x30(%rsp), %rsi
leaq 0x28(%rsp), %rdx
callq 0x735c2
incl %r13d
movq %rbp, %r15
movq 0x40(%rsp), %rcx
movq %rcx, (%rsp)
testl %eax, %eax
jne 0x749e0
movq 0x10(%rsp), %r15
movq %rbp, 0x8(%r15)
movq %rcx, %rbp
jmp 0x74b31
movq 0x10(%rsp), %rax
movq %r15, 0x8(%rax)
movq %rax, %r15
movl %r13d, 0x30(%rax)
movq (%rsp), %rax
movq %rax, (%r15)
cmpq $0x0, (%r14)
je 0x74b38
movq (%r12), %rdi
movq 0x20(%rsp), %rsi
callq 0x30ad5
movq %rax, (%r12)
movq 0x8(%rsp), %rsi
movq %r12, %rdi
callq 0x2fd59
jmp 0x74b38
xorl %r13d, %r13d
movl %r13d, 0x30(%r15)
movq %rbp, (%r15)
cmpl $0x0, (%rbx)
je 0x74b49
movups 0x30(%rsp), %xmm0
movups %xmm0, 0x10(%r15)
jmp 0x74b55
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x28(%r15)
movq 0x18(%rsp), %rsi
movq %r12, %rdi
callq 0x2fd59
cmpl $0x0, 0x8(%rbx)
jle 0x74b99
xorl %ebp, %ebp
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x72d9a
movq (%r14), %rsi
testq %rsi, %rsi
jne 0x74b87
movq (%r12), %rsi
movl 0x4(%rbx), %edx
movq %r15, %rdi
callq 0x7277b
incl %ebp
cmpl 0x8(%rbx), %ebp
jl 0x74b6a
movq %r15, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop