// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/mlp.c
// Function: hessian_matrix_cls
matrix hessian_matrix_cls(Mlpnetwork N, Instanceptr train)
{
	/*!Last Changed 18.06.2005*/
	int weightcount, firstlayer, k, h, hprime, i, iprime, index1, index2, classno;
	double mul, yk, zh, sum1, sum2, zhprime, xi, xiprime, vkh, vkhprime;
	Instanceptr tmp;
	matrix result, testY, testH, inst;
	weightcount = number_of_weights_in_mlp_network(N);
	result = matrix_alloc(weightcount, weightcount);
	testY = matrix_alloc(1, N.P.classnum);
	testH = matrix_alloc(1, N.P.hidden[0]);
	firstlayer = N.weights[0].row * N.weights[0].col;
	tmp = train;
	while (tmp)
	 {
		 classno = give_classno(tmp);
		 inst = instance_to_matrix(tmp);
  	calculate_hidden_values(inst.values[0], N.weights[0], &testH);
		 calculate_output_values_cls(testH.values[0], N.weights[1], &testY);
			/*Both in the second layer*/
   for (k = 0; k < N.weights[1].row; k++)
			 {
					yk = testY.values[0][k];
				 for (h = 0; h < N.weights[1].col; h++)
					 {
						 zh = testH.values[0][h];
  					for (hprime = 0; hprime < N.weights[1].col; hprime++)
							 {
									zhprime = testH.values[0][hprime];
									index1 = firstlayer + k * N.weights[1].col + h;
									index2 = firstlayer + k * N.weights[1].col + hprime;
									result.values[index1][index2] += zh * zhprime * yk * (1 - yk);
							 }
					 }
			 }
   /*Both in the first 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++)
					 {
						 xi = inst.values[0][i];
						 index2 = 0;
						 for (hprime = 0; hprime < N.weights[0].row; hprime++)
							 {
								 zhprime = testH.values[0][hprime];
								 if (h == hprime)
									 {
           sum1 = 0;
											for (k = 0; k < N.weights[1].row; k++)
											 {
												 vkhprime = N.weights[1].values[k][hprime + 1];
													yk = testY.values[0][k];
												 if (k == classno)
														 sum1 += vkhprime * (yk - 1);
													else
														 sum1 += vkhprime * yk;
											 }
											sum1 = sum1 * (1 - 2 * zhprime);
									 }
									else
										 sum1 = 0;
									sum2 = 0;
         for (k = 0; k < N.weights[1].row; k++)
									 {
										 vkh = N.weights[1].values[k][h + 1];
											vkhprime = N.weights[1].values[k][hprime + 1];
											yk = testY.values[0][k];
											sum2 += vkh * vkhprime * yk * (1 - yk);
									 }
         sum2 = zh * (1 - zh) * sum2;
								 for (iprime = 0; iprime < N.weights[0].col; iprime++)
									 { 
										 xiprime = inst.values[0][iprime];
    							mul = xi * xiprime * zhprime * (1 - zhprime);
           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 (k = 0; k < N.weights[1].row; k++)
							 {
								 yk = testY.values[0][k];
								 for (hprime = 0; hprime < N.weights[1].col; hprime++)
									 {
										 if (h == hprime - 1)
												 if (k == classno)
  												 sum1 = yk - 1;
													else
														 sum1 = yk;
											else
											  sum1 = 0;
											zhprime = testH.values[0][hprime];
											vkh = N.weights[1].values[k][h + 1];
											sum2 = zhprime * vkh * yk * (1 - yk);
           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
movq %rdi, %r14
leaq 0xc0(%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 0x3e0fa
movl (%rcx), %edx
imull -0x4(%rcx), %edx
addl %edx, %edi
addq $0x10, %rcx
jmp 0x3e0e6
movl %edi, %esi
callq 0x380d3
movq %rax, 0x50(%rsp)
movq %rdx, %r15
leaq 0xc0(%rsp), %r12
movl 0x8(%r12), %esi
pushq $0x1
popq %rbp
movl %ebp, %edi
callq 0x380d3
movq %rdx, %r13
leaq 0x78(%rsp), %rcx
movq %rax, 0x48(%rsp)
movq %rax, (%rcx)
movq %rdx, 0x8(%rcx)
movl 0x50(%r12), %esi
movl %ebp, %edi
callq 0x380d3
leaq 0x68(%rsp), %rcx
movq %rax, 0x40(%rsp)
movq %rax, (%rcx)
movq %rdx, 0x8(%rsp)
movq %rdx, 0x8(%rcx)
movl 0x4(%rbx), %eax
imull (%rbx), %eax
movl %eax, 0x14(%rsp)
testq %r14, %r14
je 0x3e5a5
movq %r14, %rdi
callq 0x2b47e
movl %eax, %ebp
movq %r14, 0x60(%rsp)
movq %r14, %rdi
callq 0x2b20d
movq %rax, 0x58(%rsp)
movq %rdx, 0x28(%rsp)
movq (%rdx), %rdi
leaq 0xc0(%rsp), %rax
movq (%rax), %r12
movq (%r12), %rsi
movq 0x8(%r12), %rdx
leaq 0x68(%rsp), %rcx
callq 0x3e5db
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x10(%r12), %rsi
movq 0x18(%r12), %rdx
leaq 0x78(%rsp), %rcx
callq 0x3eaa2
movsd 0x57350(%rip), %xmm8    # 0x95520
movl 0x10(%r12), %eax
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
xorl %ecx, %ecx
cmpq %rax, %rcx
je 0x3e285
movq (%r13), %rdx
movsd (%rdx,%rcx,8), %xmm0
movl 0x14(%r12), %edx
movl %edx, %edi
imull %ecx, %edi
movl 0x14(%rsp), %r9d
addl %r9d, %edi
movapd %xmm8, %xmm1
subsd %xmm0, %xmm1
testl %edx, %edx
movl $0x0, %esi
cmovgl %edx, %esi
movslq %edi, %rdi
leaq (%r15,%rdi,8), %rdi
movl %edx, %r8d
imull %ecx, %r8d
addl %r9d, %r8d
movslq %r8d, %r8
shlq $0x3, %r8
xorl %r9d, %r9d
cmpq %rsi, %r9
je 0x3e27d
movq 0x8(%rsp), %r10
movq (%r10), %r10
movsd (%r10,%r9,8), %xmm2
xorl %r11d, %r11d
cmpq %r11, %rdx
je 0x3e278
movsd (%r10,%r11,8), %xmm3
mulsd %xmm2, %xmm3
mulsd %xmm0, %xmm3
mulsd %xmm1, %xmm3
movq (%rdi,%r9,8), %rbx
addq %r8, %rbx
addsd (%rbx,%r11,8), %xmm3
movsd %xmm3, (%rbx,%r11,8)
incq %r11
jmp 0x3e249
incq %r9
jmp 0x3e233
incq %rcx
jmp 0x3e1e1
movl (%r12), %esi
movl %ebp, %ecx
testl %esi, %esi
movl $0x0, %edx
movq %rsi, 0x30(%rsp)
cmovgl %esi, %edx
movq %rdx, 0x38(%rsp)
xorl %edi, %edi
xorl %r8d, %r8d
movsd 0x57b03(%rip), %xmm9    # 0x95db0
cmpq 0x38(%rsp), %rdi
je 0x3e435
movq 0x8(%rsp), %rdx
movq (%rdx), %r9
movsd (%r9,%rdi,8), %xmm1
movl 0x4(%r12), %edx
movapd %xmm8, %xmm0
subsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
movslq %r8d, %r8
testl %edx, %edx
movl $0x0, %esi
cmovgl %edx, %esi
movq %rsi, 0x18(%rsp)
xorl %r10d, %r10d
cmpq 0x18(%rsp), %r10
je 0x3e42d
movq 0x28(%rsp), %rsi
movq (%rsi), %rbx
movq %r10, 0x20(%rsp)
movsd (%rbx,%r10,8), %xmm1
xorl %r14d, %r14d
xorl %r11d, %r11d
cmpq 0x30(%rsp), %r14
je 0x3e41d
movsd (%r9,%r14,8), %xmm2
xorpd %xmm3, %xmm3
xorpd %xmm4, %xmm4
cmpq %r14, %rdi
jne 0x3e384
xorpd %xmm5, %xmm5
xorl %ebp, %ebp
cmpq %rbp, %rax
je 0x3e36f
movq (%r13), %r10
movsd (%r10,%rbp,8), %xmm6
movapd %xmm6, %xmm4
addsd %xmm9, %xmm4
cmpq %rbp, %rcx
je 0x3e356
movapd %xmm6, %xmm4
movq 0x18(%r12), %r10
movq (%r10,%rbp,8), %r10
mulsd 0x8(%r10,%rdi,8), %xmm4
addsd %xmm4, %xmm5
incq %rbp
jmp 0x3e335
movapd %xmm2, %xmm6
addsd %xmm2, %xmm6
movapd %xmm8, %xmm4
subsd %xmm6, %xmm4
mulsd %xmm5, %xmm4
xorl %r10d, %r10d
cmpq %r10, %rax
je 0x3e3c7
movq 0x18(%r12), %rbp
movq (%rbp,%r10,8), %rbp
movsd 0x8(%rbp,%rdi,8), %xmm5
movq (%r13), %rsi
movsd (%rsi,%r10,8), %xmm6
mulsd 0x8(%rbp,%r14,8), %xmm5
mulsd %xmm6, %xmm5
movapd %xmm8, %xmm7
subsd %xmm6, %xmm7
mulsd %xmm5, %xmm7
addsd %xmm7, %xmm3
incq %r10
jmp 0x3e387
mulsd %xmm0, %xmm3
addsd %xmm3, %xmm4
movapd %xmm8, %xmm3
subsd %xmm2, %xmm3
movslq %r11d, %r11
movq %rbx, %rbp
movq %rdx, %r10
subq $0x1, %r10
jb 0x3e415
movsd (%rbp), %xmm5
mulsd %xmm1, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm3, %xmm5
mulsd %xmm4, %xmm5
movq (%r15,%r8,8), %rsi
addsd (%rsi,%r11,8), %xmm5
movsd %xmm5, (%rsi,%r11,8)
incq %r11
addq $0x8, %rbp
jmp 0x3e3e1
incq %r14
jmp 0x3e311
incq %r8
movq 0x20(%rsp), %r10
incq %r10
jmp 0x3e2ed
incq %rdi
jmp 0x3e2ad
xorl %edx, %edx
xorl %esi, %esi
cmpq 0x38(%rsp), %rdx
je 0x3e588
movq 0x8(%rsp), %rdi
movq (%rdi), %rdi
movq %rdi, 0x30(%rsp)
movsd (%rdi,%rdx,8), %xmm0
movl 0x4(%r12), %r8d
movapd %xmm8, %xmm1
subsd %xmm0, %xmm1
movslq %esi, %rsi
testl %r8d, %r8d
movl $0x0, %edi
cmovlel %edi, %r8d
movq %r8, 0x18(%rsp)
xorl %r8d, %r8d
cmpq 0x18(%rsp), %r8
je 0x3e580
movq 0x28(%rsp), %rdi
movq (%rdi), %rdi
movq %r8, 0x20(%rsp)
movsd (%rdi,%r8,8), %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
xorl %r10d, %r10d
movl 0x14(%rsp), %r11d
cmpq %rax, %r10
je 0x3e570
movq (%r13), %rdi
movl 0x14(%r12), %ebx
testl %ebx, %ebx
movl $0x0, %r8d
cmovlel %r8d, %ebx
movsd (%rdi,%r10,8), %xmm3
movapd %xmm3, %xmm4
addsd %xmm9, %xmm4
cmpq %rcx, %r10
je 0x3e4df
movapd %xmm3, %xmm4
movapd %xmm8, %xmm5
subsd %xmm3, %xmm5
movslq %r11d, %r14
negq %rbx
movq 0x30(%rsp), %rdi
xorl %r8d, %r8d
xorl %ebp, %ebp
cmpq %r8, %rbx
je 0x3e565
leaq -0x1(%rbp), %r9
movapd %xmm4, %xmm6
cmpq %rdx, %r9
je 0x3e50e
xorpd %xmm6, %xmm6
movsd (%rdi), %xmm7
movq 0x18(%r12), %r9
movq (%r9,%r10,8), %r9
mulsd 0x8(%r9,%rdx,8), %xmm7
mulsd %xmm3, %xmm7
mulsd %xmm5, %xmm7
addsd %xmm6, %xmm7
mulsd %xmm2, %xmm7
movq (%r15,%rsi,8), %r9
movsd (%r9,%r14,8), %xmm6
addsd %xmm7, %xmm6
movsd %xmm6, (%r9,%r14,8)
movq (%r15,%r14,8), %r9
addsd (%r9,%rsi,8), %xmm7
movsd %xmm7, (%r9,%rsi,8)
incq %r14
incq %rbp
decq %r8
addq $0x8, %rdi
jmp 0x3e4f8
subl %r8d, %r11d
incq %r10
jmp 0x3e4a9
incq %rsi
movq 0x20(%rsp), %r8
incq %r8
jmp 0x3e47b
incq %rdx
jmp 0x3e439
movq 0x58(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x3929f
movq 0x60(%rsp), %r14
movq 0x10(%r14), %r14
jmp 0x3e160
movq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x3929f
movq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3929f
movq 0x50(%rsp), %rax
movq %r15, %rdx
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq