// File: snesic[P]stochastic_thin_films/newton-raphson_tools.cpp
// Function: elimination(double**, double*, double*, int const&)
void elimination(double ** a, double *r, double *q, const int& L)    // Gaussan elimination of 5 diagonal matrix, gives q out of Aq=r
{
  int i,j,l; double c;

  for(l=0;l<L-2;l++)
    for(j=0;j<2;j++)
     {
   	c=a[j+1+l][1-j]/a[l][2]; 
	a[j+1+l][1-j]=0;
   	for(i=1;i<4;i++)
      	    a[j+1+l][i-j]=a[j+1+l][i-j]-c*a[l][1+i];
    	    r[j+1+l]=r[j+1+l]-r[l]*c;
      }

  c=a[L-1][1] / a[L-2][2];
  a[L-1][1]=0;
  a[L-1][2]=a[L-1][2]-a[L-2][3]*c;

  r[L-1]=r[L-1]-r[L-2]*c;

  // calculating solution reverse 

   q[L-1]=r[L-1]/a[L-1][2];
   q[L-2]=(r[L-2] - q[L-1]*a[L-2][3])/a[L-2][2];

   for(i=L-3;i>=0;i--)
       q[i]=(r[i] - q[i+1]*a[i][3] - q[i+2]*a[i][4])/a[i][2];

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jge 0x715b
movl $0x0, -0x28(%rbp)
cmpl $0x2, -0x28(%rbp)
jge 0x714b
movq -0x8(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl $0x1, %ecx
subl -0x28(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
divsd 0x10(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl $0x1, %ecx
subl -0x28(%rbp), %ecx
movslq %ecx, %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl $0x1, -0x24(%rbp)
cmpl $0x4, -0x24(%rbp)
jge 0x70e2
movq -0x8(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x24(%rbp), %ecx
subl -0x28(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x38(%rbp), %xmm0
movq -0x8(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl -0x24(%rbp), %ecx
subl -0x28(%rbp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x7048
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0x38(%rbp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movl -0x28(%rbp), %ecx
addl $0x1, %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x6fd6
jmp 0x714d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x6fbb
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsd 0x8(%rax), %xmm0
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
divsd 0x10(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x8(%rax)
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsd 0x10(%rax), %xmm1
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsd 0x18(%rax), %xmm0
movsd -0x38(%rbp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsd %xmm0, 0x10(%rax)
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd -0x38(%rbp), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
divsd 0x10(%rax), %xmm0
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsd 0x18(%rax), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
divsd 0x10(%rax), %xmm0
movq -0x18(%rbp), %rax
movq -0x20(%rbp), %rcx
movl (%rcx), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movl (%rax), %eax
subl $0x3, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x7426
movq -0x10(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd 0x18(%rax), %xmm2
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
addl $0x2, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsd 0x20(%rax), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
divsd 0x10(%rax), %xmm0
movq -0x18(%rbp), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x735f
popq %rbp
retq
nopl (%rax,%rax)