// File: /workspace/github_c_makefile_star2_O1/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 0x3b285(%rip), %rsi     # 0xaca1f
movl $0x18, %edi
movl $0x6, %edx
callq 0x390f5
movq %rax, 0x68(%rsp)
leaq 0x610bb(%rip), %rbx     # 0xd2870
movq (%rbx), %rax
movl 0x1c0(%rax), %esi
decl %esi
movl $0x1, %edi
callq 0x3c6e5
movq %rax, 0x50(%rsp)
movq %rdx, %r13
movq (%rbp), %rsi
leaq 0x78(%rsp), %r14
movq %r14, %rdi
callq 0x12519
movq %r14, %rdi
callq 0x2e851
movq %rax, %r15
movq %rdx, %r12
movq %rax, %rdi
movq %rdx, %rsi
callq 0x3dbba
movq %rax, 0x60(%rsp)
movq %rdx, 0x58(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x3dbad
movq (%rbp), %rdi
callq 0x2f6a1
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 0x113c9
leaq 0x40(%rsp), %rdi
movq %rax, (%rdi)
movq %rdx, 0x8(%rdi)
callq 0x3f648
movq (%rbp), %rbp
testq %rbp, %rbp
je 0x7190d
xorl %eax, %eax
leaq 0x78(%rsp), %r14
movl %eax, %r12d
movq %rbp, %rdi
callq 0x2eaee
movsd %xmm0, 0x30(%rsp)
movq (%rbx), %rax
cmpl $0x2, 0x1c0(%rax)
jl 0x718f1
movsd 0x30(%rsp), %xmm0
subsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %r15d, %r15d
movq %rbp, %rdi
movl %r15d, %esi
callq 0x2e4b6
movsd %xmm0, 0x70(%rsp)
movq %r14, %rdi
movl %r15d, %esi
callq 0x2e4b6
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), %rax
decq %rax
cmpq %rax, %r15
jl 0x718a0
leal 0x1(%r12), %eax
movq 0x10(%rbp), %rbp
testq %rbp, %rbp
jne 0x7186e
xorps %xmm0, %xmm0
cvtsi2sd %r12d, %xmm0
jmp 0x71915
movsd 0x31493(%rip), %xmm0    # 0xa2da8
movq (%rbx), %rax
movl 0x1c0(%rax), %eax
cmpl $0x2, %eax
jl 0x71941
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 0x7192b
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x3dc8b
movq 0x68(%rsp), %rbx
movq %rax, 0x8(%rbx)
movq %rdx, 0x10(%rbx)
movq %r14, %rdi
movq %r13, %rsi
callq 0x3dbad
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
movq 0x60(%rsp), %r12
movq %r12, %rdx
movq 0x58(%rsp), %r13
movq %r13, %rcx
callq 0x3dc8b
movq %rax, %r14
movq %rdx, %r15
movq (%rdx), %rax
movsd 0x38(%rsp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, (%rbx)
movq 0x78(%rsp), %rdi
callq 0x39194
movq %r14, %rdi
movq %r15, %rsi
callq 0x3dbad
movq %r12, %rdi
movq %r13, %rsi
callq 0x3dbad
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x3dbad
movq %rbx, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq