// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/mlp.c
// Function: hessian_matrix_reg
matrix hessian_matrix_reg(Mlpnetwork N, Instanceptr train)
{
	/*!Last Changed 18.06.2005*/
	int weightcount, firstlayer, h, hprime, i, iprime, index1, index2;
	double mul, yk, zh, sum1, sum2, zhprime, xi, xiprime, vkh, vkhprime, regvalue;
	Instanceptr tmp;
	matrix result, testY, testH, inst;
	weightcount = number_of_weights_in_mlp_network(N);
	result = matrix_alloc(weightcount, weightcount);
	testH = matrix_alloc(1, N.P.hidden[0]);
	testY = matrix_alloc(1, 1);
	firstlayer = N.weights[0].row * N.weights[0].col;
	tmp = train;
	while (tmp)
	 {
		 regvalue = give_regressionvalue(tmp);
   yk = testY.values[0][0];
		 inst = instance_to_matrix(tmp);
  	calculate_hidden_values(inst.values[0], N.weights[0], &testH);
		 calculate_output_values_reg(testH.values[0], N.weights[1], &testY);
			/*Both in the second layer*/
   for (h = 0; h < N.weights[1].col; h++)
				 for (hprime = 0; hprime < N.weights[1].col; hprime++)
					 {
							zh = testH.values[0][h];
							zhprime = testH.values[0][hprime];
							index1 = firstlayer + h;
							index2 = firstlayer + hprime;
							result.values[index1][index2] += zh * zhprime;
					 }
   /*Both in the first layer*/
			index1 = 0;
			for (h = 0; h < N.weights[0].row; h++)
			 {
					zh = testH.values[0][h];
     vkh = N.weights[1].values[0][h + 1];
				 for (i = 0; i < N.weights[0].col; i++)
					 {
						 xi = inst.values[0][i];
						 index2 = 0;
						 for (hprime = 0; hprime < N.weights[0].row; hprime++)
							 {
         vkhprime = N.weights[1].values[0][hprime + 1];
								 zhprime = testH.values[0][hprime];
								 if (h == hprime)
           sum1 = (yk - regvalue) * (1 - 2 * zhprime);
									else
										 sum1 = 0;
									sum2 = zh * (1 - zh) * vkh;
								 for (iprime = 0; iprime < N.weights[0].col; iprime++)
									 { 
										 xiprime = inst.values[0][iprime];
    							mul = xi * xiprime * zhprime * (1 - zhprime) * vkhprime;
           result.values[index1][index2] += mul * (sum1 + sum2);
										 index2++;
									 }
							 }
						 index1++;
					 }
			 }
   /*One weight in each layer*/
			index1 = 0;
			for (h = 0; h < N.weights[0].row; h++)
			 {
				 zh = testH.values[0][h];
				 for (i = 0; i < N.weights[0].col; i++)
					 {
						 index2 = firstlayer;
							xi = inst.values[0][i];
							mul = xi * zh * (1 - zh);
							for (hprime = 0; hprime < N.weights[1].col; hprime++)
								{
									if (h == hprime - 1)
  									sum1 = yk - regvalue;
									else
											sum1 = 0;
									zhprime = testH.values[0][hprime];
									vkh = N.weights[1].values[0][h + 1];
									sum2 = zhprime * vkh;
         result.values[index1][index2] += mul * (sum1 + sum2);
									result.values[index2][index1] += mul * (sum1 + sum2);
									index2++;
							 }
							index1++;
					 }
			 }
   matrix_free(inst);
		 tmp = tmp->next;
	 }
	matrix_free(testY);
	matrix_free(testH);
	return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
leaq 0xc0(%rsp), %rcx
movl 0x5c(%rcx), %eax
movq (%rcx), %rbx
movq %rdi, %r14
testl %eax, %eax
js 0x44df4
shlq $0x4, %rax
addq $0x10, %rax
xorl %ecx, %ecx
xorl %edi, %edi
movl 0x4(%rbx,%rcx), %edx
imull (%rbx,%rcx), %edx
addl %edx, %edi
addq $0x10, %rcx
cmpq %rcx, %rax
jne 0x44ddf
jmp 0x44df6
xorl %edi, %edi
movl %edi, %esi
callq 0x3d79d
movq %rax, 0x48(%rsp)
movq %rdx, 0x8(%rsp)
leaq 0xc0(%rsp), %rax
movl 0x50(%rax), %esi
movl $0x1, %edi
callq 0x3d79d
movq %rax, 0x40(%rsp)
movq %rax, 0x78(%rsp)
movq %rdx, 0x30(%rsp)
movq %rdx, 0x80(%rsp)
movl $0x1, %edi
movl $0x1, %esi
callq 0x3d79d
movq %rax, 0x38(%rsp)
movq %rdx, 0x10(%rsp)
testq %r14, %r14
je 0x4518a
movq %r14, %rdi
movl 0x4(%rbx), %eax
imull (%rbx), %eax
movslq %eax, %rbp
movq 0x8(%rsp), %rax
leaq (%rax,%rbp,8), %r14
shlq $0x3, %rbp
movq %rbp, 0x70(%rsp)
movq %rdi, %rbx
callq 0x2f35e
movsd %xmm0, 0x58(%rsp)
movq 0x10(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbx, 0x68(%rsp)
movq %rbx, %rdi
callq 0x2f0c1
movq %rax, 0x60(%rsp)
movq %rdx, 0x18(%rsp)
movq (%rdx), %rdi
leaq 0xc0(%rsp), %rax
movq (%rax), %rbx
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
leaq 0x78(%rsp), %rcx
callq 0x44d21
movq %rbx, %r11
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rbx), %rcx
movq 0x18(%rbx), %rdx
movq %rdx, 0x28(%rsp)
movq %rcx, %rdx
shrq $0x20, %rdx
testl %ecx, %ecx
jle 0x44f3e
movq 0x10(%rsp), %rsi
movq (%rsi), %rsi
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
leaq -0x1(%rdx), %rdi
xorl %r8d, %r8d
movq 0x28(%rsp), %r9
movq (%r9,%r8,8), %r9
movsd (%r9), %xmm0
cmpl $0x2, %edx
jl 0x44f30
xorl %r10d, %r10d
movsd 0x8(%r9,%r10,8), %xmm1
mulsd (%rax,%r10,8), %xmm1
addsd %xmm1, %xmm0
incq %r10
cmpq %r10, %rdi
jne 0x44f17
movsd %xmm0, (%rsi,%r8,8)
incq %r8
cmpq %rcx, %r8
jne 0x44f01
testl %edx, %edx
movsd 0x605d8(%rip), %xmm7    # 0xa5520
movsd 0x20(%rsp), %xmm8
jle 0x44f80
xorl %ecx, %ecx
movq (%r14,%rcx,8), %rsi
addq %rbp, %rsi
xorl %edi, %edi
movsd (%rax,%rcx,8), %xmm0
mulsd (%rax,%rdi,8), %xmm0
addsd (%rsi,%rdi,8), %xmm0
movsd %xmm0, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rdx
jne 0x44f5c
incq %rcx
cmpq %rdx, %rcx
jne 0x44f53
movslq (%r11), %rsi
testq %rsi, %rsi
jle 0x45169
movq 0x28(%rsp), %rcx
movq (%rcx), %rdi
movq %r11, 0x50(%rsp)
movl 0x4(%r11), %r8d
subsd 0x58(%rsp), %xmm8
xorl %r9d, %r9d
xorl %r10d, %r10d
movq %r9, %r11
incq %r9
testl %r8d, %r8d
jle 0x45098
movsd (%rax,%r11,8), %xmm1
movq 0x18(%rsp), %rcx
movq (%rcx), %rbx
movapd %xmm7, %xmm0
subsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movq %r9, 0x20(%rsp)
mulsd (%rdi,%r9,8), %xmm0
movslq %r10d, %r10
xorl %r12d, %r12d
movsd (%rbx,%r12,8), %xmm1
movq 0x8(%rsp), %rcx
movq (%rcx,%r10,8), %rbp
xorl %r13d, %r13d
xorl %ecx, %ecx
movsd (%rax,%r13,8), %xmm2
cmpq %r13, %r11
je 0x45009
xorpd %xmm3, %xmm3
jmp 0x4501e
movapd %xmm2, %xmm4
addsd %xmm2, %xmm4
movapd %xmm7, %xmm3
subsd %xmm4, %xmm3
mulsd %xmm8, %xmm3
addsd %xmm0, %xmm3
movsd 0x8(%rdi,%r13,8), %xmm4
incq %r13
movapd %xmm7, %xmm5
subsd %xmm2, %xmm5
movslq %ecx, %rcx
leaq (,%rcx,8), %r15
addq %rbp, %r15
xorl %r9d, %r9d
movsd (%rbx,%r9,8), %xmm6
mulsd %xmm1, %xmm6
mulsd %xmm2, %xmm6
mulsd %xmm5, %xmm6
mulsd %xmm4, %xmm6
mulsd %xmm3, %xmm6
addsd (%r15,%r9,8), %xmm6
movsd %xmm6, (%r15,%r9,8)
incq %r9
cmpq %r9, %r8
jne 0x45045
addq %r9, %rcx
cmpq %rsi, %r13
jne 0x44ff8
incq %r10
incq %r12
cmpq %r8, %r12
jne 0x44fe4
movq 0x70(%rsp), %rbp
movq 0x20(%rsp), %r9
cmpq %rsi, %r9
jne 0x44faa
testl %esi, %esi
movq 0x50(%rsp), %rcx
jle 0x45169
movl 0x4(%rcx), %edi
xorl %r8d, %r8d
xorl %r9d, %r9d
testl %edi, %edi
jle 0x4515d
movsd (%rax,%r8,8), %xmm0
movq 0x18(%rsp), %rcx
movq (%rcx), %r10
movapd %xmm7, %xmm1
subsd %xmm0, %xmm1
movslq %r9d, %r9
leaq 0x1(%r8), %r11
xorl %ecx, %ecx
testl %edx, %edx
jle 0x45152
movsd (%r10,%rcx,8), %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movq 0x28(%rsp), %rbx
movq (%rbx), %rbx
movq 0x8(%rsp), %r15
movq (%r15,%r9,8), %r12
addq %rbp, %r12
xorl %r13d, %r13d
movapd %xmm8, %xmm3
cmpq %r13, %r11
je 0x45115
xorpd %xmm3, %xmm3
movsd (%rax,%r13,8), %xmm4
mulsd 0x8(%rbx,%r8,8), %xmm4
addsd %xmm3, %xmm4
mulsd %xmm2, %xmm4
movsd (%r12,%r13,8), %xmm3
addsd %xmm4, %xmm3
movsd %xmm3, (%r12,%r13,8)
movq (%r14,%r13,8), %r15
addsd (%r15,%r9,8), %xmm4
movsd %xmm4, (%r15,%r9,8)
incq %r13
cmpq %r13, %rdx
jne 0x45107
incq %r9
incq %rcx
cmpq %rdi, %rcx
jne 0x450de
incq %r8
cmpq %rsi, %r8
jne 0x450b7
movq 0x60(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x3ed51
movq 0x68(%rsp), %rdi
movq 0x10(%rdi), %rdi
testq %rdi, %rdi
jne 0x44e73
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3ed51
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rsi
callq 0x3ed51
movq 0x48(%rsp), %rax
movq 0x8(%rsp), %rdx
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq