// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/regression.c
// Function: train_linearregression
void* train_linearregression(Instanceptr* trdata, Instanceptr *cvdata, void* parameters)
{
	/*!Last Changed 10.12.2004*/
	Model_linearregressionptr m;
	int i, datacount = 0;
	matrix rxy, rxx, mx, mxprime, bmatrix;
	Instanceptr tmp;
	double regmean, y;
 Instance mean;
	m = safemalloc(sizeof(Model_linearregression), "train_linearregression", 6);
	rxy = matrix_alloc(1, current_dataset->multifeaturecount - 1);
 mean = find_mean(*trdata);
	mxprime = instance_to_matrix(&mean);
	mx = matrix_transpose(mxprime);
	matrix_free(mxprime);
	regmean = find_mean_of_regression_value(*trdata);
	rxx = covariance(*trdata, mean);
	matrix_inverse(&rxx);
	tmp = *trdata;
	while (tmp)
	 {
		 datacount++;
		 y = give_regressionvalue(tmp);
		 for (i = 0; i < current_dataset->multifeaturecount - 1; i++)
				 rxy.values[0][i] += (real_feature(tmp, i) - real_feature(&mean, i)) * (y - regmean);
		 tmp = tmp->next;
	 }
	for (i = 0; i < current_dataset->multifeaturecount - 1; i++)
		 rxy.values[0][i] /= (datacount - 1);
	m->w = matrix_multiply(rxy, rxx);
	matrix_free(rxy);
 bmatrix = matrix_multiply(m->w, mx);
 m->b = regmean - bmatrix.values[0][0];
	safe_free(mean.values);
	matrix_free(bmatrix);
	matrix_free(mx);
	matrix_free(rxx);
	return m;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x18, %edi
leaq 0x4aac1(%rip), %rsi     # 0xec21b
movl $0x6, %edx
callq 0x52d70
movq %rax, -0x20(%rbp)
leaq 0x640d1(%rip), %rax     # 0x105840
movq (%rax), %rax
movl 0x1c0(%rax), %esi
subl $0x1, %esi
movl $0x1, %edi
callq 0x57fc0
movq %rax, -0xd0(%rbp)
movq %rdx, -0xc8(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rsi
leaq -0x100(%rbp), %rdi
callq 0x19b30
leaq -0xc0(%rbp), %rdi
leaq -0x100(%rbp), %rsi
movl $0x30, %edx
callq 0x42b0
leaq -0xc0(%rbp), %rdi
callq 0x43160
movq %rax, -0x110(%rbp)
movq %rdx, -0x108(%rbp)
movq -0x110(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x108(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x59ed0
movq %rax, -0x120(%rbp)
movq %rdx, -0x118(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x118(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x68(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x59ea0
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x44600
movsd %xmm0, -0x88(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movups -0xc0(%rbp), %xmm0
movups -0xb0(%rbp), %xmm1
movups -0xa0(%rbp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x18040
movq %rax, -0x130(%rbp)
movq %rdx, -0x128(%rbp)
movq -0x130(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x128(%rbp), %rax
movq %rax, -0x40(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5c470
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
je 0xa1981
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
movq -0x80(%rbp), %rdi
callq 0x43580
movsd %xmm0, -0x90(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
leaq 0x63f4d(%rip), %rcx     # 0x105840
movq (%rcx), %rcx
movl 0x1c0(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xa1970
movq -0x80(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x42c40
movsd %xmm0, -0x158(%rbp)
movl -0x24(%rbp), %esi
leaq -0xc0(%rbp), %rdi
callq 0x42c40
movaps %xmm0, %xmm1
movsd -0x158(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd -0x90(%rbp), %xmm2
subsd -0x88(%rbp), %xmm2
movq -0x30(%rbp), %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa18e9
movq -0x80(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x80(%rbp)
jmp 0xa18bd
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
leaq 0x63eae(%rip), %rcx     # 0x105840
movq (%rcx), %rcx
movl 0x1c0(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xa19d0
movl -0x28(%rbp), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
movq -0x30(%rbp), %rax
movq (%rax), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0xa1988
movq -0x20(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x40(%rbp), %rcx
callq 0x59fe0
movq %rax, %rcx
movq -0x160(%rbp), %rax
movq %rcx, -0x140(%rbp)
movq %rdx, -0x138(%rbp)
movq -0x140(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x138(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x59ea0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movq 0x10(%rax), %rsi
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rcx
callq 0x59fe0
movq %rax, -0x150(%rbp)
movq %rdx, -0x148(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x148(%rbp), %rax
movq %rax, -0x70(%rbp)
movsd -0x88(%rbp), %xmm0
movq -0x70(%rbp), %rax
movq (%rax), %rax
subsd (%rax), %xmm0
movq -0x20(%rbp), %rax
movsd %xmm0, (%rax)
movq -0xc0(%rbp), %rdi
callq 0x52e80
movq -0x78(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x59ea0
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x59ea0
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x59ea0
movq -0x20(%rbp), %rax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopw %cs:(%rax,%rax)