// File: /workspace/github_c_makefile_star2_O1/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 0x2fa14
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 0x744bb
cvtsi2sd %r12d, %xmm0
movsd %xmm0, 0x40(%rsp)
xorl %ebx, %ebx
cmpl $0x2, %ebx
je 0x74656
cmpl $0x1, %ebx
je 0x74624
testl %ebx, %ebx
jne 0x7468d
movq 0x18(%rsp), %rax
movl (%rax), %ecx
movsd 0x8(%rax), %xmm0
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x301e1
movl $0x2, %r13d
jmp 0x7468d
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %r8
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
xorl %r9d, %r9d
callq 0x3010e
leaq 0x5e226(%rip), %rax     # 0xd2870
movq (%rax), %rax
movl 0x1c0(%rax), %r13d
jmp 0x7468d
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %r8
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movl $0x1, %r9d
callq 0x3010e
leaq 0x5e1f1(%rip), %rax     # 0xd2870
movq (%rax), %rdi
callq 0x13726
movl %eax, %r13d
incl %r13d
movq 0x10(%rsp), %rdi
movq %rdi, %rsi
movl %r14d, %edx
callq 0x75f33
movsd %xmm0, 0x48(%rsp)
movq 0x8(%rsp), %rdi
movq %rdi, %rsi
movl %r14d, %edx
callq 0x75f33
addsd 0x48(%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movl %r12d, %edi
cmpl $0x1, %ebp
jne 0x746d6
callq 0x46491
jmp 0x746db
callq 0x468e1
movsd %xmm0, 0x50(%rsp,%rbx,8)
movq (%r15), %rdi
movq 0x10(%rsp), %rsi
callq 0x30ad5
movq %rax, (%r15)
movq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x2fd59
incq %rbx
cmpq $0x3, %rbx
jne 0x745ec
leaq 0x50(%rsp), %rdi
movl $0x3, %esi
callq 0x37740
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %r9
movq 0x18(%rsp), %rdi
movl %eax, %esi
callq 0x74526
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq