// File: /workspace/github_c_makefile_star2_O0/zpole[P]IICV/vl/mathop.c
// Function: vl_gaussian_elimination
VL_EXPORT vl_bool
vl_gaussian_elimination (double * A, vl_size numRows, vl_size numColumns)
{
  vl_index i, j, ii, jj ;
  assert(A) ;
  assert(numRows <= numColumns) ;

#define Aat(i,j) A[(i) + (j)*numRows]

  /* Gauss elimination */
  for(j = 0 ; j < (signed)numRows ; ++j) {
    double maxa = 0 ;
    double maxabsa = 0 ;
    vl_index maxi = -1 ;
    double tmp ;

#if 0
    {
      vl_index iii, jjj ;
      for (iii = 0 ; iii < 2 ; ++iii) {
        for (jjj = 0 ; jjj < 3 ; ++jjj) {
          VL_PRINTF("%5.2g ", Aat(iii,jjj)) ;

        }
        VL_PRINTF("\n") ;
      }
      VL_PRINTF("\n") ;
    }
#endif

    /* look for the maximally stable pivot */
    for (i = j ; i < (signed)numRows ; ++i) {
      double a = Aat(i,j) ;
      double absa = vl_abs_d (a) ;
      if (absa > maxabsa) {
        maxa = a ;
        maxabsa = absa ;
        maxi = i ;
      }
    }
    i = maxi ;

    /* if singular give up */
    if (maxabsa < 1e-10) return VL_ERR_OVERFLOW ;

    /* swap j-th row with i-th row and normalize j-th row */
    for(jj = j ; jj < (signed)numColumns ; ++jj) {
      tmp = Aat(i,jj) ; Aat(i,jj) = Aat(j,jj) ; Aat(j,jj) = tmp ;
      Aat(j,jj) /= maxa ;
    }

#if 0
    {
      vl_index iii, jjj ;
      VL_PRINTF("after swap %d %d\n", j, i);
      for (iii = 0 ; iii < 2 ; ++iii) {
        for (jjj = 0 ; jjj < 3 ; ++jjj) {
          VL_PRINTF("%5.2g ", Aat(iii,jjj)) ;

        }
        VL_PRINTF("\n") ;
      }
      VL_PRINTF("\n") ;
    }
#endif

    /* elimination */
    for (ii = j+1 ; ii < (signed)numRows ; ++ii) {
      double x = Aat(ii,j) ;
      for (jj = j ; jj < (signed)numColumns ; ++jj) {
        Aat(ii,jj) -= x * Aat(j,jj) ;
      }
    }

#if 0
    {
      VL_PRINTF("after elimination\n");

      vl_index iii, jjj ;
      for (iii = 0 ; iii < 2 ; ++iii) {
        for (jjj = 0 ; jjj < 3 ; ++jjj) {
          VL_PRINTF("%5.2g ", Aat(iii,jjj)) ;

        }
        VL_PRINTF("\n") ;
      }
      VL_PRINTF("\n") ;
    }
#endif

  }

  /* backward substitution */
  for (i = numRows - 1 ; i > 0 ; --i) {
    /* substitute in all rows above */
    for (ii = i - 1 ; ii >= 0 ; --ii) {
      double x = Aat(ii,i) ;
      /* j = numRows */
      for (j = numRows ; j < (signed)numColumns ; ++j) {
        Aat(ii,j) -= x * Aat(i,j) ;
      }
    }
  }

#if 0
  {
    VL_PRINTF("after substitution\n");

    vl_index iii, jjj ;
    for (iii = 0 ; iii < 2 ; ++iii) {
      for (jjj = 0 ; jjj < 3 ; ++jjj) {
        VL_PRINTF("%5.2g ", Aat(iii,jjj)) ;

      }
      VL_PRINTF("\n") ;
    }
    VL_PRINTF("\n") ;
  }
#endif


  return VL_ERR_OK ;
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x78(%rsp)
movq %rsi, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movq $0x0, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq 0x70(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x3c792
xorps %xmm0, %xmm0
movsd %xmm0, 0x40(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movq $-0x1, 0x30(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq 0x70(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x3c585
movq 0x78(%rsp), %rax
movq 0x60(%rsp), %rcx
movq 0x58(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x3aed0
movsd %xmm0, 0x18(%rsp)
movsd 0x18(%rsp), %xmm0
ucomisd 0x38(%rsp), %xmm0
jbe 0x3c570
movsd 0x20(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x30(%rsp)
jmp 0x3c572
movq 0x60(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x3c4fa
movq 0x30(%rsp), %rax
movq %rax, 0x60(%rsp)
movsd 0x1d269(%rip), %xmm0    # 0x59800
ucomisd 0x38(%rsp), %xmm0
jbe 0x3c5af
movl $0x1, 0x84(%rsp)
jmp 0x3c8b1
movq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq 0x68(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x3c68e
movq 0x78(%rsp), %rax
movq 0x60(%rsp), %rcx
movq 0x48(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x78(%rsp), %rax
movq 0x58(%rsp), %rcx
movq 0x48(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x78(%rsp), %rax
movq 0x60(%rsp), %rcx
movq 0x48(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x28(%rsp), %xmm0
movq 0x78(%rsp), %rax
movq 0x58(%rsp), %rcx
movq 0x48(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd 0x40(%rsp), %xmm1
movq 0x78(%rsp), %rax
movq 0x58(%rsp), %rcx
movq 0x48(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd (%rax,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x3c5b9
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq 0x70(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x3c77d
movq 0x78(%rsp), %rax
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
movq 0x68(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x3c768
movsd 0x10(%rsp), %xmm0
movq 0x78(%rsp), %rax
movq 0x58(%rsp), %rcx
movq 0x48(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd (%rax,%rcx,8), %xmm2
movq 0x78(%rsp), %rax
movq 0x50(%rsp), %rcx
movq 0x48(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq %xmm0, %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
xorq %rsi, %rdx
movq %rdx, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x3c6df
jmp 0x3c76a
movq 0x50(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x3c69c
jmp 0x3c77f
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x3c4bf
movq 0x70(%rsp), %rax
subq $0x1, %rax
movq %rax, 0x60(%rsp)
cmpq $0x0, 0x60(%rsp)
jle 0x3c8a6
movq 0x60(%rsp), %rax
subq $0x1, %rax
movq %rax, 0x50(%rsp)
cmpq $0x0, 0x50(%rsp)
jl 0x3c891
movq 0x78(%rsp), %rax
movq 0x50(%rsp), %rcx
movq 0x60(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rax
movq 0x68(%rsp), %rcx
movslq %ecx, %rcx
cmpq %rcx, %rax
jge 0x3c87c
movsd 0x8(%rsp), %xmm0
movq 0x78(%rsp), %rax
movq 0x60(%rsp), %rcx
movq 0x58(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd (%rax,%rcx,8), %xmm2
movq 0x78(%rsp), %rax
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %rdx
imulq 0x70(%rsp), %rdx
addq %rdx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq %xmm0, %rdx
movabsq $-0x8000000000000000, %rsi # imm = 0x8000000000000000
xorq %rsi, %rdx
movq %rdx, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq 0x58(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x3c7f3
jmp 0x3c87e
movq 0x50(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x50(%rsp)
jmp 0x3c7ba
jmp 0x3c893
movq 0x60(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x60(%rsp)
jmp 0x3c7a0
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
addq $0x88, %rsp
retq