// File: /workspace/github_c_makefile_star2_O2/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 $0x98, %rsp
movq %rdi, %r14
leaq 0xd0(%rsp), %rcx
movl 0x5c(%rcx), %eax
movq (%rcx), %rbx
testl %eax, %eax
pushq $-0x1
popq %rcx
cmovnsl %eax, %ecx
movslq %ecx, %rax
incq %rax
leaq 0x4(%rbx), %rcx
xorl %edi, %edi
subq $0x1, %rax
jb 0x3e6a2
movl (%rcx), %edx
imull -0x4(%rcx), %edx
addl %edx, %edi
addq $0x10, %rcx
jmp 0x3e68e
movl %edi, %esi
callq 0x380d3
movq %rax, 0x38(%rsp)
movq %rdx, %r15
leaq 0xd0(%rsp), %rax
movl 0x50(%rax), %esi
pushq $0x1
popq %rbp
movl %ebp, %edi
callq 0x380d3
leaq 0x78(%rsp), %rcx
movq %rax, 0x30(%rsp)
movq %rax, (%rcx)
movq %rdx, 0x8(%rsp)
movq %rdx, 0x8(%rcx)
movl %ebp, %edi
movl %ebp, %esi
callq 0x380d3
leaq 0x88(%rsp), %rcx
movq %rax, 0x28(%rsp)
movq %rax, (%rcx)
movq %rdx, 0x18(%rsp)
movq %rdx, 0x8(%rcx)
movl 0x4(%rbx), %eax
imull (%rbx), %eax
cltq
leaq (%r15,%rax,8), %rcx
movq %rax, 0x68(%rsp)
leaq (,%rax,8), %rax
movq %rax, 0x60(%rsp)
movq %rcx, 0x40(%rsp)
testq %r14, %r14
je 0x3ea12
movq %r14, %rdi
callq 0x2b4a0
movsd %xmm0, (%rsp)
movq 0x18(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r14, 0x50(%rsp)
movq %r14, %rdi
callq 0x2b20d
movq %rax, 0x48(%rsp)
movq %rdx, %r12
movq (%rdx), %rdi
leaq 0xd0(%rsp), %rax
movq (%rax), %r13
movq (%r13), %rsi
movq 0x8(%r13), %rdx
leaq 0x78(%rsp), %rcx
callq 0x3e5db
movq 0x8(%rsp), %r14
movq (%r14), %rdi
movq 0x10(%r13), %rsi
movq 0x18(%r13), %rdx
leaq 0x88(%rsp), %rcx
callq 0x3ea4a
movq 0x40(%rsp), %r8
movl 0x14(%r13), %ecx
testl %ecx, %ecx
movl $0x0, %eax
cmovgl %ecx, %eax
movq %rax, 0x20(%rsp)
xorl %edx, %edx
cmpq 0x20(%rsp), %rdx
je 0x3e7ed
xorl %eax, %eax
cmpq %rax, %rcx
je 0x3e7e8
movq (%r14), %rsi
movsd (%rsi,%rdx,8), %xmm0
movq (%r8,%rdx,8), %rdi
addq 0x60(%rsp), %rdi
mulsd (%rsi,%rax,8), %xmm0
addsd (%rdi,%rax,8), %xmm0
movsd %xmm0, (%rdi,%rax,8)
incq %rax
jmp 0x3e7be
incq %rdx
jmp 0x3e7b5
movl (%r13), %edx
movsd 0x10(%rsp), %xmm8
subsd (%rsp), %xmm8
testl %edx, %edx
movl $0x0, %eax
cmovgl %edx, %eax
movq %rax, (%rsp)
xorl %edi, %edi
xorl %esi, %esi
movsd 0x56d08(%rip), %xmm7    # 0x95520
movq %r12, 0x70(%rsp)
cmpq (%rsp), %rdi
je 0x3e929
movq (%r14), %r8
movsd (%r8,%rdi,8), %xmm1
movq 0x18(%r13), %rax
movq (%rax), %r10
leaq 0x1(%rdi), %rax
movq %rax, 0x58(%rsp)
movl 0x4(%r13), %r14d
movapd %xmm7, %xmm0
subsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
mulsd 0x8(%r10,%rdi,8), %xmm0
movslq %esi, %rsi
testl %r14d, %r14d
movl $0x0, %eax
cmovgl %r14d, %eax
movq %rax, 0x10(%rsp)
xorl %r9d, %r9d
cmpq 0x10(%rsp), %r9
je 0x3e91a
movq (%r12), %rax
movsd (%rax,%r9,8), %xmm1
xorl %ebx, %ebx
xorl %r12d, %r12d
cmpq %rdx, %rbx
je 0x3e90a
movsd (%r8,%rbx,8), %xmm2
cmpq %rbx, %rdi
je 0x3e89e
xorpd %xmm3, %xmm3
jmp 0x3e8b3
movapd %xmm2, %xmm4
addsd %xmm2, %xmm4
movapd %xmm7, %xmm3
subsd %xmm4, %xmm3
mulsd %xmm8, %xmm3
addsd %xmm0, %xmm3
movsd 0x8(%r10,%rbx,8), %xmm4
incq %rbx
movapd %xmm7, %xmm5
subsd %xmm2, %xmm5
movslq %r12d, %r12
movq %rax, %rbp
movq %r14, %r11
subq $0x1, %r11
jb 0x3e888
movsd (%rbp), %xmm6
mulsd %xmm1, %xmm6
mulsd %xmm2, %xmm6
mulsd %xmm5, %xmm6
mulsd %xmm4, %xmm6
mulsd %xmm3, %xmm6
movq (%r15,%rsi,8), %rcx
addsd (%rcx,%r12,8), %xmm6
movsd %xmm6, (%rcx,%r12,8)
incq %r12
addq $0x8, %rbp
jmp 0x3e8d2
incq %rsi
incq %r9
movq 0x70(%rsp), %r12
jmp 0x3e86e
movq 0x58(%rsp), %rdi
movq 0x8(%rsp), %r14
jmp 0x3e81d
xorl %edx, %edx
xorl %esi, %esi
cmpq (%rsp), %rdx
je 0x3e9f7
movq (%r14), %rcx
movsd (%rcx,%rdx,8), %xmm0
movl 0x4(%r13), %edi
movapd %xmm7, %xmm1
subsd %xmm0, %xmm1
movslq %esi, %rsi
testl %edi, %edi
movl $0x0, %eax
cmovlel %eax, %edi
xorl %r8d, %r8d
cmpq %rdi, %r8
je 0x3e9ef
movq (%r12), %rax
movsd (%rax,%r8,8), %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movq %rcx, %r9
movq 0x20(%rsp), %r10
xorl %r11d, %r11d
movq 0x68(%rsp), %rbx
subq $0x1, %r10
jb 0x3e9e4
leaq -0x1(%r11), %rax
movapd %xmm8, %xmm3
cmpq %rdx, %rax
je 0x3e99e
xorpd %xmm3, %xmm3
movsd (%r9), %xmm4
movq 0x18(%r13), %rax
movq (%rax), %rax
mulsd 0x8(%rax,%rdx,8), %xmm4
addsd %xmm3, %xmm4
mulsd %xmm2, %xmm4
movq (%r15,%rsi,8), %rax
movsd (%rax,%rbx,8), %xmm3
addsd %xmm4, %xmm3
movsd %xmm3, (%rax,%rbx,8)
movq (%r15,%rbx,8), %rax
addsd (%rax,%rsi,8), %xmm4
movsd %xmm4, (%rax,%rsi,8)
incq %rbx
incq %r11
addq $0x8, %r9
jmp 0x3e986
incq %rsi
incq %r8
jmp 0x3e95b
incq %rdx
jmp 0x3e92d
movq 0x48(%rsp), %rdi
movq %r12, %rsi
callq 0x3929f
movq 0x50(%rsp), %r14
movq 0x10(%r14), %r14
jmp 0x3e721
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x3929f
movq 0x30(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3929f
movq 0x38(%rsp), %rax
movq %r15, %rdx
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq