// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/multiplemodel.c
// Function: mmelin1
int mmelin1(Instanceptr* traindata)
{
	/*!Last Changed 11.04.2005*/
	matrix X, r, w, bestw, *models;
	Instanceptr removed = NULL, modelremoved = NULL, tmp;
	int i, finished = 1, iteration, size, j, mindatasize, modelcount, first;
	double totalerror, *residuals, threshold, upperbound, upperbefore, bestthreshold, ratio, bestratio;
	size = data_size(*traindata);
 mindatasize = size / 20;
	modelcount = 0;
	while (finished)
	 {
		 iteration = size / mindatasize;
			bestratio = 0;
			first = 1;
		 for (i = 0; i < iteration - 2; i++)
			 {
     create_regression_matrices(*traindata, &X, &r);
    	w = multivariate_regression(X, r);
	  		matrix_free(X);
		  	matrix_free(r);
    	size = data_size(*traindata);
					residuals = safemalloc(size * sizeof(double), "mmelin", 20);
					j = 0;
					totalerror = 0;
					tmp = *traindata;
					while (tmp)
					 {
						 residuals[j] = fabs(linear_fit_value(w, tmp) - give_regressionvalue(tmp));
							totalerror += residuals[j] * residuals[j]; 
						 tmp = tmp->next;
							j++;
					 }
					totalerror /= j;
     upperbound = srm_regression(totalerror, current_dataset->multifeaturecount, size, 1.0, 1.0);
					if (i != 0)
						 ratio = upperbefore / upperbound;
					else
						 ratio = 0;
					upperbefore = upperbound;
     if (ratio > bestratio)
					 {
						 if (!first)
								 matrix_free(bestw);
       bestw = matrix_copy(w);
							bestratio = ratio;
							bestthreshold = threshold;
					 }
     qsort(residuals, size, sizeof(double), sort_function_double_ascending);
					threshold = (residuals[size - mindatasize - 1] + residuals[size - mindatasize]) / 2;
     remove_instances_according_to_threshold(traindata, &modelremoved, threshold, w, '>');
					matrix_free(w);
			 }
			merge_instancelist(traindata, modelremoved);
   remove_instances_according_to_threshold(traindata, &removed, bestthreshold, bestw, '<');
			modelremoved = NULL;
			modelcount++;
			models = alloc(models, modelcount * sizeof(matrix), modelcount);
			models[modelcount - 1] = matrix_copy(bestw);
			matrix_free(bestw);
			size = data_size(*traindata);
			if (size <= 2 * mindatasize)
				 finished = 0;
	 }
	merge_instancelist(traindata, removed);
	removed = NULL;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x8(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl $0x1, -0x70(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x449f0
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl $0x14, %ecx
cltd
idivl %ecx
movl %eax, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
cmpl $0x0, -0x70(%rbp)
je 0x6c536
movl -0x78(%rbp), %eax
cltd
idivl -0x80(%rbp)
movl %eax, -0x74(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0xc8(%rbp)
movl $0x1, -0x88(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
movl -0x74(%rbp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jge 0x6c445
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x18(%rbp), %rsi
leaq -0x28(%rbp), %rdx
callq 0xa6c20
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rcx
callq 0xa6590
movq %rax, -0xd8(%rbp)
movq %rdx, -0xd0(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x59ea0
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x59ea0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x449f0
movl %eax, -0x78(%rbp)
movslq -0x78(%rbp), %rdi
shlq $0x3, %rdi
leaq 0x7b045(%rip), %rsi     # 0xe7218
movl $0x14, %edx
callq 0x52d70
movq %rax, -0x98(%rbp)
movl $0x0, -0x7c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x6c2aa
movq -0x68(%rbp), %rdx
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xa6aa0
movsd %xmm0, -0x100(%rbp)
movq -0x68(%rbp), %rdi
callq 0x43580
movaps %xmm0, %xmm1
movsd -0x100(%rbp), %xmm0
subsd %xmm1, %xmm0
movaps 0x76c1c(%rip), %xmm1    # 0xe2e60
pand %xmm1, %xmm0
movq -0x98(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x98(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x98(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd -0x90(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x6c201
cvtsi2sdl -0x7c(%rbp), %xmm1
movsd -0x90(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd -0x90(%rbp), %xmm0
leaq 0x9956e(%rip), %rax     # 0x105840
movq (%rax), %rax
movl 0x1c0(%rax), %edi
movl -0x78(%rbp), %esi
movsd 0x75d32(%rip), %xmm2    # 0xe2018
movaps %xmm2, %xmm1
callq 0x67ad0
movsd %xmm0, -0xa8(%rbp)
cmpl $0x0, -0x6c(%rbp)
je 0x6c316
movsd -0xb0(%rbp), %xmm0
divsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xc0(%rbp)
jmp 0x6c321
xorps %xmm0, %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xc0(%rbp), %xmm0
ucomisd -0xc8(%rbp), %xmm0
jbe 0x6c3aa
cmpl $0x0, -0x88(%rbp)
jne 0x6c359
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x59ea0
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x58550
movq %rax, -0xe8(%rbp)
movq %rdx, -0xe0(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x40(%rbp)
movsd -0xc0(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movq -0x98(%rbp), %rdi
movslq -0x78(%rbp), %rsi
movl $0x8, %edx
leaq -0x18f01(%rip), %rcx    # 0x534c0
callq 0x41f0
movq -0x98(%rbp), %rax
movl -0x78(%rbp), %ecx
subl -0x80(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x98(%rbp), %rax
movl -0x78(%rbp), %ecx
subl -0x80(%rbp), %ecx
movslq %ecx, %rcx
addsd (%rax,%rcx,8), %xmm0
movsd 0x768a5(%rip), %xmm1    # 0xe2ca0
divsd %xmm1, %xmm0
movsd %xmm0, -0xa0(%rbp)
movq -0x8(%rbp), %rdi
movsd -0xa0(%rbp), %xmm0
movq -0x38(%rbp), %rdx
movq -0x30(%rbp), %rcx
leaq -0x60(%rbp), %rsi
movl $0x3e, %r8d
callq 0x6bf60
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x59ea0
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x6c13d
movq -0x8(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x44f40
movq -0x8(%rbp), %rdi
movsd -0xb8(%rbp), %xmm0
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rcx
leaq -0x58(%rbp), %rsi
movl $0x3c, %r8d
callq 0x6bf60
movq $0x0, -0x60(%rbp)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
movq -0x50(%rbp), %rdi
movslq -0x84(%rbp), %rsi
shlq $0x4, %rsi
movl -0x84(%rbp), %edx
callq 0x52d10
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl -0x84(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x108(%rbp)
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x58550
movq %rax, %rcx
movq -0x108(%rbp), %rax
movq %rcx, -0xf8(%rbp)
movq %rdx, -0xf0(%rbp)
movq -0xf8(%rbp), %rcx
movq %rcx, (%rax)
movq -0xf0(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x59ea0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x449f0
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl -0x80(%rbp), %ecx
shll %ecx
cmpl %ecx, %eax
jg 0x6c531
movl $0x0, -0x70(%rbp)
jmp 0x6c10d
movq -0x8(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x44f40
movq $0x0, -0x58(%rbp)
xorl %eax, %eax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw %cs:(%rax,%rax)