// File: /workspace/github_cpp_makefile_star2_O3/Kingsford-Group[P]ghost2/src/sigApprox.hpp
// Function: inverseIter(Eigen::Matrix<double, -1, -1, 0, -1, -1>*, double)
double inverseIter(MatrixXd *A, double mu)
{
  int N=(*A).rows(); // rows and cols should be the same
  double prev=200, cur;  // dummy value
  bool flag=false;
  VectorXd seed = randomVec(N);
  for(int i=0;i<N;i++)
    (*A)(i,i) -= mu;
  LDLT<MatrixXd,Lower> ALU = (*A).ldlt();
  for(int i=0;i<1000;i++)
  {
    VectorXd temp = seed;
    seed = ALU.solve(seed);
    cur = normalize(&seed); // in place
    if(fabs(cur-prev) < ZERO) 
    {
      for(int i=0;i<N;i++)
        if(fabs(temp(i)) > ZERO)
        {
          cur*=(temp(i)*seed(i)>0)?1:-1;
          break;
        }
      flag=true;
      break;
    }
    prev=cur;
  }
  for(int i=0;i<N;i++)
    (*A)(i,i) += mu;
//  if(!flag) cout << "warning: did not converge\n"; // uncomment for warning
  cur = 1.0/cur + mu;
  return cur;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movsd %xmm0, (%rsp)
movq %rdi, %rbx
movq 0x8(%rdi), %r14
leaq 0x10(%rsp), %r15
movq %r15, %rdi
movl %r14d, %esi
callq 0xfa13
testl %r14d, %r14d
jle 0xfc58
movq 0x8(%rbx), %rsi
xorl %eax, %eax
testq %rsi, %rsi
movl $0x0, %ecx
cmovgq %rsi, %rcx
movl %r14d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
leaq 0x8(,%rsi,8), %rsi
xorl %edi, %edi
cmpq %rdi, %rcx
je 0xfe58
cmpq %rdi, 0x10(%rbx)
jle 0xfe58
movq (%rbx), %r8
movsd (%r8,%rax), %xmm0
subsd (%rsp), %xmm0
movsd %xmm0, (%r8,%rax)
incq %rdi
addq %rsi, %rax
cmpq %rdi, %rdx
jne 0xfc26
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
callq 0x29980
movsd 0x38413(%rip), %xmm0    # 0x48080
movsd %xmm0, 0x8(%rsp)
movl $0x3e8, %r12d           # imm = 0x3E8
leaq 0x38(%rsp), %r13
leaq 0x48(%rsp), %rbp
movq %r13, %rdi
movq %r15, %rsi
callq 0x1c55e
cmpb $0x0, 0x94(%rsp)
je 0xfe96
movq 0x60(%rsp), %rax
cmpq 0x18(%rsp), %rax
jne 0xfe77
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %r15, 0x50(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2b2b6
movq %r15, %rdi
callq 0xfaed
movapd %xmm0, %xmm1
subsd 0x8(%rsp), %xmm1
andpd 0x38450(%rip), %xmm1    # 0x48130
movsd 0x383a0(%rip), %xmm2    # 0x48088
ucomisd %xmm1, %xmm2
movq 0x38(%rsp), %rdi
movapd %xmm0, 0x20(%rsp)
ja 0xfd18
callq 0xc660
movapd 0x20(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
decl %r12d
jne 0xfc83
jmp 0xfdb0
testl %r14d, %r14d
jle 0xfda6
movq 0x40(%rsp), %rcx
xorl %eax, %eax
testq %rcx, %rcx
cmovleq %rax, %rcx
movl %r14d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
cmpq %rax, %rcx
je 0xfeb5
movsd (%rdi,%rax,8), %xmm3
movapd %xmm3, %xmm1
andpd 0x383de(%rip), %xmm1    # 0x48130
ucomisd 0x3832e(%rip), %xmm1    # 0x48088
ja 0xfd66
incq %rax
cmpq %rax, %rdx
jne 0xfd38
jmp 0xfda6
cmpq %rax, 0x18(%rsp)
jle 0xfeb5
movq 0x10(%rsp), %rcx
mulsd (%rcx,%rax,8), %xmm3
movapd 0x383bd(%rip), %xmm1    # 0x48140
xorpd %xmm0, %xmm1
xorpd %xmm2, %xmm2
cmpltsd %xmm3, %xmm2
movapd %xmm2, %xmm3
andpd %xmm0, %xmm3
andnpd %xmm1, %xmm2
orpd %xmm3, %xmm2
movapd %xmm2, 0x20(%rsp)
callq 0xc660
movaps 0x20(%rsp), %xmm1
testl %r14d, %r14d
jle 0xfe00
movq 0x8(%rbx), %rdx
xorl %eax, %eax
testq %rdx, %rdx
movl $0x0, %ecx
cmovgq %rdx, %rcx
andl $0x7fffffff, %r14d      # imm = 0x7FFFFFFF
leaq 0x8(,%rdx,8), %rdx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0xfe58
cmpq %rsi, 0x10(%rbx)
jle 0xfe58
movq (%rbx), %rdi
movsd (%rdi,%rax), %xmm0
addsd (%rsp), %xmm0
movsd %xmm0, (%rdi,%rax)
incq %rsi
addq %rdx, %rax
cmpq %rsi, %r14
jne 0xfdd8
movsd 0x38258(%rip), %xmm0    # 0x48060
divsd %xmm1, %xmm0
addsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movq 0x80(%rsp), %rdi
callq 0xc660
movq 0x70(%rsp), %rdi
callq 0xc660
movq 0x58(%rsp), %rdi
callq 0xc660
movq 0x10(%rsp), %rdi
callq 0xc660
movsd (%rsp), %xmm0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3cbf8(%rip), %rdi     # 0x4ca57
leaq 0x3cc26(%rip), %rsi     # 0x4ca8c
leaq 0x3cc48(%rip), %rcx     # 0x4cab5
movl $0x151, %edx            # imm = 0x151
callq 0xc340
leaq 0x3ec08(%rip), %rdi     # 0x4ea86
leaq 0x3ccd3(%rip), %rsi     # 0x4cb58
leaq 0x3eb14(%rip), %rcx     # 0x4e9a0
movl $0xbe, %edx
callq 0xc340
leaq 0x3ead5(%rip), %rdi     # 0x4e972
leaq 0x3ccb4(%rip), %rsi     # 0x4cb58
leaq 0x3eaf5(%rip), %rcx     # 0x4e9a0
movl $0xbc, %edx
callq 0xc340
leaq 0x3fb56(%rip), %rdi     # 0x4fa12
leaq 0x3cbc9(%rip), %rsi     # 0x4ca8c
leaq 0x403ca(%rip), %rcx     # 0x50294
movl $0x18a, %edx            # imm = 0x18A
callq 0xc340
movq %rax, %rbx
jmp 0xfef7
jmp 0xfedb
movq %rax, %rbx
movq 0x38(%rsp), %rdi
callq 0xc660
jmp 0xfeed
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x1c664
movq 0x10(%rsp), %rdi
callq 0xc660
movq %rbx, %rdi
callq 0xc9c0