// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
leaq 0xb0(%rsp), %r14
movl 0x5c(%r14), %eax
movq %rdi, %rbx
testl %eax, %eax
js 0x43a65
movq (%r14), %rcx
shlq $0x4, %rax
addq $0x10, %rax
xorl %edx, %edx
xorl %edi, %edi
movl 0x4(%rcx,%rdx), %esi
imull (%rcx,%rdx), %esi
addl %esi, %edi
addq $0x10, %rdx
cmpq %rdx, %rax
jne 0x43a50
jmp 0x43a67
xorl %edi, %edi
movl %edi, %esi
callq 0x3c6e5
movq %rax, 0x48(%rsp)
movq %rdx, (%rsp)
movl 0x50(%r14), %esi
movl $0x1, %edi
callq 0x3c6e5
movq %rax, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
movl $0x1, %edi
movl $0x1, %esi
callq 0x3c6e5
movq %rax, 0x40(%rsp)
movq %rdx, 0x8(%rsp)
testq %rbx, %rbx
je 0x43dff
leaq 0xb0(%rsp), %rax
movq (%rax), %rax
movl 0x4(%rax), %ecx
imull (%rax), %ecx
movslq %ecx, %rcx
movq (%rsp), %rax
leaq (%rax,%rcx,8), %r13
shlq $0x3, %rcx
movq %rcx, 0x28(%rsp)
movq %rbx, %rdi
callq 0x2eaee
movsd %xmm0, 0x50(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
movq %rbx, 0x68(%rsp)
movq %rbx, %rdi
callq 0x2e851
movq %rax, 0x58(%rsp)
movq %rdx, 0x10(%rsp)
movq (%rdx), %rdi
leaq 0xb0(%rsp), %rax
movq (%rax), %rbx
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
leaq 0x30(%rsp), %rcx
callq 0x43994
movq %rbx, %r11
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rbx), %rdx
movq 0x18(%rbx), %rcx
movq %rcx, 0x18(%rsp)
testl %edx, %edx
jle 0x43ba2
movq %rdx, %rsi
shrq $0x20, %rsi
movq 0x8(%rsp), %rcx
movq (%rcx), %rdi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %rsi, %r8
decq %r8
xorl %r9d, %r9d
movq 0x18(%rsp), %rcx
movq (%rcx,%r9,8), %rcx
movsd (%rcx), %xmm0
cmpl $0x2, %esi
jl 0x43b94
xorl %r10d, %r10d
movsd 0x8(%rcx,%r10,8), %xmm1
mulsd (%rax,%r10,8), %xmm1
addsd %xmm1, %xmm0
incq %r10
cmpq %r10, %r8
jne 0x43b7b
movsd %xmm0, (%rdi,%r9,8)
incq %r9
cmpq %rdx, %r9
jne 0x43b66
movslq 0x14(%r11), %rdx
testq %rdx, %rdx
movsd 0x5e96e(%rip), %xmm8    # 0xa2520
movsd 0x60(%rsp), %xmm9
movsd 0x50(%rsp), %xmm10
jle 0x43bf4
xorl %ecx, %ecx
movq (%r13,%rcx,8), %rsi
addq 0x28(%rsp), %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 0x43bd0
incq %rcx
cmpq %rdx, %rcx
jne 0x43bc4
movq %r11, 0x20(%rsp)
movslq (%r11), %rsi
testq %rsi, %rsi
jle 0x43d0c
movq 0x18(%rsp), %rcx
movq (%rcx), %rdi
movq 0x20(%rsp), %rcx
movl 0x4(%rcx), %r8d
movapd %xmm9, %xmm0
subsd %xmm10, %xmm0
xorl %r9d, %r9d
xorl %r10d, %r10d
movq %r9, %r11
incq %r9
testl %r8d, %r8d
jle 0x43d03
movsd (%rax,%r11,8), %xmm2
movq 0x10(%rsp), %rcx
movq (%rcx), %rbx
movapd %xmm8, %xmm1
subsd %xmm2, %xmm1
mulsd %xmm2, %xmm1
movq %r9, 0x70(%rsp)
mulsd (%rdi,%r9,8), %xmm1
movslq %r10d, %r10
xorl %r14d, %r14d
movsd (%rbx,%r14,8), %xmm2
movq (%rsp), %rcx
movq (%rcx,%r10,8), %r12
xorl %r9d, %r9d
xorl %ebp, %ebp
movsd (%rax,%r9,8), %xmm3
cmpq %r9, %r11
je 0x43c85
xorpd %xmm4, %xmm4
jmp 0x43c9a
movapd %xmm3, %xmm5
addsd %xmm3, %xmm5
movapd %xmm8, %xmm4
subsd %xmm5, %xmm4
mulsd %xmm0, %xmm4
addsd %xmm1, %xmm4
movsd 0x8(%rdi,%r9,8), %xmm5
incq %r9
movapd %xmm8, %xmm6
subsd %xmm3, %xmm6
movslq %ebp, %rbp
leaq (%r12,%rbp,8), %r15
xorl %ecx, %ecx
movsd (%rbx,%rcx,8), %xmm7
mulsd %xmm2, %xmm7
mulsd %xmm3, %xmm7
mulsd %xmm6, %xmm7
mulsd %xmm5, %xmm7
mulsd %xmm4, %xmm7
addsd (%r15,%rcx,8), %xmm7
movsd %xmm7, (%r15,%rcx,8)
incq %rcx
cmpq %rcx, %r8
jne 0x43cba
addq %rcx, %rbp
cmpq %rsi, %r9
jne 0x43c74
incq %r10
incq %r14
cmpq %r8, %r14
jne 0x43c61
movq 0x70(%rsp), %r9
cmpq %rsi, %r9
jne 0x43c26
testl %esi, %esi
jle 0x43dde
subsd %xmm10, %xmm9
movq 0x20(%rsp), %rcx
movl 0x4(%rcx), %edi
movl %edx, %r8d
xorl %r9d, %r9d
xorl %r10d, %r10d
testl %edi, %edi
jle 0x43dd2
movsd (%rax,%r9,8), %xmm0
movq 0x10(%rsp), %rcx
movq (%rcx), %r11
movapd %xmm8, %xmm1
subsd %xmm0, %xmm1
movslq %r10d, %r10
leaq 0x1(%r9), %rbx
xorl %r14d, %r14d
testl %edx, %edx
jle 0x43dc7
movsd (%r11,%r14,8), %xmm2
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
movq 0x18(%rsp), %rcx
movq (%rcx), %r12
movq (%rsp), %rcx
movq (%rcx,%r10,8), %rbp
addq 0x28(%rsp), %rbp
xorl %ecx, %ecx
movapd %xmm9, %xmm3
cmpq %rcx, %rbx
je 0x43d8a
xorpd %xmm3, %xmm3
movsd (%rax,%rcx,8), %xmm4
mulsd 0x8(%r12,%r9,8), %xmm4
addsd %xmm3, %xmm4
mulsd %xmm2, %xmm4
movsd (%rbp,%rcx,8), %xmm3
addsd %xmm4, %xmm3
movsd %xmm3, (%rbp,%rcx,8)
movq (%r13,%rcx,8), %r15
addsd (%r15,%r10,8), %xmm4
movsd %xmm4, (%r15,%r10,8)
incq %rcx
cmpq %rcx, %r8
jne 0x43d7c
incq %r10
incq %r14
cmpq %rdi, %r14
jne 0x43d53
incq %r9
cmpq %rsi, %r9
jne 0x43d2a
movq 0x58(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3dbad
movq 0x68(%rsp), %rbx
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
jne 0x43ad6
movq 0x40(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3dbad
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3dbad
movq 0x48(%rsp), %rax
movq (%rsp), %rdx
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq