// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbp
leaq 0x3cb91(%rip), %rsi     # 0xafaf7
movl $0x18, %edi
movl $0x6, %edx
callq 0x3a0e1
movq %rax, 0x68(%rsp)
leaq 0x628ef(%rip), %rbx     # 0xd5870
movq (%rbx), %rax
movl 0x1c0(%rax), %esi
decl %esi
movl $0x1, %edi
callq 0x3d79d
movq %rax, 0x50(%rsp)
movq %rdx, %r13
movq (%rbp), %rsi
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x1247b
movq %r14, %rdi
callq 0x2f0c1
movq %rax, %r15
movq %rdx, %r12
movq %rax, %rdi
movq %rdx, %rsi
callq 0x3ed5e
movq %rax, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x3ed51
movq (%rbp), %rdi
callq 0x2ffe1
movsd %xmm0, 0x38(%rsp)
movq (%rbp), %rdi
movupd (%r14), %xmm0
movupd 0x10(%r14), %xmm1
movups 0x20(%r14), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x11398
leaq 0x40(%rsp), %rdi
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
callq 0x409b7
movq (%rbp), %rbp
testq %rbp, %rbp
je 0x730d9
xorl %ecx, %ecx
leaq 0x78(%rsp), %r14
movl %ecx, %r12d
movq %rbp, %rdi
callq 0x2f35e
movsd %xmm0, 0x30(%rsp)
movq (%rbx), %rax
cmpl $0x2, 0x1c0(%rax)
jl 0x730bd
movsd 0x30(%rsp), %xmm0
subsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %r15d, %r15d
movq %rbp, %rdi
movl %r15d, %esi
callq 0x2ed6a
movsd %xmm0, 0x70(%rsp)
movq %r14, %rdi
movl %r15d, %esi
callq 0x2ed6a
movsd 0x70(%rsp), %xmm1
subsd %xmm0, %xmm1
mulsd 0x30(%rsp), %xmm1
movq (%r13), %rax
addsd (%rax,%r15,8), %xmm1
movsd %xmm1, (%rax,%r15,8)
incq %r15
movq (%rbx), %rax
movslq 0x1c0(%rax), %rcx
decq %rcx
cmpq %rcx, %r15
jl 0x7306c
leal 0x1(%r12), %ecx
movq 0x10(%rbp), %rbp
testq %rbp, %rbp
jne 0x7303a
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
jmp 0x730e4
movq (%rbx), %rax
movsd 0x32cc4(%rip), %xmm0    # 0xa5da8
movl 0x1c0(%rax), %eax
cmpl $0x2, %eax
jl 0x7310d
decl %eax
movq (%r13), %rcx
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x730f7
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x3ee2f
movq 0x68(%rsp), %rbx
movq %rax, 0x8(%rbx)
movq %rdx, 0x10(%rbx)
movq %r14, %rdi
movq %r13, %rsi
callq 0x3ed51
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
movq 0x60(%rsp), %r12
movq %r12, %rdx
movq 0x58(%rsp), %r13
movq %r13, %rcx
callq 0x3ee2f
movq %rax, %r14
movq %rdx, %r15
movq (%rdx), %rax
movsd 0x38(%rsp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, (%rbx)
movq 0x78(%rsp), %rdi
callq 0x3a180
movq %r14, %rdi
movq %r15, %rsi
callq 0x3ed51
movq %r12, %rdi
movq %r13, %rsi
callq 0x3ed51
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x3ed51
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq