// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/matrix.c
// Function: matrix_inverse
int matrix_inverse(matrix *matrix1)
{
	/*!Last Changed 02.02.2004 added safemalloc*/
 double big;
 double dum,pivinv;
 int i,icol,irow,j,k,l,ll,n=matrix1->row;
 matrix b;
 int *indxc,*indxr,*ipiv;
 if (matrix1->row != matrix1->col)
  {
   printf(m1365, "Inverse");
   return 0;
  } 
 b = identity(n);
 indxc = (int *)safemalloc(n*sizeof(int), "matrix_inverse", 7);
 indxr = (int *)safemalloc(n*sizeof(int), "matrix_inverse", 8);
 ipiv = (int *)safemalloc(n*sizeof(int), "matrix_inverse", 9);
 for (j=1;j<=n;j++)
   ipiv[j-1] = 0;
 for (i=1;i<=n;i++)
  {
   big = 0.0;
   irow = -1;
   icol = -1;
   for (j=1;j<=n;j++)
     if (ipiv[j-1]!=1)
       for (k=1;k<=n;k++)
         if (ipiv[k-1]==0)
           if (fabs(matrix1->values[j-1][k-1])>=big)
            {
             big = fabs(matrix1->values[j-1][k-1]);
             irow = j;
             icol = k;
            }
   if (irow == -1 || icol == -1)
     return 0;         
   ipiv[icol-1]=ipiv[icol-1]+1;
   if (irow!=icol)
    {
     for (l=1;l<=n;l++)
      {
       dum=matrix1->values[irow-1][l-1];
       matrix1->values[irow-1][l-1]=matrix1->values[icol-1][l-1];
       matrix1->values[icol-1][l-1]=dum;
      }
     for (l=1;l<=n;l++)
      {
       dum = b.values[irow-1][l-1];
       b.values[irow-1][l-1] = b.values[icol-1][l-1];
       b.values[icol-1][l-1] = dum;
      }
    }
   indxr[i-1]=irow;
   indxc[i-1]=icol;
			if (matrix1->values[icol-1][icol-1] == 0)
			 {
     matrix_free(b);
     safe_free(ipiv);
     safe_free(indxr);
     safe_free(indxc);
				 return 0;
			 }
   pivinv = (1.0)/(matrix1->values[icol-1][icol-1]);
   matrix1->values[icol-1][icol-1]=1.0;
   for (l=1;l<=n;l++)
     matrix1->values[icol-1][l-1]=matrix1->values[icol-1][l-1]*pivinv;
   for (l=1;l<=n;l++)
     b.values[icol-1][l-1]=b.values[icol-1][l-1]*pivinv;
   for (ll=1;ll<=n;ll++)
     if (ll!=icol)
      {
       dum = matrix1->values[ll-1][icol-1];
       matrix1->values[ll-1][icol-1] = 0.0;
       for (l=1;l<=n;l++)
         matrix1->values[ll-1][l-1]=matrix1->values[ll-1][l-1]-matrix1->values[icol-1][l-1]*dum;
       for (l=1;l<=n;l++)
         b.values[ll-1][l-1]=b.values[ll-1][l-1]-dum*b.values[icol-1][l-1];
      }
  }
 for (l=n;l>=1;l--)
   if (indxr[l-1]!=indxc[l-1])
     for (k=1;k<=n;k++)
      {
       dum = matrix1->values[k-1][indxr[l-1]-1];
       matrix1->values[k-1][indxr[l-1]-1] = matrix1->values[k-1][indxc[l-1]-1];
       matrix1->values[k-1][indxc[l-1]-1] = dum;
      }
 matrix_free(b);
 safe_free(ipiv);
 safe_free(indxr);
 safe_free(indxc);
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl (%rdi), %r15d
cmpl 0x4(%rdi), %r15d
jne 0x40cd1
movq %rdi, %r14
movslq %r15d, %rbp
movl %r15d, %edi
callq 0x3eddb
movq %rax, 0x10(%rsp)
movq %rdx, %r13
leaq (,%rbp,4), %rbx
leaq 0x69619(%rip), %r12     # 0xaa010
movq %rbx, %rdi
movq %r12, %rsi
movl $0x7, %edx
callq 0x3a0e1
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x3a0e1
movq %rax, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl $0x9, %edx
callq 0x3a0e1
movq %rax, %r12
testl %r15d, %r15d
jle 0x40ca2
leaq (,%r15,4), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x4050
leaq 0x1(%r15), %rax
movl $0x1, %ecx
xorpd %xmm0, %xmm0
movsd 0x64abd(%rip), %xmm1    # 0xa5520
movapd 0x65765(%rip), %xmm2    # 0xa61d0
movapd 0x6576d(%rip), %xmm3    # 0xa61e0
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x1, %edi
xorpd %xmm4, %xmm4
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
cmpl $0x1, -0x4(%r12,%rdi,4)
je 0x40ac9
movl $0x1, %r9d
cmpl $0x0, -0x4(%r12,%r9,4)
jne 0x40ac1
movq 0x8(%r14), %rdx
movq -0x8(%rdx,%rdi,8), %rdx
movsd -0x8(%rdx,%r9,8), %xmm5
andpd %xmm3, %xmm5
ucomisd %xmm4, %xmm5
jb 0x40ac1
movl %edi, %r8d
movl %r9d, %esi
movapd %xmm5, %xmm4
incq %r9
cmpq %r9, %rax
jne 0x40a95
incq %rdi
cmpq %rax, %rdi
jne 0x40a87
xorl %ebx, %ebx
cmpl $-0x1, %r8d
je 0x40ce8
cmpl $-0x1, %esi
je 0x40ce8
movslq %esi, %rdi
incl -0x4(%r12,%rdi,4)
decq %rdi
cmpl %esi, %r8d
je 0x40b54
movq 0x8(%r14), %rdx
movslq %r8d, %r9
movq -0x8(%rdx,%r9,8), %r10
movq (%rdx,%rdi,8), %r11
xorl %edx, %edx
movsd (%r10,%rdx,8), %xmm4
movsd (%r11,%rdx,8), %xmm5
movsd %xmm5, (%r10,%rdx,8)
movsd %xmm4, (%r11,%rdx,8)
incq %rdx
cmpq %rdx, %r15
jne 0x40b08
movq -0x8(%r13,%r9,8), %r9
movq (%r13,%rdi,8), %r10
xorl %edx, %edx
movsd (%r9,%rdx,8), %xmm4
movsd (%r10,%rdx,8), %xmm5
movsd %xmm5, (%r9,%rdx,8)
movsd %xmm4, (%r10,%rdx,8)
incq %rdx
cmpq %rdx, %r15
jne 0x40b34
movq (%rsp), %rdx
movl %r8d, -0x4(%rdx,%rcx,4)
movq 0x8(%rsp), %rdx
movl %esi, -0x4(%rdx,%rcx,4)
movq 0x8(%r14), %r8
movq (%r8,%rdi,8), %r9
movsd (%r9,%rdi,8), %xmm5
ucomisd %xmm0, %xmm5
jne 0x40b80
jnp 0x40cf9
movapd %xmm1, %xmm4
divsd %xmm5, %xmm4
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rdx, (%r9,%rdi,8)
xorl %edx, %edx
movsd (%r9,%rdx,8), %xmm5
mulsd %xmm4, %xmm5
movsd %xmm5, (%r9,%rdx,8)
incq %rdx
cmpq %rdx, %r15
jne 0x40b98
movq (%r13,%rdi,8), %r10
xorl %edx, %edx
movsd (%r10,%rdx,8), %xmm5
mulsd %xmm4, %xmm5
movsd %xmm5, (%r10,%rdx,8)
incq %rdx
cmpq %rdx, %r15
jne 0x40bb7
movl %esi, %esi
movl $0x1, %r10d
cmpq %rsi, %r10
je 0x40c40
movq -0x8(%r8,%r10,8), %r11
movsd (%r11,%rdi,8), %xmm4
movq $0x0, (%r11,%rdi,8)
xorl %ebx, %ebx
movsd (%r11,%rbx,8), %xmm5
movsd (%r9,%rbx,8), %xmm6
mulsd %xmm4, %xmm6
subsd %xmm6, %xmm5
movsd %xmm5, (%r11,%rbx,8)
incq %rbx
cmpq %rbx, %r15
jne 0x40bf1
movq -0x8(%r13,%r10,8), %r11
movq (%r13,%rdi,8), %rbx
xorpd %xmm2, %xmm4
xorl %edx, %edx
movsd (%rbx,%rdx,8), %xmm5
mulsd %xmm4, %xmm5
addsd (%r11,%rdx,8), %xmm5
movsd %xmm5, (%r11,%rdx,8)
incq %rdx
cmpq %rdx, %r15
jne 0x40c23
incq %r10
cmpq %rax, %r10
jne 0x40bd7
incq %rcx
cmpq %rax, %rcx
jne 0x40a73
movq (%rsp), %rax
movslq -0x4(%rax,%rbp,4), %rax
movq 0x8(%rsp), %rcx
movslq -0x4(%rcx,%rbp,4), %rcx
cmpl %ecx, %eax
je 0x40c95
movq 0x8(%r14), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
movsd -0x8(%rdi,%rax,8), %xmm0
movsd -0x8(%rdi,%rcx,8), %xmm1
movsd %xmm1, -0x8(%rdi,%rax,8)
movsd %xmm0, -0x8(%rdi,%rcx,8)
incq %rsi
cmpq %rsi, %r15
jne 0x40c71
leaq -0x1(%rbp), %rax
cmpq $0x1, %rbp
movq %rax, %rbp
jg 0x40c54
movq %r13, %rdi
movq 0x10(%rsp), %rsi
callq 0x3a14b
movq %r12, %rdi
callq 0x3a180
movq (%rsp), %rdi
callq 0x3a180
movq 0x8(%rsp), %rdi
callq 0x3a180
movl $0x1, %ebx
jmp 0x40ce8
leaq 0x692a1(%rip), %rdi     # 0xa9f79
leaq 0x69329(%rip), %rsi     # 0xaa008
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4030
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
movq 0x10(%rsp), %rsi
callq 0x3a14b
movq %r12, %rdi
callq 0x3a180
movq (%rsp), %rdi
callq 0x3a180
movq 0x8(%rsp), %rdi
callq 0x3a180
jmp 0x40ce8