// File: /workspace/github_c_makefile_star2_O1/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 $0x28, %rsp
movl (%rdi), %r15d
cmpl 0x4(%rdi), %r15d
jne 0x3f985
movq %rdi, %r14
movslq %r15d, %r13
movl %r15d, %edi
callq 0x3dc37
movq %rax, 0x18(%rsp)
movq %rdx, %rbp
leaq (,%r13,4), %rbx
leaq 0x678e8(%rip), %r12     # 0xa6f70
movq %rbx, %rdi
movq %r12, %rsi
movl $0x7, %edx
callq 0x390f5
movq %rax, 0x8(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x390f5
movq %rax, (%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl $0x9, %edx
callq 0x390f5
movq %rax, %r12
testl %r15d, %r15d
jle 0x3f6db
leaq (,%r15,4), %rdx
movq %r12, %rdi
xorl %esi, %esi
callq 0x4050
testl %r15d, %r15d
jle 0x3f903
leaq 0x1(%r15), %rax
movq %rax, 0x20(%rsp)
movl %eax, %ecx
leaq -0x1(%rcx), %rdx
movl $0x1, %eax
movq %rax, 0x10(%rsp)
xorpd %xmm0, %xmm0
movsd 0x62e17(%rip), %xmm1    # 0xa2520
movapd 0x63abf(%rip), %xmm2    # 0xa31d0
movapd 0x63ac7(%rip), %xmm3    # 0xa31e0
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl $0x1, %r9d
xorpd %xmm4, %xmm4
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
cmpl $0x1, -0x4(%r12,%r9,4)
je 0x3f771
movl $0x1, %r11d
cmpl $0x0, -0x4(%r12,%r11,4)
jne 0x3f769
movq 0x8(%r14), %rax
movq -0x8(%rax,%r9,8), %rax
movsd -0x8(%rax,%r11,8), %xmm5
andpd %xmm3, %xmm5
ucomisd %xmm4, %xmm5
jb 0x3f769
movl %r9d, %r10d
movl %r11d, %r8d
movapd %xmm5, %xmm4
incq %r11
cmpq %r11, %rcx
jne 0x3f73d
incq %r9
cmpq %rcx, %r9
jne 0x3f72f
xorl %ebx, %ebx
cmpl $-0x1, %r10d
je 0x3f99c
cmpl $-0x1, %r8d
je 0x3f99c
movslq %r8d, %r9
incl -0x4(%r12,%r9,4)
decq %r9
cmpl %r8d, %r10d
je 0x3f7f7
movq 0x8(%r14), %rsi
movslq %r10d, %rax
movq -0x8(%rsi,%rax,8), %rdi
movq (%rsi,%r9,8), %r11
xorl %esi, %esi
movsd (%rdi,%rsi,8), %xmm4
movsd (%r11,%rsi,8), %xmm5
movsd %xmm5, (%rdi,%rsi,8)
movsd %xmm4, (%r11,%rsi,8)
incq %rsi
cmpq %rsi, %rdx
jne 0x3f7b1
movq -0x8(%rbp,%rax,8), %rax
movq (%rbp,%r9,8), %rdi
xorl %esi, %esi
movsd (%rax,%rsi,8), %xmm4
movsd (%rdi,%rsi,8), %xmm5
movsd %xmm5, (%rax,%rsi,8)
movsd %xmm4, (%rdi,%rsi,8)
incq %rsi
cmpq %rsi, %rdx
jne 0x3f7db
movq (%rsp), %rax
movq 0x10(%rsp), %rsi
movl %r10d, -0x4(%rax,%rsi,4)
movq 0x8(%rsp), %rax
movl %r8d, -0x4(%rax,%rsi,4)
movq 0x8(%r14), %r10
movq (%r10,%r9,8), %r11
movsd (%r11,%r9,8), %xmm5
ucomisd %xmm0, %xmm5
jne 0x3f829
jnp 0x3f9ad
movapd %xmm1, %xmm4
divsd %xmm5, %xmm4
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, (%r11,%r9,8)
xorl %eax, %eax
movsd (%r11,%rax,8), %xmm5
mulsd %xmm4, %xmm5
movsd %xmm5, (%r11,%rax,8)
incq %rax
cmpq %rax, %rdx
jne 0x3f841
movq (%rbp,%r9,8), %rax
xorl %esi, %esi
movsd (%rax,%rsi,8), %xmm5
mulsd %xmm4, %xmm5
movsd %xmm5, (%rax,%rsi,8)
incq %rsi
cmpq %rsi, %rdx
jne 0x3f860
movl %r8d, %r8d
movl $0x1, %ebx
cmpq %r8, %rbx
je 0x3f8e3
movq -0x8(%r10,%rbx,8), %rax
movsd (%rax,%r9,8), %xmm4
movq $0x0, (%rax,%r9,8)
xorl %edi, %edi
movsd (%rax,%rdi,8), %xmm5
movsd (%r11,%rdi,8), %xmm6
mulsd %xmm4, %xmm6
subsd %xmm6, %xmm5
movsd %xmm5, (%rax,%rdi,8)
incq %rdi
cmpq %rdi, %rdx
jne 0x3f898
movq -0x8(%rbp,%rbx,8), %rdi
movq (%rbp,%r9,8), %rax
xorpd %xmm2, %xmm4
xorl %esi, %esi
movsd (%rax,%rsi,8), %xmm5
mulsd %xmm4, %xmm5
addsd (%rdi,%rsi,8), %xmm5
movsd %xmm5, (%rdi,%rsi,8)
incq %rsi
cmpq %rsi, %rdx
jne 0x3f8c8
incq %rbx
cmpq %rcx, %rbx
jne 0x3f87e
movq 0x10(%rsp), %rax
incq %rax
movq %rax, 0x10(%rsp)
cmpq 0x20(%rsp), %rax
jne 0x3f719
testl %r15d, %r15d
movq 0x8(%rsp), %rbx
movq (%rsp), %r8
jle 0x3f956
movslq -0x4(%r8,%r13,4), %rax
movslq -0x4(%rbx,%r13,4), %rcx
cmpl %ecx, %eax
je 0x3f949
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 0x3f925
leaq -0x1(%r13), %rax
cmpq $0x1, %r13
movq %rax, %r13
jg 0x3f911
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
movq %r8, %r14
callq 0x3915f
movq %r12, %rdi
callq 0x39194
movq %r14, %rdi
callq 0x39194
movq %rbx, %rdi
callq 0x39194
movl $0x1, %ebx
jmp 0x3f99c
leaq 0x6754d(%rip), %rdi     # 0xa6ed9
leaq 0x675d5(%rip), %rsi     # 0xa6f68
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4030
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
callq 0x3915f
movq %r12, %rdi
callq 0x39194
movq (%rsp), %rdi
callq 0x39194
movq 0x8(%rsp), %rdi
callq 0x39194
jmp 0x3f99c