// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/regressionrule.c
// Function: best_regression_condition_aic_or_bic
void best_regression_condition_aic_or_bic(Regressionconditionptr condition, Instanceptr* data, LEAF_TYPE leaftype, int modelselectionmethod)
{
	/*!Last Changed 27.03.2005*/
	int i, size = data_size(*data), d, bestmodel;
	double error, results[3];
 Instanceptr leftl, rightl, leftq, rightq, leftinstances, rightinstances;
 find_uni_and_multi_regression_conditions(condition, *data, &leftl, &rightl, &leftq, &rightq, leaftype);
	for (i = 0; i < 3; i++)
	 {
		 switch (i)
    {
		   case MODEL_UNI:divide_instancelist_according_to_split(data, &leftinstances, &rightinstances, condition->featureindex, condition->value);
						              d = 2;
						              break;
					case MODEL_LIN:divide_instancelist_according_centers(data, &leftinstances, &rightinstances, leftl, rightl, NO);
						              d = current_dataset->multifeaturecount;
						              break;
					case MODEL_QUA:divide_instancelist_according_centers(data, &leftinstances, &rightinstances, leftq, rightq, YES);
						              d = multifeaturecount_2d(current_dataset) + 1;
						              break;
    }
			error = (constant_or_linear_model_mse(leftinstances, leftinstances, leaftype) + constant_or_linear_model_mse(rightinstances, rightinstances, leaftype)) / size;
			if (modelselectionmethod == 1)
     results[i] = aic_squared_error(error, d, size);
			else
				 results[i] = bic_squared_error(error, d, size);
  	*data = restore_instancelist(*data, leftinstances);
	  merge_instancelist(data, rightinstances);	
	 }
	bestmodel = find_min_in_list_double(results, 3);
	set_best_model_in_regression_rule(condition, bestmodel, leftl, rightl, leftq, rightq);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %ebp
movl %edx, %r14d
movq %rsi, %r15
movq %rdi, %rbx
movq (%rsi), %rdi
callq 0x2c3cc
movl %eax, %r12d
movq (%r15), %rsi
movl %r14d, (%rsp)
leaq 0x38(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x28(%rsp), %r8
leaq 0x20(%rsp), %r9
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
callq 0x6bde9
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x40(%rsp)
xorl %ebx, %ebx
cmpq $0x3, %rbx
je 0x6c02f
cmpl $0x2, %ebx
je 0x6bf60
cmpl $0x1, %ebx
jne 0x6bf97
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %r8
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
xorl %r9d, %r9d
callq 0x2ca3c
leaq 0x6191c(%rip), %rax     # 0xcd870
movq (%rax), %rax
movl 0x1c0(%rax), %r13d
jmp 0x6bfb9
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %r8
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
pushq $0x1
popq %r9
callq 0x2ca3c
leaq 0x618e9(%rip), %rax     # 0xcd870
movq (%rax), %rdi
callq 0x126ea
movl %eax, %r13d
incl %r13d
jmp 0x6bfb9
movq 0x18(%rsp), %rax
movl (%rax), %ecx
movsd 0x8(%rax), %xmm0
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x2caf4
pushq $0x2
popq %r13
movq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl %r14d, %edx
callq 0x6d63d
movsd %xmm0, 0x48(%rsp)
movq 0x8(%rsp), %rdi
movq %rdi, %rsi
movl %r14d, %edx
callq 0x6d63d
addsd 0x48(%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
cvtsi2sd %r13d, %xmm1
movl %r12d, %edi
cmpl $0x1, %ebp
jne 0x6bfff
callq 0x40b9e
jmp 0x6c004
callq 0x40f59
movsd %xmm0, 0x50(%rsp,%rbx,8)
movq (%r15), %rdi
movq 0x10(%rsp), %rsi
callq 0x2d2da
movq %rax, (%r15)
movq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2c6e4
incq %rbx
jmp 0x6bf1a
leaq 0x50(%rsp), %rdi
pushq $0x3
popq %rsi
callq 0x338cc
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %rdi
movl %eax, %esi
callq 0x6be54
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq