// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/matrix.c
// Function: jacobi
void jacobi(matrix matrix2,double **d,matrix *v)
{
	/*!Last Changed 02.02.2004 added safemalloc*/
 /*Computes the eigenvectors and eigenvalues of a SYMMETRIC matrix*/
 int j,iq,ip,i,n=matrix2.row;
 double tresh,theta,tau,t,sm,s,h,g,c;
 double *b;
 double *z;
 matrix matrix1 = matrix_copy(matrix2);
 (*v) = matrix_alloc(matrix2.row,matrix2.col);
 (*d) = (double *)safemalloc(n*sizeof(double), "jacobi", 7);
 b = (double *)safemalloc(n*sizeof(double), "jacobi", 8);
 z = (double *)safemalloc(n*sizeof(double), "jacobi", 9);
 for (ip=1;ip<=n;ip++)
  {
   for (iq=1;iq<=n;iq++)
     (*v).values[ip-1][iq-1]=0.0;
   (*v).values[ip-1][ip-1]=1.0;
  }
 for (ip=1;ip<=n;ip++)
  {
   b[ip-1]=matrix1.values[ip-1][ip-1];
   (*d)[ip-1]=b[ip-1];
   z[ip-1]=0.0;
  }
 for (i=1;i<=50;i++)
  {
   sm = 0.0;
   for (ip=1;ip<=n-1;ip++)
     for (iq=ip+1;iq<=n;iq++)
       sm += (double)fabs(matrix1.values[ip-1][iq-1]);
   if (sm==0.0)
     goto devam;
   if (i<4)
     tresh=0.2*sm/pow(n,2);
   else
     tresh=0.0;
   for (ip=1;ip<=n-1;ip++)
    {
     for (iq=ip+1;iq<=n;iq++)
      {
       g = 100.0*(double)fabs(matrix1.values[ip-1][iq-1]);
       if ((i > 4)&&((double)fabs((*d)[ip-1])+g==(double)fabs((*d)[ip-1]))&&((double)fabs((*d)[iq-1])+g==(double)fabs((*d)[iq-1])))
         matrix1.values[ip-1][iq-1]=0.0;
       else
         if ((double)fabs(matrix1.values[ip-1][iq-1])>tresh)
          {
           h = (*d)[iq-1]-(*d)[ip-1];
           if ((double)fabs(h)+g==(double)fabs(h))
             t=matrix1.values[ip-1][iq-1]/h;
           else
            {
             theta=0.5*h/matrix1.values[ip-1][iq-1];
             t = 1.0/((double)fabs(theta)+sqrt(1.0+pow(theta,2)));
             if (theta < 0.0)
               t = -t;
            }
           c= 1.0/sqrt(1+pow(t,2));
           s = t*c;
           tau = s/(1.0+c);
           h = t*matrix1.values[ip-1][iq-1];
           z[ip-1] -= h;
           z[iq-1] += h;
           (*d)[ip-1] -= h;
           (*d)[iq-1] += h;
           matrix1.values[ip-1][iq-1]=0.0;
           for (j=1;j<=ip-1;j++)
            {
             g=matrix1.values[j-1][ip-1];
             h=matrix1.values[j-1][iq-1];
             matrix1.values[j-1][ip-1]=g-s*(h+g*tau);
             matrix1.values[j-1][iq-1]=h+s*(g-h*tau);
            }
           for (j=ip+1;j<=iq-1;j++)
            {
             g=matrix1.values[ip-1][j-1];
             h=matrix1.values[j-1][iq-1];
             matrix1.values[ip-1][j-1] = g-s*(h+g*tau);
             matrix1.values[j-1][iq-1] = h+s*(g-h*tau);
            }
           for (j=iq+1;j<=n;j++)
            {
             g = matrix1.values[ip-1][j-1];
             h = matrix1.values[iq-1][j-1];
             matrix1.values[ip-1][j-1] = g-s*(h+g*tau);
             matrix1.values[iq-1][j-1] = h+s*(g-h*tau);
            }
           for (j=1;j<=n;j++)
            {
             g = (*v).values[j-1][ip-1];
             h = (*v).values[j-1][iq-1];
             (*v).values[j-1][ip-1] = g-s*(h+g*tau);
             (*v).values[j-1][iq-1] = h+s*(g-h*tau);
            }
          }
      }
    }
   for (ip=1;ip<=n;ip++)
    {
     b[ip-1] = b[ip-1]+z[ip-1];
     (*d)[ip-1] = b[ip-1];
     z[ip-1] = 0.0;
    }
  }
devam:
 safe_free(z);
 safe_free(b);
 matrix_free(matrix1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rdi, %r12
movq %rdi, %rbp
shrq $0x20, %rbp
callq 0x383f4
movq %rax, 0x8(%rsp)
movq %rdx, %r13
movl %r12d, %edi
movl %ebp, %esi
callq 0x380d3
movq %rax, (%rbx)
movq %rdx, 0x8(%rbx)
movslq %r12d, %rbp
leaq (,%rbp,8), %r15
leaq 0x5f160(%rip), %rsi     # 0x99f4f
pushq $0x7
popq %rdx
movq %r15, %rdi
callq 0x34f59
movq %rax, (%r14)
pushq $0x8
popq %rdx
movq %r15, %rdi
leaq 0x5f145(%rip), %rsi     # 0x99f4f
callq 0x34f59
movq %rax, (%rsp)
pushq $0x9
popq %rdx
movq %r15, %rdi
leaq 0x5f12f(%rip), %rsi     # 0x99f4f
callq 0x34f59
leal 0x1(%rbp), %ecx
xorl %edx, %edx
testl %ebp, %ebp
cmovgl %r12d, %edx
leal 0x1(%rdx), %esi
leaq -0x1(%rcx), %rdi
pushq $0x1
popq %r8
movabsq $0x3ff0000000000000, %r9 # imm = 0x3FF0000000000000
cmpq %rsi, %r8
je 0x3ae74
movq 0x8(%rbx), %r10
xorl %r11d, %r11d
cmpq %r11, %rdi
je 0x3ae65
movq -0x8(%r10,%r8,8), %r15
andq $0x0, (%r15,%r11,8)
incq %r11
jmp 0x3ae51
movq -0x8(%r10,%r8,8), %r10
movq %r9, -0x8(%r10,%r8,8)
incq %r8
jmp 0x3ae45
movl %edx, %r8d
xorl %edx, %edx
movq (%rsp), %r15
cmpq %rdx, %r8
je 0x3aea4
movq (%r13,%rdx,8), %rsi
movsd (%rsi,%rdx,8), %xmm0
movsd %xmm0, (%r15,%rdx,8)
movq (%r14), %rsi
movsd %xmm0, (%rsi,%rdx,8)
andq $0x0, (%rax,%rdx,8)
incq %rdx
jmp 0x3ae7d
cvtsi2sd %r12d, %xmm0
mulsd %xmm0, %xmm0
movslq %r12d, %rdx
movl %ecx, %esi
decq %rsi
pushq $0x1
popq %rdi
pushq $0x1
popq %r11
movapd 0x5b31c(%rip), %xmm1    # 0x961e0
xorpd %xmm2, %xmm2
movsd 0x5cec0(%rip), %xmm3    # 0x97d90
movsd 0x5aed0(%rip), %xmm4    # 0x95da8
movsd 0x5a640(%rip), %xmm5    # 0x95520
movapd 0x5b2e8(%rip), %xmm6    # 0x961d0
movsd 0x5ae30(%rip), %xmm7    # 0x95d20
movq %r8, 0x10(%rsp)
cmpl $0x33, %edi
je 0x3b2e2
xorpd %xmm8, %xmm8
movq %r11, %rcx
cmpq %rdx, %rcx
jge 0x3af36
movq %rcx, %r8
leal 0x1(%r8), %r9d
cmpl %r12d, %r9d
jg 0x3af31
movq -0x8(%r13,%rcx,8), %r9
movsd (%r9,%r8,8), %xmm9
andpd %xmm1, %xmm9
addsd %xmm9, %xmm8
incq %r8
jmp 0x3af0e
incq %rcx
jmp 0x3af06
ucomisd %xmm2, %xmm8
jne 0x3af43
jnp 0x3b2e2
mulsd %xmm3, %xmm8
cmpl $0x4, %edi
jb 0x3af54
xorpd %xmm8, %xmm8
jmp 0x3af59
divsd %xmm0, %xmm8
xorl %r10d, %r10d
pushq $0x2
popq %r15
cmpq %rdx, %r11
jge 0x3b2a2
movslq %r15d, %r9
movq %r9, 0x20(%rsp)
movq %r15, 0x18(%rsp)
cmpq %rdx, %r9
jg 0x3b28e
movq -0x8(%r13,%r11,8), %rbp
movsd -0x8(%rbp,%r9,8), %xmm11
movapd %xmm11, %xmm10
andpd %xmm1, %xmm10
movapd %xmm10, %xmm9
mulsd %xmm4, %xmm9
cmpl $0x5, %edi
jb 0x3aff0
movq (%r14), %rcx
movsd -0x8(%rcx,%r11,8), %xmm12
andpd %xmm1, %xmm12
movapd %xmm9, %xmm13
addsd %xmm12, %xmm13
ucomisd %xmm12, %xmm13
jne 0x3aff0
jp 0x3aff0
movsd -0x8(%rcx,%r9,8), %xmm12
andpd %xmm1, %xmm12
movapd %xmm9, %xmm13
addsd %xmm12, %xmm13
ucomisd %xmm12, %xmm13
jne 0x3aff0
jp 0x3aff0
andq $0x0, -0x8(%rbp,%r9,8)
jmp 0x3b283
ucomisd %xmm8, %xmm10
jbe 0x3b283
movq (%r14), %rcx
movsd -0x8(%rcx,%r9,8), %xmm10
subsd -0x8(%rcx,%r11,8), %xmm10
movapd %xmm10, %xmm12
andpd %xmm1, %xmm12
addsd %xmm12, %xmm9
ucomisd %xmm12, %xmm9
jne 0x3b030
jp 0x3b030
movapd %xmm11, %xmm12
divsd %xmm10, %xmm12
jmp 0x3b06e
mulsd %xmm7, %xmm10
divsd %xmm11, %xmm10
movapd %xmm10, %xmm9
andpd %xmm1, %xmm9
ucomisd %xmm10, %xmm2
mulsd %xmm10, %xmm10
addsd %xmm5, %xmm10
sqrtsd %xmm10, %xmm10
addsd %xmm9, %xmm10
movapd %xmm5, %xmm12
divsd %xmm10, %xmm12
jbe 0x3b06e
xorpd %xmm6, %xmm12
movapd %xmm12, %xmm9
mulsd %xmm12, %xmm9
addsd %xmm5, %xmm9
sqrtsd %xmm9, %xmm9
movapd %xmm5, %xmm13
divsd %xmm9, %xmm13
movapd %xmm12, %xmm9
mulsd %xmm13, %xmm9
addsd %xmm5, %xmm13
movapd %xmm9, %xmm10
mulsd %xmm12, %xmm11
movsd -0x8(%rax,%r11,8), %xmm12
subsd %xmm11, %xmm12
movsd %xmm12, -0x8(%rax,%r11,8)
movsd -0x8(%rax,%r9,8), %xmm12
addsd %xmm11, %xmm12
movsd %xmm12, -0x8(%rax,%r9,8)
movsd -0x8(%rcx,%r11,8), %xmm12
subsd %xmm11, %xmm12
movsd %xmm12, -0x8(%rcx,%r11,8)
addsd -0x8(%rcx,%r9,8), %xmm11
movsd %xmm11, -0x8(%rcx,%r9,8)
andq $0x0, -0x8(%rbp,%r9,8)
divsd %xmm13, %xmm10
movapd %xmm9, %xmm11
xorpd %xmm6, %xmm11
xorl %ecx, %ecx
cmpq %rcx, %r10
je 0x3b161
movq (%r13,%rcx), %r8
movsd -0x8(%r8,%r11,8), %xmm12
movsd -0x8(%r8,%r9,8), %xmm13
movapd %xmm12, %xmm14
mulsd %xmm10, %xmm14
addsd %xmm13, %xmm14
mulsd %xmm11, %xmm14
addsd %xmm12, %xmm14
movsd %xmm14, -0x8(%r8,%r11,8)
movapd %xmm13, %xmm14
mulsd %xmm10, %xmm14
subsd %xmm14, %xmm12
mulsd %xmm9, %xmm12
addsd %xmm13, %xmm12
movsd %xmm12, -0x8(%r8,%r9,8)
addq $0x8, %rcx
jmp 0x3b103
movq 0x20(%rsp), %rcx
cmpq %r9, %rcx
jae 0x3b1c3
movsd -0x8(%rbp,%rcx,8), %xmm12
movq -0x8(%r13,%rcx,8), %r8
movsd -0x8(%r8,%r9,8), %xmm13
movapd %xmm12, %xmm14
mulsd %xmm10, %xmm14
addsd %xmm13, %xmm14
mulsd %xmm11, %xmm14
addsd %xmm12, %xmm14
movsd %xmm14, -0x8(%rbp,%rcx,8)
movapd %xmm13, %xmm14
mulsd %xmm10, %xmm14
subsd %xmm14, %xmm12
mulsd %xmm9, %xmm12
addsd %xmm13, %xmm12
movsd %xmm12, -0x8(%r8,%r9,8)
incq %rcx
jmp 0x3b166
movq %r15, %rcx
cmpl %r12d, %ecx
jge 0x3b221
movsd (%rbp,%rcx,8), %xmm12
movq -0x8(%r13,%r9,8), %r8
movsd (%r8,%rcx,8), %xmm13
movapd %xmm12, %xmm14
mulsd %xmm10, %xmm14
addsd %xmm13, %xmm14
mulsd %xmm11, %xmm14
addsd %xmm12, %xmm14
movsd %xmm14, (%rbp,%rcx,8)
movapd %xmm13, %xmm14
mulsd %xmm10, %xmm14
subsd %xmm14, %xmm12
mulsd %xmm9, %xmm12
addsd %xmm13, %xmm12
movsd %xmm12, (%r8,%rcx,8)
incq %rcx
jmp 0x3b1c6
xorl %ecx, %ecx
cmpq %rcx, %rsi
je 0x3b283
movq 0x8(%rbx), %r8
movq (%r8,%rcx,8), %r8
movsd -0x8(%r8,%r11,8), %xmm12
movsd -0x8(%r8,%r9,8), %xmm13
movapd %xmm12, %xmm14
mulsd %xmm10, %xmm14
addsd %xmm13, %xmm14
mulsd %xmm11, %xmm14
addsd %xmm12, %xmm14
movsd %xmm14, -0x8(%r8,%r11,8)
movapd %xmm13, %xmm14
mulsd %xmm10, %xmm14
subsd %xmm14, %xmm12
mulsd %xmm9, %xmm12
addsd %xmm13, %xmm12
movsd %xmm12, -0x8(%r8,%r9,8)
incq %rcx
jmp 0x3b223
incq %r9
incq %r15
jmp 0x3af76
incq %r11
movq 0x18(%rsp), %r15
incq %r15
addq $0x8, %r10
jmp 0x3af60
xorl %ecx, %ecx
movq (%rsp), %r15
movq 0x10(%rsp), %r9
pushq $0x1
popq %r11
cmpq %rcx, %r9
je 0x3b2db
movsd (%r15,%rcx,8), %xmm8
addsd (%rax,%rcx,8), %xmm8
movsd %xmm8, (%r15,%rcx,8)
movq (%r14), %r8
movsd %xmm8, (%r8,%rcx,8)
andq $0x0, (%rax,%rcx,8)
incq %rcx
jmp 0x3b2b1
incl %edi
jmp 0x3aef5
movq %rax, %rdi
callq 0x34ff7
movq %r15, %rdi
callq 0x34ff7
movq %r13, %rdi
movq 0x8(%rsp), %rsi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x34fc3