// File: /workspace/github_c_makefile_star2_O2/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
movq %rdi, %r14
movslq (%rdi), %rdi
cmpl 0x4(%r14), %edi
jne 0x3aa90
movq %rdi, 0x10(%rsp)
callq 0x3930e
movq %rax, 0x18(%rsp)
movq %rdx, %r12
movq 0x10(%rsp), %rax
leaq (,%rax,4), %r15
leaq 0x5f509(%rip), %rbp     # 0x99f40
pushq $0x7
popq %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x34f59
movq %rax, 0x8(%rsp)
pushq $0x8
popq %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x34f59
movq %rax, (%rsp)
pushq $0x9
popq %rdx
movq %r15, %rdi
movq %rbp, %rsi
callq 0x34f59
movq 0x10(%rsp), %rsi
movq %rax, %rbp
xorl %edx, %edx
testl %esi, %esi
movl $0x0, %eax
cmovgl %esi, %eax
leal 0x1(%rax), %ecx
cmpq %rdx, %rax
je 0x3aaac
andl $0x0, (%rbp,%rdx,4)
incq %rdx
jmp 0x3aa81
leaq 0x5f412(%rip), %rdi     # 0x99ea9
leaq 0x5f49a(%rip), %rsi     # 0x99f38
xorl %ebx, %ebx
xorl %eax, %eax
callq 0x4030
jmp 0x3ad90
leal 0x1(%rsi), %edx
leaq -0x1(%rdx), %rsi
pushq $0x1
popq %rdi
xorpd %xmm0, %xmm0
movsd 0x5aa5e(%rip), %xmm1    # 0x95520
movapd 0x5b706(%rip), %xmm2    # 0x961d0
movapd 0x5b70e(%rip), %xmm3    # 0x961e0
cmpq %rcx, %rdi
je 0x3acde
movq %rdi, 0x20(%rsp)
xorpd %xmm4, %xmm4
pushq $0x1
popq %r9
pushq $-0x1
popq %r11
movl %r11d, %r8d
cmpq %rdx, %r9
je 0x3ab39
cmpl $0x1, -0x4(%rbp,%r9,4)
jne 0x3ab01
incq %r9
jmp 0x3aaef
pushq $0x1
popq %rbx
cmpq %rbx, %rdx
je 0x3aafc
cmpl $0x0, -0x4(%rbp,%rbx,4)
jne 0x3ab34
movq 0x8(%r14), %r10
movq -0x8(%r10,%r9,8), %r10
movsd -0x8(%r10,%rbx,8), %xmm5
andpd %xmm3, %xmm5
ucomisd %xmm4, %xmm5
jb 0x3ab34
movl %r9d, %r8d
movl %ebx, %r11d
movapd %xmm5, %xmm4
incq %rbx
jmp 0x3ab04
xorl %ebx, %ebx
cmpl $-0x1, %r8d
je 0x3ad90
cmpl $-0x1, %r11d
je 0x3ad90
movslq %r11d, %r9
incl -0x4(%rbp,%r9,4)
decq %r9
cmpl %r11d, %r8d
jne 0x3ac77
movq (%rsp), %rdi
movq 0x20(%rsp), %r10
movl %r8d, -0x4(%rdi,%r10,4)
movq 0x8(%rsp), %rdi
movl %r11d, -0x4(%rdi,%r10,4)
movq 0x8(%r14), %r8
movq (%r8,%r9,8), %rbx
movsd (%rbx,%r9,8), %xmm5
ucomisd %xmm0, %xmm5
jne 0x3ab95
jnp 0x3ad66
movapd %xmm1, %xmm4
divsd %xmm5, %xmm4
movabsq $0x3ff0000000000000, %rdi # imm = 0x3FF0000000000000
movq %rdi, (%rbx,%r9,8)
xorl %r10d, %r10d
cmpq %r10, %rax
je 0x3abc8
movsd (%rbx,%r10,8), %xmm5
mulsd %xmm4, %xmm5
movsd %xmm5, (%rbx,%r10,8)
incq %r10
jmp 0x3abae
xorl %r10d, %r10d
cmpq %r10, %rax
je 0x3abe9
movq (%r12,%r9,8), %r15
movsd (%r15,%r10,8), %xmm5
mulsd %xmm4, %xmm5
movsd %xmm5, (%r15,%r10,8)
incq %r10
jmp 0x3abcb
movl %r11d, %r11d
pushq $0x1
popq %r15
cmpq %rcx, %r15
je 0x3ac6a
cmpq %r11, %r15
jne 0x3abff
incq %r15
jmp 0x3abf0
movq -0x8(%r8,%r15,8), %r13
movsd (%r13,%r9,8), %xmm4
andq $0x0, (%r13,%r9,8)
xorl %r10d, %r10d
cmpq %r10, %rsi
je 0x3ac3a
movsd (%r13,%r10,8), %xmm5
movsd (%rbx,%r10,8), %xmm6
mulsd %xmm4, %xmm6
subsd %xmm6, %xmm5
movsd %xmm5, (%r13,%r10,8)
incq %r10
jmp 0x3ac14
xorpd %xmm2, %xmm4
xorl %r13d, %r13d
cmpq %r13, %rsi
je 0x3abfa
movq -0x8(%r12,%r15,8), %r10
movq (%r12,%r9,8), %rdi
movsd (%rdi,%r13,8), %xmm5
mulsd %xmm4, %xmm5
addsd (%r10,%r13,8), %xmm5
movsd %xmm5, (%r10,%r13,8)
incq %r13
jmp 0x3ac41
movq 0x20(%rsp), %rdi
incq %rdi
jmp 0x3aad2
movslq %r8d, %rbx
xorl %r13d, %r13d
cmpq %r13, %rsi
je 0x3acac
movq 0x8(%r14), %r10
movq -0x8(%r10,%rbx,8), %r15
movsd (%r15,%r13,8), %xmm4
movq (%r10,%r9,8), %r10
movsd (%r10,%r13,8), %xmm5
movsd %xmm5, (%r15,%r13,8)
movsd %xmm4, (%r10,%r13,8)
incq %r13
jmp 0x3ac7d
xorl %r13d, %r13d
cmpq %r13, %rsi
je 0x3ab63
movq -0x8(%r12,%rbx,8), %r10
movsd (%r10,%r13,8), %xmm4
movq (%r12,%r9,8), %r15
movsd (%r15,%r13,8), %xmm5
movsd %xmm5, (%r10,%r13,8)
movsd %xmm4, (%r15,%r13,8)
incq %r13
jmp 0x3acaf
movl 0x10(%rsp), %edi
testl %edi, %edi
jle 0x3ad39
leaq -0x1(%rdi), %rcx
movq (%rsp), %rdx
movslq -0x4(%rdx,%rdi,4), %rdx
movq 0x8(%rsp), %rsi
movslq -0x4(%rsi,%rdi,4), %rsi
movq %rcx, %rdi
cmpl %esi, %edx
je 0x3ace2
xorl %edi, %edi
cmpq %rdi, %rax
je 0x3ad34
movq 0x8(%r14), %r8
movq (%r8,%rdi,8), %r8
movsd -0x8(%r8,%rdx,8), %xmm0
movsd -0x8(%r8,%rsi,8), %xmm1
movsd %xmm1, -0x8(%r8,%rdx,8)
movsd %xmm0, -0x8(%r8,%rsi,8)
incq %rdi
jmp 0x3ad06
movq %rcx, %rdi
jmp 0x3ace2
movq %r12, %rdi
movq 0x18(%rsp), %rsi
callq 0x34fc3
movq %rbp, %rdi
callq 0x34ff7
movq (%rsp), %rdi
callq 0x34ff7
movq 0x8(%rsp), %rdi
callq 0x34ff7
pushq $0x1
popq %rbx
jmp 0x3ad90
movq %r12, %rdi
movq 0x18(%rsp), %rsi
callq 0x34fc3
movq %rbp, %rdi
callq 0x34ff7
movq (%rsp), %rdi
callq 0x34ff7
movq 0x8(%rsp), %rdi
callq 0x34ff7
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq