// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/data.c
// Function: covariance_2d
matrix covariance_2d(Instanceptr myptr, matrix currentmean)
{
 /*!Last Changed 30.01.2005*/
 matrix result;
 Instanceptr tmp;
 int dim, matrixdim, i, j, k, m, size = 0, x, y;
 double fx, fy, meanx, meany;
 dim  = current_dataset->multifeaturecount - 1;
 matrixdim = multifeaturecount_2d(current_dataset);
 result = matrix_alloc(matrixdim, matrixdim);
 tmp = myptr;
 while (tmp)
  {
   x = 0;
   /*For dimensions x_ix_j*/
   for (i = 0; i < dim; i++)
     for (j = i; j < dim; j++)
      {
       y = 0;
       fx = real_feature(tmp, i) * real_feature(tmp, j);
       meanx = currentmean.values[0][x];
       /*with dimensions x_kx_m*/
       for (k = 0; k < dim; k++)
         for (m = k; m < dim; m++)
          {           
           fy = real_feature(tmp, k) * real_feature(tmp, m);
           meany = currentmean.values[0][y];
           result.values[x][y] += (fx - meanx) * (fy - meany);
           y++;
          }
       /*with dimensions x_k*/
       for (k = 0; k < dim; k++)
        {
         fy = real_feature(tmp, k);
         meany = currentmean.values[0][y];
         result.values[x][y] += (fx - meanx) * (fy - meany);
         y++;
        }
       x++;
      }
   /*For dimensions x_i*/
   for (i = 0; i < dim; i++)
    {
     y = 0;
     fx = real_feature(tmp, i);
     meanx = currentmean.values[0][x];
     /*with dimensions x_kx_m*/
     for (k = 0; k < dim; k++)
       for (m = k; m < dim; m++)
        {           
         fy = real_feature(tmp, k) * real_feature(tmp, m);
         meany = currentmean.values[0][y];
         result.values[x][y] += (fx - meanx) * (fy - meany);
         y++;
        }
     /*with dimensions x_k*/
     for (k = 0; k < dim; k++)
      {
       fy = real_feature(tmp, k);
       meany = currentmean.values[0][y];
       result.values[x][y] += (fx - meanx) * (fy - meany);
       y++;
      }
     x++;
    }
   tmp = tmp->next;
   size++;
  }
 for (i = 0; i < matrixdim; i++)
   for (j = 0; j < matrixdim; j++)
     result.values[i][j] /= (size - 1);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r14
movq %rdi, %r12
leaq 0xc480c(%rip), %rax     # 0xd5870
movq (%rax), %rdi
movl 0x1c0(%rdi), %r15d
callq 0x1372c
movl %eax, %ebp
movl %eax, %edi
movl %eax, %esi
callq 0x3d79d
movq %rdx, %rbx
testq %r12, %r12
je 0x11352
movl %ebp, 0x44(%rsp)
movq %rax, 0x50(%rsp)
leal -0x1(%r15), %r13d
xorl %eax, %eax
movq %rbx, 0x30(%rsp)
movq %r14, 0x28(%rsp)
movq %r15, 0x48(%rsp)
movl %r13d, 0x4(%rsp)
movq %rax, 0x58(%rsp)
cmpl $0x2, %r15d
jl 0x11325
xorl %esi, %esi
xorl %ecx, %ecx
movq %r12, 0x38(%rsp)
movslq %ecx, %rcx
movl %esi, %ebp
movq %rsi, 0x60(%rsp)
movq %rcx, 0x8(%rsp)
movq %r12, %rdi
callq 0x2ed6a
movsd %xmm0, 0x20(%rsp)
movq %r12, %rdi
movl %ebp, 0x14(%rsp)
movl %ebp, %esi
callq 0x2ed6a
movapd %xmm0, %xmm1
mulsd 0x20(%rsp), %xmm1
movq (%r14), %rax
movq 0x8(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm1
xorl %ebx, %ebx
movl $0x0, (%rsp)
movsd %xmm1, 0x18(%rsp)
movslq %ebx, %rbx
movl (%rsp), %ebp
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r12
movq 0x38(%rsp), %r13
movq %rbx, %r15
incq %rbx
movq %r13, %rdi
movl (%rsp), %esi
callq 0x2ed6a
movsd %xmm0, 0x20(%rsp)
movq %r13, %rdi
movl %ebp, %esi
callq 0x2ed6a
movsd 0x18(%rsp), %xmm1
mulsd 0x20(%rsp), %xmm0
movq (%r12), %rax
subsd (%rax,%r15,8), %xmm0
movq 0x8(%rsp), %rax
movq (%r14,%rax,8), %rax
mulsd %xmm1, %xmm0
addsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%rax,%r15,8)
incl %ebp
cmpl 0x4(%rsp), %ebp
jl 0x1112b
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
movl 0x4(%rsp), %ecx
cmpl %ecx, %eax
jne 0x11116
movl %ecx, %r13d
movslq %ebx, %r15
xorl %ebp, %ebp
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %r14
movq 0x38(%rsp), %r12
movq %r12, %rdi
movl %ebp, %esi
callq 0x2ed6a
movq 0x8(%rsp), %rcx
movq (%r14), %rax
subsd (%rax,%r15,8), %xmm0
movq (%rbx,%rcx,8), %rax
mulsd 0x18(%rsp), %xmm0
addsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%rax,%r15,8)
incq %r15
incl %ebp
cmpl %ebp, %r13d
jne 0x111aa
incq %rcx
movl 0x14(%rsp), %ebp
incl %ebp
cmpl %r13d, %ebp
movq 0x60(%rsp), %rsi
jl 0x110cf
incl %esi
cmpl %r13d, %esi
jne 0x110c5
cmpl $0x2, 0x48(%rsp)
jl 0x11325
movslq %ecx, %rcx
xorl %esi, %esi
movq %rcx, 0x8(%rsp)
movq %r12, %rdi
movl %esi, 0x14(%rsp)
callq 0x2ed6a
movapd %xmm0, %xmm1
movq (%r14), %rax
movq 0x8(%rsp), %rcx
subsd (%rax,%rcx,8), %xmm1
xorl %r15d, %r15d
movl $0x0, (%rsp)
movsd %xmm1, 0x18(%rsp)
movslq %r15d, %r15
movl (%rsp), %r13d
movq 0x30(%rsp), %r14
movq 0x28(%rsp), %r12
movq 0x38(%rsp), %rbp
movq %r15, %rbx
incq %r15
movq %rbp, %rdi
movl (%rsp), %esi
callq 0x2ed6a
movsd %xmm0, 0x20(%rsp)
movq %rbp, %rdi
movl %r13d, %esi
callq 0x2ed6a
movsd 0x18(%rsp), %xmm1
mulsd 0x20(%rsp), %xmm0
movq (%r12), %rax
subsd (%rax,%rbx,8), %xmm0
movq 0x8(%rsp), %rax
movq (%r14,%rax,8), %rax
mulsd %xmm1, %xmm0
addsd (%rax,%rbx,8), %xmm0
movsd %xmm0, (%rax,%rbx,8)
incl %r13d
cmpl 0x4(%rsp), %r13d
jl 0x1125c
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
movl 0x4(%rsp), %ecx
cmpl %ecx, %eax
jne 0x11246
movl %ecx, %r13d
movslq %r15d, %r15
xorl %ebp, %ebp
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %r14
movq 0x38(%rsp), %r12
movq %r12, %rdi
movl %ebp, %esi
callq 0x2ed6a
movq 0x8(%rsp), %rcx
movq (%r14), %rax
subsd (%rax,%r15,8), %xmm0
movq (%rbx,%rcx,8), %rax
mulsd 0x18(%rsp), %xmm0
addsd (%rax,%r15,8), %xmm0
movsd %xmm0, (%rax,%r15,8)
incq %r15
incl %ebp
cmpl %ebp, %r13d
jne 0x112db
incq %rcx
movl 0x14(%rsp), %esi
incl %esi
cmpl %r13d, %esi
jne 0x11214
movq 0x10(%r12), %r12
movq 0x58(%rsp), %rcx
leal 0x1(%rcx), %eax
testq %r12, %r12
movq 0x48(%rsp), %r15
jne 0x110ad
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movq 0x50(%rsp), %rax
movl 0x44(%rsp), %ebp
jmp 0x1135a
movsd 0x94a4e(%rip), %xmm0    # 0xa5da8
testl %ebp, %ebp
jle 0x11386
movl %ebp, %edi
xorl %ecx, %ecx
movq (%rbx,%rcx,8), %rdx
xorl %esi, %esi
movsd (%rdx,%rsi,8), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rdi
jne 0x11368
incq %rcx
cmpq %rdi, %rcx
jne 0x11362
movq %rbx, %rdx
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq